Class: ShadcnPhlexcomponents::ComboboxTrigger

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(id: nil, value: nil, placeholder: nil, aria_id: nil, **attributes) ⇒ ComboboxTrigger

Returns a new instance of ComboboxTrigger.



150
151
152
153
154
155
156
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 150

def initialize(id: nil, value: nil, placeholder: nil, aria_id: nil, **attributes)
  @id = id
  @value = value
  @placeholder = placeholder
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributesObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 166

def default_attributes
  {
    type: "button",
    id: @id,
    role: "combobox",
    aria: {
      autocomplete: "none",
      expanded: false,
      controls: "#{@aria_id}-content",
    },
    data: {
      placeholder: @placeholder,
      has_value: @value.present?.to_s,
      action: "        click->combobox#toggle\n        keydown.down->combobox#open:prevent\n      HEREDOC\n      combobox_target: \"trigger\",\n    },\n  }\nend\n",

#view_templateObject



158
159
160
161
162
163
164
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 158

def view_template
  button(**@attributes) do
    ComboboxTriggerText(value: @value, placeholder: @placeholder)

    icon("chevron-down", class: "size-4 opacity-50 text-foreground")
  end
end