Class: FoxTail::FAB::ItemComponent

Inherits:
IconButtonComponent
  • Object
show all
Defined in:
app/components/fox_tail/f_a_b/item_component.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{color: :light, variant: :solid}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(icon_or_attributes = {}, html_attributes = {}) ⇒ ItemComponent

Returns a new instance of ItemComponent.



10
11
12
13
14
15
16
17
18
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 10

def initialize(icon_or_attributes = {}, html_attributes = {})
  if icon_or_attributes.is_a? Hash
    icon_or_attributes.reverse_merge! DEFAULT_OPTIONS
  else
    html_attributes.reverse_merge! DEFAULT_OPTIONS
  end

  super
end

Instance Method Details

#before_renderObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 20

def before_render
  super

  html_attributes[:class] = classnames theme.apply(:root, self), html_class

  if label_style == :tooltip && self.class.use_stimulus?
    trigger_component = FoxTail::TooltipTriggerComponent.new tag_id, "##{tooltip_id}", trigger_type: :hover
    options = trigger_component.stimulus_controller_options
    attributes = FoxTail::TooltipTriggerComponent.stimulus_controller.attributes options
    stimulus_merger.merge_attributes! html_attributes, attributes
  end
end

#callObject



48
49
50
51
52
53
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 48

def call
  capture do
    concat render_button
    concat render_tooltip if label_style == :tooltip
  end
end

#sizeObject



41
42
43
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 41

def size
  :fab
end

#tag_idObject



33
34
35
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 33

def tag_id
  html_attributes[:id] ||= :"fab_item_#{SecureRandom.hex(4)}"
end

#tooltip_idObject



37
38
39
# File 'app/components/fox_tail/f_a_b/item_component.rb', line 37

def tooltip_id
  :"tooltip_#{tag_id}"
end