Class: Shadcn::Accordion::Component

Inherits:
Shadcn::ApplicationViewComponent show all
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

Attributes inherited from Shadcn::ApplicationViewComponent

#attributes

Instance Method Summary collapse

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.

Parameters:

  • type (:single, :multiple) (defaults to: :single)
  • collapsible (Boolean) (defaults to: false)

    may the open item be closed again (single only)

  • value (String, Array) (defaults to: nil)

    initially open item value(s)



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

#collapsibleObject (readonly)

Returns the value of attribute collapsible.



15
16
17
# File 'app/components/shadcn/accordion/component.rb', line 15

def collapsible
  @collapsible
end

#orientationObject (readonly)

Returns the value of attribute orientation.



15
16
17
# File 'app/components/shadcn/accordion/component.rb', line 15

def orientation
  @orientation
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'app/components/shadcn/accordion/component.rb', line 15

def type
  @type
end

#valueObject (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

#callObject



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