Class: ShadcnPhlexcomponents::ComboboxContent

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/combobox.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(include_blank: false, side: :bottom, align: :center, aria_id: nil, search_error_text: nil, search_empty_text: nil, search_placeholder_text: nil, **attributes) ⇒ ComboboxContent

Returns a new instance of ComboboxContent.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 206

def initialize(
  include_blank: false,
  side: :bottom,
  align: :center,
  aria_id: nil,
  search_error_text: nil,
  search_empty_text: nil,
  search_placeholder_text: nil,
  **attributes
)
  @include_blank = include_blank
  @side = side
  @align = align
  @search_error_text = search_error_text
  @search_empty_text = search_empty_text
  @search_placeholder_text = search_placeholder_text
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributes ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 269

def default_attributes
  {
    id: "#{@aria_id}-content",
    tabindex: -1,
    role: "listbox",
    aria: {
      labelledby: "#{@aria_id}-trigger",
      orientation: "vertical",
    },
    data: {
      side: @side,
      align: @align,
      state: "closed",
      combobox_target: "content",
      action: "        combobox:click:outside->combobox#clickOutside\n        keydown.up->combobox#highlightItem:prevent\n        keydown.down->combobox#highlightItem:prevent\n        keydown.enter->combobox#select:prevent\n      HEREDOC\n    },\n  }\nend\n",

#view_template ⇒ Object



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
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 226

def view_template(&)
  ComboboxContentContainer do
    div(**@attributes) do
      template do
        ComboboxGroup do
          ComboboxLabel { "" }
        end
      end

      label(
        class: "sr-only",
        id: "#{@aria_id}-search-label",
        for: "#{@aria_id}-search",
      ) { @search_placeholder_text }

      ComboboxSearchInputContainer do
        icon("search", class: "size-4 shrink-0 opacity-50")
        ComboboxSearchInput(aria_id: @aria_id, search_placeholder_text: @search_placeholder_text)
      end

      ComboboxListContainer do
        ComboboxText(target: "empty") { @search_empty_text }
        ComboboxText(target: "error") { @search_error_text }
        ComboboxText(target: "loading") do
          div(class: "flex justify-center", aria: { label: "Loading" }) do
            icon("loader-circle", class: "animate-spin")
          end
        end

        div(id: "#{@aria_id}-list", data: { combobox_target: "list" }) do
          if @include_blank
            ComboboxItem(aria_id: @aria_id, value: "", class: "h-8") do
              @include_blank.is_a?(String) ? @include_blank : ""
            end
          end

          yield
        end
      end
    end
  end
end