Class: Shadcn::Accordion::Component
- Inherits:
-
Shadcn::ApplicationViewComponent
- Object
- ViewComponent::Base
- Shadcn::ApplicationViewComponent
- Shadcn::Accordion::Component
- Defined in:
- app/components/shadcn/accordion/component.rb
Overview
Port of registry/new-york-v4/ui/accordion.tsx
Radix's Accordion.Root renders a plain div; the shadcn--accordion
Stimulus controller supplies the open/close state machine, the roving
arrow-key navigation and the ARIA wiring between triggers and panels.
Constant Summary
Constants inherited from Shadcn::ApplicationViewComponent
Shadcn::ApplicationViewComponent::CONTENTS_STYLE, Shadcn::ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#collapsible ⇒ Object
readonly
Returns the value of attribute collapsible.
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Shadcn::ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(type: :single, collapsible: false, value: nil, orientation: :vertical, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from Shadcn::ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(type: :single, collapsible: false, value: nil, orientation: :vertical, **attributes) ⇒ Component
Returns a new instance of Component.
20 21 22 23 24 25 26 27 |
# File 'app/components/shadcn/accordion/component.rb', line 20 def initialize(type: :single, collapsible: false, value: nil, orientation: :vertical, **attributes) @type = type&.to_sym || :single @collapsible = collapsible @value = Array(value).compact.join(",") @orientation = orientation&.to_sym || :vertical super(**attributes) end |
Instance Attribute Details
#collapsible ⇒ Object (readonly)
Returns the value of attribute collapsible.
15 16 17 |
# File 'app/components/shadcn/accordion/component.rb', line 15 def collapsible @collapsible end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
15 16 17 |
# File 'app/components/shadcn/accordion/component.rb', line 15 def orientation @orientation end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'app/components/shadcn/accordion/component.rb', line 15 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
15 16 17 |
# File 'app/components/shadcn/accordion/component.rb', line 15 def value @value end |
Instance Method Details
#call ⇒ Object
39 40 41 |
# File 'app/components/shadcn/accordion/component.rb', line 39 def call render_element(body: safe_join([ items, content ].flatten.compact)) end |
#element_attributes(**defaults) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/components/shadcn/accordion/component.rb', line 29 def element_attributes(**defaults) super(**{ "data-orientation" => orientation, "data-controller" => "shadcn--accordion", "data-shadcn--accordion-type-value" => type, "data-shadcn--accordion-collapsible-value" => collapsible, "data-shadcn--accordion-value-value" => value }.merge(defaults)) end |