Class: FoxTail::CollapsibleComponent
- Inherits:
-
BaseComponent
show all
- Includes:
- FoxTail::Concerns::HasStimulusController, FoxTail::Concerns::Identifiable
- Defined in:
- app/components/fox_tail/collapsible_component.rb
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary
#html_attributes
Instance Method Summary
collapse
classname_merger, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
fox_tail_config
Constructor Details
#initialize(id_or_attributes = {}, html_attributes = {}) ⇒ CollapsibleComponent
Returns a new instance of CollapsibleComponent.
14
15
16
17
18
19
20
21
22
23
|
# File 'app/components/fox_tail/collapsible_component.rb', line 14
def initialize(id_or_attributes = {}, html_attributes = {})
if id_or_attributes.is_a? Hash
html_attributes = id_or_attributes
else
__id_argument_deprecated_warning
html_attributes[:id] = id_or_attributes
end
super(html_attributes)
end
|
Instance Method Details
#before_render ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'app/components/fox_tail/collapsible_component.rb', line 29
def before_render
super
generate_unique_id
html_attributes[:class] = classnames theme.apply(:root, self),
!open? && theme.apply("root/collapsed", self),
html_class
end
|
#call ⇒ Object
38
39
40
41
42
43
|
# File 'app/components/fox_tail/collapsible_component.rb', line 38
def call
capture do
concat trigger if trigger?
concat content_tag(:div, content, html_attributes)
end
end
|
#stimulus_controller_options ⇒ Object
45
46
47
48
49
50
|
# File 'app/components/fox_tail/collapsible_component.rb', line 45
def stimulus_controller_options
{
open: open?,
hidden_classes: theme.apply("root/collapsed", self)
}
end
|
#trigger_id ⇒ Object
25
26
27
|
# File 'app/components/fox_tail/collapsible_component.rb', line 25
def trigger_id
options[:trigger_id] ||= :"#{id}_trigger"
end
|