Class: Daisy::DataDisplay::CollapseComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/data_display/collapse_component.rb

Overview

The Collapse component creates an expandable/collapsible section of content with a title that toggles visibility. It’s similar to the Accordion component but designed for standalone use rather than groups.

Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary collapse

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws, &block) ⇒ CollapseComponent

Creates a new collapse component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • title (String)

    The text to display in the title bar. You can also provide custom title content using the title slot.

  • checkbox (Boolean)

    Whether to use a checkbox for toggle state (true) or focus/tabindex mode (false). Defaults to true.

  • tip (String)

    The tooltip text to display when hovering over the component.



70
71
72
73
74
75
# File 'app/components/daisy/data_display/collapse_component.rb', line 70

def initialize(*args, **kws, &block)
  super

  @simple_title = config_option(:title)
  @checkbox = config_option(:checkbox, true)
end

Instance Attribute Details

#checkboxBoolean (readonly)

Returns Whether to use a checkbox for toggle state (true) or focus/tabindex mode (false).

Returns:

  • (Boolean)

    Whether to use a checkbox for toggle state (true) or focus/tabindex mode (false).



54
55
56
# File 'app/components/daisy/data_display/collapse_component.rb', line 54

def checkbox
  @checkbox
end

#simple_titleString (readonly)

Returns The title text when using the simple title option.

Returns:

  • (String)

    The title text when using the simple title option.



50
51
52
# File 'app/components/daisy/data_display/collapse_component.rb', line 50

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



77
78
79
80
81
82
# File 'app/components/daisy/data_display/collapse_component.rb', line 77

def before_render
  setup_component # Set base styles/attributes
  super           # Run concern setup hooks
  setup_title     # Set title part styles
  setup_wrapper   # Set wrapper part styles
end

#has_title?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/components/daisy/data_display/collapse_component.rb', line 97

def has_title?
  title? || @simple_title.present?
end

#setup_componentObject



84
85
86
87
# File 'app/components/daisy/data_display/collapse_component.rb', line 84

def setup_component
  add_css(:component, "collapse")
  add_html(:component, { tabindex: 0 }) unless @checkbox
end

#setup_titleObject



89
90
91
# File 'app/components/daisy/data_display/collapse_component.rb', line 89

def setup_title
  add_css(:title, "collapse-title")
end

#setup_wrapperObject



93
94
95
# File 'app/components/daisy/data_display/collapse_component.rb', line 93

def setup_wrapper
  add_css(:wrapper, "collapse-content")
end