Class: FoxTail::ClickableComponent
- Inherits:
-
BaseComponent
show all
- Includes:
- FoxTail::Concerns::HasStimulusController
- Defined in:
- app/components/fox_tail/clickable_component.rb
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary
#html_attributes
Class Method Summary
collapse
Instance Method Summary
collapse
classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
fox_tail_config
Class Method Details
.stimulus_controller_name ⇒ Object
81
82
83
|
# File 'app/components/fox_tail/clickable_component.rb', line 81
def stimulus_controller_name
:clickable
end
|
Instance Method Details
#before_render ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/components/fox_tail/clickable_component.rb', line 24
def before_render
super
html_attributes[:class] = root_classes
if root_tag_name == :a
html_attributes[:href] = url
html_attributes["aria-disabled"] = true if disabled?
elsif root_tag_name == :button
html_attributes[:role] ||= :button
html_attributes[:type] ||= :button
html_attributes[:disabled] = true if disabled?
end
end
|
#call(&block) ⇒ Object
39
40
41
42
|
# File 'app/components/fox_tail/clickable_component.rb', line 39
def call(&block)
captured_content = block ? capture(&block) : content
content_tag root_tag_name, captured_content, html_attributes
end
|
#link? ⇒ Boolean
16
17
18
|
# File 'app/components/fox_tail/clickable_component.rb', line 16
def link?
url? && ((!disabled? && !loading?) || controlled?)
end
|
#root_tag_name ⇒ Object
20
21
22
|
# File 'app/components/fox_tail/clickable_component.rb', line 20
def root_tag_name
link? ? :a : :button
end
|
#stimulus_controller_options ⇒ Object
44
45
46
|
# File 'app/components/fox_tail/clickable_component.rb', line 44
def stimulus_controller_options
{state: stimulus_state, active_classes: active_classes, disabled_classes: disabled_classes}
end
|
#use_stimulus? ⇒ Boolean
12
13
14
|
# File 'app/components/fox_tail/clickable_component.rb', line 12
def use_stimulus?
controlled? && self.class.use_stimulus?
end
|