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
In details mode the toggle is the <summary> element itself, so
the component keeps native disclosure semantics: it works with no
JavaScript, stays keyboard-accessible, exposes the open
property / attribute for programmatic control (e.g.
details.open = true while filtering a list), and interactive
elements near the title remain clickable — checkbox mode overlays an
invisible input across the title area, which can swallow those
clicks.
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).
-
#details ⇒ Boolean
readonly
Whether to render native
<details>/<summary>elements instead of the checkbox / focus mechanisms. -
#open ⇒ Boolean
readonly
Whether a details-mode collapse starts expanded.
-
#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.
-
#render_checkbox? ⇒ Boolean
Details mode toggles via its summary element, so the hidden checkbox input is only rendered for checkbox mode.
- #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
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(*args, **kws, &block) ⇒ CollapseComponent
Creates a new collapse component.
106 107 108 109 110 111 112 113 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 106 def initialize(*args, **kws, &block) super @simple_title = config_option(:title) @checkbox = config_option(:checkbox, true) @details = config_option(:details, false) @open = config_option(:open, false) end |
Instance Attribute Details
#checkbox ⇒ Boolean (readonly)
Returns Whether to use a checkbox for toggle state (true) or focus/tabindex mode (false).
73 74 75 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 73 def checkbox @checkbox end |
#details ⇒ Boolean (readonly)
Returns Whether to render native <details> / <summary>
elements instead of the checkbox / focus mechanisms.
77 78 79 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 77 def details @details end |
#open ⇒ Boolean (readonly)
Returns Whether a details-mode collapse starts expanded.
80 81 82 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 80 def open @open end |
#simple_title ⇒ String (readonly)
Returns The title text when using the simple title option.
69 70 71 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 69 def simple_title @simple_title end |
Instance Method Details
#before_render ⇒ Object
115 116 117 118 119 120 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 115 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
148 149 150 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 148 def has_title? title? || @simple_title.present? end |
#render_checkbox? ⇒ Boolean
Details mode toggles via its summary element, so the hidden checkbox input is only rendered for checkbox mode.
140 141 142 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 140 def render_checkbox? @checkbox && !@details end |
#setup_component ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 122 def setup_component add_css(:component, "collapse") if @details set_tag_name(:component, :details) add_html(:component, { open: true }) if @open else add_html(:component, { tabindex: 0 }) unless @checkbox end end |
#setup_title ⇒ Object
133 134 135 136 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 133 def setup_title add_css(:title, "collapse-title") set_tag_name(:title, :summary) if @details end |
#setup_wrapper ⇒ Object
144 145 146 |
# File 'app/components/daisy/data_display/collapse_component.rb', line 144 def setup_wrapper add_css(:wrapper, "collapse-content") end |