Class: Shadcn::AccordionComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/accordion_component.rb

Overview

Accordion component for collapsible content sections Matches shadcn/ui Accordion component Uses Stimulus for interactivity

Examples:

Single accordion

<%= render Shadcn::AccordionComponent.new(type: :single, collapsible: true) do |accordion| %>
  <% accordion.with_item(value: "item-1") do |item| %>
    <% item.with_trigger { "Is it accessible?" } %>
    <% item.with_body { "Yes. It adheres to the WAI-ARIA design pattern." } %>
  <% end %>
  <% accordion.with_item(value: "item-2") do |item| %>
    <% item.with_trigger { "Is it styled?" } %>
    <% item.with_body { "Yes. It comes with default styles." } %>
  <% end %>
<% end %>

Multiple accordion

<%= render Shadcn::AccordionComponent.new(type: :multiple) do |accordion| %>
  ...
<% end %>

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(type: :single, collapsible: false, default_value: nil, **options) ⇒ AccordionComponent

Returns a new instance of AccordionComponent.

Parameters:

  • type (Symbol) (defaults to: :single)

    Accordion type (:single, :multiple)

  • collapsible (Boolean) (defaults to: false)

    For single type, whether all items can be collapsed

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

    Initially expanded item(s)



33
34
35
36
37
38
# File 'app/components/shadcn/accordion_component.rb', line 33

def initialize(type: :single, collapsible: false, default_value: nil, **options)
  super(**options)
  @type = type.to_sym
  @collapsible = collapsible
  @default_value = default_value
end