Class: Fluxbit::AccordionComponent

Inherits:
Component
  • Object
show all
Includes:
Config::AccordionComponent
Defined in:
app/components/fluxbit/accordion_component.rb

Overview

The ‘Fluxbit::AccordionComponent` renders an accordion component following Flowbite styles. It supports collapsible panels with headers and content, customizable icons, and various styling options.

Defined Under Namespace

Classes: Panel

Constant Summary

Constants inherited from Component

Component::ComponentObj

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ Fluxbit::AccordionComponent

Initializes the accordion component with the given properties.

Parameters:

  • **props (Hash)

    The properties to customize the accordion.

  • props (Hash)

    a customizable set of options

Options Hash (**props):

  • :flush (Boolean) — default: false

    When true, removes borders and rounded corners for seamless integration.

  • :color (Symbol, String) — default: :default

    The color theme for accordion panels (default, light, primary, secondary, success, danger, warning, info, dark).

  • :collapse_all (Boolean) — default: false

    When true, allows all panels to be collapsed simultaneously. When false, keeps at least one panel open.

  • :remove_class (String) — default: ''

    CSS classes to remove from the default class list.

  • **props (Hash)

    Remaining options declared as HTML attributes for the accordion container.



28
29
30
31
32
33
34
# File 'app/components/fluxbit/accordion_component.rb', line 28

def initialize(**props)
  super
  @props = props
  @flush = options(@props.delete(:flush), default: @@flush)
  @color = options(@props.delete(:color), collection: styles[:colors].keys, default: @@color).to_sym
  @collapse_all = options(@props.delete(:collapse_all), default: @@collapse_all)
end

Instance Method Details

#before_renderObject



36
37
38
39
40
41
42
43
44
# File 'app/components/fluxbit/accordion_component.rb', line 36

def before_render
  add to: @props, first_element: true, class: [
    styles[:base],
    @flush ? "" : "border border-gray-200 dark:border-gray-700 rounded-xl"
  ]
  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
  @props[:id] ||= fx_id
  @props["data-accordion"] = @collapse_all ? "collapse" : "open"
end

#callObject



46
47
48
49
50
# File 'app/components/fluxbit/accordion_component.rb', line 46

def call
  tag.div(**@props) do
    safe_join(panels)
  end
end