Class: Daisy::DataDisplay::CollapseComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataDisplay::CollapseComponent
- 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
-
#checkbox ⇒ Boolean
readonly
Whether to use a checkbox for toggle state (true) or focus/tabindex mode (false).
-
#simple_title ⇒ String
readonly
The title text when using the simple title option.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
- #has_title? ⇒ Boolean
-
#initialize(*args, **kws, &block) ⇒ CollapseComponent
constructor
Creates a new collapse component.
- #setup_component ⇒ Object
- #setup_title ⇒ Object
- #setup_wrapper ⇒ Object
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.
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
#checkbox ⇒ Boolean (readonly)
Returns 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_title ⇒ String (readonly)
Returns 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_render ⇒ Object
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
97 98 99 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 97 def has_title? title? || @simple_title.present? end |
#setup_component ⇒ Object
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_title ⇒ Object
89 90 91 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 89 def setup_title add_css(:title, "collapse-title") end |
#setup_wrapper ⇒ Object
93 94 95 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 93 def setup_wrapper add_css(:wrapper, "collapse-content") end |