Class: Views::Docs::Combobox

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_ui/combobox/combobox_docs.rb

Instance Method Summary collapse

Methods inherited from Base

#Alert, #AlertDescription, #AlertTitle, #Heading, #InlineCode, #InlineLink, #Text, #component_files, #docs_accordion_path, #docs_alert_dialog_path, #docs_alert_path, #docs_aspect_ratio_path, #docs_avatar_path, #docs_badge_path, #docs_installation_path, #docs_separator_path, #docs_sheet_path

Instance Method Details

#view_templateObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/ruby_ui/combobox/combobox_docs.rb', line 4

def view_template
  component = "Combobox"
  div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
    render Docs::Header.new(title: component, description: "Autocomplete input and command palette with a list of suggestions.")

    Heading(level: 2) { "Usage" }

    render Docs::VisualCodeExample.new(title: "Basic", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxInputTrigger(placeholder: "Select framework...")

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxRadio(name: "framework", value: "rails")
                  span { "Rails" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "framework", value: "hanami")
                  span { "Hanami" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "framework", value: "nextjs")
                  span { "Next.js" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "framework", value: "nuxt")
                  span { "Nuxt" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Popup", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxTrigger(placeholder: "Select framework...")

            ComboboxPopover do
              ComboboxSearchInput(placeholder: "Search framework...")

              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxRadio(name: "fw2", value: "rails")
                  span { "Rails" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "fw2", value: "hanami")
                  span { "Hanami" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "fw2", value: "nextjs")
                  span { "Next.js" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Multiple", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxBadgeTrigger(clear_button: true)

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "rails")
                  span { "Rails" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "hanami")
                  span { "Hanami" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "sinatra")
                  span { "Sinatra" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "nextjs", checked: true)
                  span { "Next.js" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "nuxt")
                  span { "Nuxt" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "svelte")
                  span { "SvelteKit" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "remix")
                  span { "Remix" }
                end
                ComboboxItem do
                  ComboboxCheckbox(name: "frameworks[]", value: "astro")
                  span { "Astro" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Groups", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxInputTrigger(placeholder: "Select food...")

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxListGroup(label: "Fruits") do
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "apple")
                    span { "Apple" }
                  end
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "banana")
                    span { "Banana" }
                  end
                end

                ComboboxListGroup(label: "Vegetables") do
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "broccoli")
                    span { "Broccoli" }
                  end
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "carrot")
                    span { "Carrot" }
                  end
                end

                ComboboxListGroup(label: "Grains") do
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "rice")
                    span { "Rice" }
                  end
                  ComboboxItem do
                    ComboboxRadio(name: "food", value: "wheat")
                    span { "Wheat" }
                  end
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Custom Items", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxInputTrigger(placeholder: "Select status...")

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxRadio(name: "status", value: "backlog", data: {text: "Backlog"})
                  svg(xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewbox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", class: "text-muted-foreground") { |s| s.circle(cx: "12", cy: "12", r: "10") }
                  span { "Backlog" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "status", value: "todo", data: {text: "Todo"})
                  svg(xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewbox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", class: "text-blue-500") { |s| s.circle(cx: "12", cy: "12", r: "10") }
                  span { "Todo" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "status", value: "done", data: {text: "Done"})
                  svg(xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewbox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", class: "text-green-500") { |s| s.path(d: "M22 11.08V12a10 10 0 1 1-5.93-9.14"); s.path(d: "m9 11 3 3L22 4") }
                  span { "Done" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Invalid", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxInputTrigger(placeholder: "Required field", aria: {invalid: "true"})

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxRadio(name: "req", value: "option1")
                  span { "Option 1" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "req", value: "option2")
                  span { "Option 2" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Disabled", context: self) do
      <<~RUBY
        div(class: "w-96 space-y-2") do
          Combobox do
            ComboboxTrigger(disabled: true, placeholder: "Disabled trigger")
          end

          Combobox do
            ComboboxInputTrigger(placeholder: "Disabled input", disabled: true)
          end
        end
      RUBY
    end

    render Docs::VisualCodeExample.new(title: "Auto Highlight", context: self) do
      <<~RUBY
        div(class: "w-96") do
          Combobox do
            ComboboxInputTrigger(placeholder: "Type to search...")

            ComboboxPopover do
              ComboboxList do
                ComboboxEmptyState { "No results found." }

                ComboboxItem do
                  ComboboxRadio(name: "color", value: "red")
                  span { "Red" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "color", value: "green")
                  span { "Green" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "color", value: "blue")
                  span { "Blue" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "color", value: "yellow")
                  span { "Yellow" }
                end
                ComboboxItem do
                  ComboboxRadio(name: "color", value: "purple")
                  span { "Purple" }
                end
              end
            end
          end
        end
      RUBY
    end

    render Components::ComponentSetup::Tabs.new(component_name: component)

    render Docs::ComponentsTable.new(component_files(component))
  end
end