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

Attributes inherited from BaseComponent

#html_attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

This class inherits a constructor from FoxTail::BaseComponent

Class Method Details

.stimulus_controller_nameObject



81
82
83
# File 'app/components/fox_tail/clickable_component.rb', line 81

def stimulus_controller_name
  :clickable
end

Instance Method Details

#before_renderObject



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
   root_tag_name, captured_content, html_attributes
end

#link?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/components/fox_tail/clickable_component.rb', line 16

def link?
  url? && ((!disabled? && !loading?) || controlled?)
end

#root_tag_nameObject



20
21
22
# File 'app/components/fox_tail/clickable_component.rb', line 20

def root_tag_name
  link? ? :a : :button
end

#stimulus_controller_optionsObject



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

Returns:

  • (Boolean)


12
13
14
# File 'app/components/fox_tail/clickable_component.rb', line 12

def use_stimulus?
  controlled? && self.class.use_stimulus?
end