Class: Shadcn::Select::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Select::Component
- Includes:
- Concerns::SubmitsValue
- Defined in:
- app/components/shadcn/select/component.rb
Overview
Port of registry/new-york-v4/ui/select.tsx
A role="combobox" trigger driving a role="listbox" layer. When name:
is given a hidden input mirrors the selection, the way Radix's BubbleSelect
does, so the control submits with the form.
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#searchable ⇒ Object
readonly
Returns the value of attribute searchable.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#side_offset ⇒ Object
readonly
Returns the value of attribute side_offset.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value: nil, name: nil, placeholder: nil, open: false, side: :bottom, align: :center, side_offset: 4, searchable: false, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods included from Concerns::SubmitsValue
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value: nil, name: nil, placeholder: nil, open: false, side: :bottom, align: :center, side_offset: 4, searchable: false, **attributes) ⇒ Component
Returns a new instance of Component.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/components/shadcn/select/component.rb', line 26 def initialize(value: nil, name: nil, placeholder: nil, open: false, side: :bottom, align: :center, side_offset: 4, searchable: false, **attributes) @searchable = searchable @value = value.to_s @name = name @placeholder = placeholder.to_s @open = open @side = side&.to_sym || :bottom @align = align&.to_sym || :center @side_offset = side_offset super(**attributes) end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def align @align end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def name @name end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def open @open end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def placeholder @placeholder end |
#searchable ⇒ Object (readonly)
Returns the value of attribute searchable.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def searchable @searchable end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def side @side end |
#side_offset ⇒ Object (readonly)
Returns the value of attribute side_offset.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def side_offset @side_offset end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
24 25 26 |
# File 'app/components/shadcn/select/component.rb', line 24 def value @value end |
Instance Method Details
#call ⇒ Object
54 55 56 |
# File 'app/components/shadcn/select/component.rb', line 54 def call render_element(body: safe_join([ trigger, select_content, content, hidden_input ].compact)) end |
#element_attributes(**defaults) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/shadcn/select/component.rb', line 40 def element_attributes(**defaults) super(**{ style: merged_style(CONTENTS_STYLE), "data-controller" => "shadcn--select", "data-shadcn--select-open-value" => open, "data-shadcn--select-value-value" => value, "data-shadcn--select-placeholder-value" => placeholder, "data-shadcn--select-side-value" => side, "data-shadcn--select-align-value" => align, "data-shadcn--select-side-offset-value" => side_offset, "data-shadcn--select-searchable-value" => searchable }.merge(defaults)) end |