Class: DaisyUI::AccordionItem

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/daisy_ui/data_display/accordion_item.rb

Overview

Renders a single accordion item within an AccordionComponent.

Examples:

Basic usage

<%= render(AccordionItemComponent.new(title: "Item 1")) do %>
  Content for item 1
<% end %>

With arrow indicator

<%= render(AccordionItemComponent.new(
  title: "Item 1",
  indicator: :arrow
)) do %>
  Content for item 1
<% end %>

With plus/minus indicator

<%= render(AccordionItemComponent.new(
  title: "Item 1",
  indicator: :plus
)) do %>
  Content for item 1
<% end %>

As part of a radio group

<%= render(AccordionItemComponent.new(
  title: "Item 1",
  input_type: :radio,
  name: "group1",
  checked: true
)) do %>
  Content for item 1
<% end %>

With custom colors

<%= render(AccordionItemComponent.new(
  title: "Item 1",
  bg_color: "bg-primary",
  text_color: "text-primary-content",
  border_color: "border-primary-focus"
)) do %>
  Content for item 1
<% end %>

Constant Summary collapse

INDICATORS =
%i[arrow plus].freeze
INPUT_TYPES =
%i[radio checkbox].freeze

Instance Method Summary collapse

Constructor Details

#initialize(title:, name:, text: nil, checked: false, indicator: nil, input_type: :checkbox, join: false, bg_color: nil, text_color: nil, border_color: nil, padding: nil, **system_arguments) ⇒ AccordionItem

Returns a new instance of AccordionItem.

Parameters:

  • title (String)

    The title text for the accordion item

  • name (String)

    Input name for radio/checkbox behavior

  • indicator (Symbol) (defaults to: nil)

    Type of indicator to show (:arrow, :plus)

  • input_type (Symbol) (defaults to: :checkbox)

    Type of input to use (:radio, :checkbox)

  • checked (Boolean) (defaults to: false)

    Whether the item is initially expanded

  • join (Boolean) (defaults to: false)

    Style for joined items

  • bg_color (String) (defaults to: nil)

    Background color class

  • text_color (String) (defaults to: nil)

    Text color class

  • border_color (String) (defaults to: nil)

    Border color class

  • padding (String) (defaults to: nil)

    Padding class

  • system_arguments (Hash)

    Additional HTML attributes



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/components/daisy_ui/data_display/accordion_item.rb', line 61

def initialize(title:, name:, text: nil, checked: false, indicator: nil,
               input_type: :checkbox, join: false, bg_color: nil, text_color: nil,
               border_color: nil, padding: nil, **system_arguments)
  @title = title
  @name = name
  @text = text
  @checked = checked
  @indicator = indicator
  @input_type = input_type
  @join = join
  @bg_color = bg_color
  @text_color = text_color
  @border_color = border_color
  @padding = padding
  super(**system_arguments)
end

Instance Method Details

#callObject



78
79
80
81
82
# File 'app/components/daisy_ui/data_display/accordion_item.rb', line 78

def call
  tag.div(**html_attributes) do
    safe_join([render_input, render_title, render_content].compact)
  end
end