Class: FoxTail::CollapsibleComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- Base
- BaseComponent
- FoxTail::CollapsibleComponent
- Includes:
- FoxTail::Concerns::HasStimulusController
- Defined in:
- app/components/fox_tail/collapsible_component.rb
Direct Known Subclasses
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(id, html_attributes = {}) ⇒ CollapsibleComponent
constructor
A new instance of CollapsibleComponent.
- #stimulus_controller_options ⇒ Object
- #trigger_id ⇒ Object
Methods inherited from BaseComponent
classname_merger, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
Constructor Details
#initialize(id, html_attributes = {}) ⇒ CollapsibleComponent
Returns a new instance of CollapsibleComponent.
15 16 17 18 |
# File 'app/components/fox_tail/collapsible_component.rb', line 15 def initialize(id, html_attributes = {}) super(html_attributes) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'app/components/fox_tail/collapsible_component.rb', line 6 def id @id end |
Instance Method Details
#before_render ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/components/fox_tail/collapsible_component.rb', line 24 def before_render super html_attributes[:id] = id html_attributes[:class] = classnames theme.apply(:root, self), !open? && theme.apply("root/collapsed", self), html_class end |
#call ⇒ Object
33 34 35 36 37 38 |
# File 'app/components/fox_tail/collapsible_component.rb', line 33 def call capture do concat trigger if trigger? concat content_tag(:div, content, html_attributes) end end |
#stimulus_controller_options ⇒ Object
40 41 42 43 44 45 |
# File 'app/components/fox_tail/collapsible_component.rb', line 40 def { open: open?, hidden_classes: theme.apply("root/collapsed", self) } end |
#trigger_id ⇒ Object
20 21 22 |
# File 'app/components/fox_tail/collapsible_component.rb', line 20 def trigger_id [:trigger_id] ||= :"#{id}_trigger" end |