Class: Daisy::DataDisplay::AccordionComponent::AccordionSectionComponent
- Inherits:
-
LocoMotion::BasicComponent
- Object
- LocoMotion::BaseComponent
- LocoMotion::BasicComponent
- Daisy::DataDisplay::AccordionComponent::AccordionSectionComponent
- Defined in:
- app/components/daisy/data_display/accordion_component.rb
Overview
Renders a single section of the accordion.
Instance Attribute Summary collapse
-
#simple_title ⇒ String
readonly
Accessor for the
titlestring passed via the component config.
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(**kws, &block) ⇒ AccordionSectionComponent
constructor
Creates a new accordion section.
- #setup_component ⇒ Object
- #setup_content ⇒ Object
- #setup_radio_button ⇒ Object
- #setup_title ⇒ Object
Methods inherited from LocoMotion::BasicComponent
Constructor Details
#initialize(**kws, &block) ⇒ AccordionSectionComponent
Creates a new accordion section.
82 83 84 85 86 87 88 89 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 82 def initialize(**kws, &block) super @value = config_option(:value) @checked = config_option(:checked, false) @simple_title = config_option(:title) @name = config_option(:name) end |
Instance Attribute Details
#simple_title ⇒ String (readonly)
Returns Accessor for the title string passed via the component
config.
64 65 66 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 64 def simple_title @simple_title end |
Instance Method Details
#before_render ⇒ Object
91 92 93 94 95 96 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 91 def before_render setup_component setup_title setup_content end |
#call ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 121 def call part(:component) do # Render the radio button which allows opening / closing concat(part(:radio_button)) # Render the title slot, or simple title if provided if title? concat(part(:title) { concat(title) }) elsif @simple_title.present? concat(part(:title) { @simple_title }) end # Render the content concat(part(:content) { content }) end end |
#setup_component ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 98 def setup_component # Reset the name to the config option or the parent name if available @name = config_option(:name, loco_parent.name) add_css(:component, "collapse") add_css(:component, "collapse-arrow") if loco_parent.config.modifiers.include?(:arrow) add_css(:component, "collapse-plus") if loco_parent.config.modifiers.include?(:plus) end |
#setup_content ⇒ Object
117 118 119 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 117 def setup_content add_css(:content, "collapse-content") end |
#setup_radio_button ⇒ Object
107 108 109 110 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 107 def set_tag_name(:radio_button, :input) add_html(:radio_button, { type: "radio", name: @name, value: @value, checked: @checked }) end |
#setup_title ⇒ Object
112 113 114 115 |
# File 'app/components/daisy/data_display/accordion_component.rb', line 112 def setup_title set_tag_name(:title, :h2) add_css(:title, "collapse-title text-lg font-bold") end |