Class: FoxTail::PopoverComponent

Inherits:
BaseComponent show all
Includes:
Concerns::HasStimulusController
Defined in:
app/components/fox_tail/popover_component.rb

Defined Under Namespace

Classes: StimulusController

Instance Attribute Summary collapse

Attributes inherited from BaseComponent

#html_attributes

Instance Method Summary collapse

Methods inherited from BaseComponent

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

Methods inherited from Base

fox_tail_config

Constructor Details

#initialize(id, html_attributes = {}) ⇒ PopoverComponent

Returns a new instance of PopoverComponent.



30
31
32
33
# File 'app/components/fox_tail/popover_component.rb', line 30

def initialize(id, html_attributes = {})
  super(html_attributes)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'app/components/fox_tail/popover_component.rb', line 6

def id
  @id
end

Instance Method Details

#before_renderObject



39
40
41
42
43
44
45
46
# File 'app/components/fox_tail/popover_component.rb', line 39

def before_render
  super

  html_attributes[:id] = id
  html_attributes[:role] ||= :tooltip
  html_attributes[:class] = classnames theme.apply(:root, self), theme.apply("root/hidden", self), html_class
  stimulus_controller.merge! html_attributes, stimulus_controller_options if use_stimulus?
end

#callObject



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

def call
  capture do
    concat trigger if trigger?
    concat render_popover
  end
end

#stimulus_controller_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/components/fox_tail/popover_component.rb', line 55

def stimulus_controller_options
  {
    trigger_id: trigger_id,
    placement: placement,
    offset: offset,
    shift: shift,
    inline: inline?,
    delay: delay,
    trigger_type: trigger_type,
    visible_classes: theme.apply("root/visible", self),
    hidden_classes: theme.apply("root/hidden", self)
  }
end

#trigger_idObject



35
36
37
# File 'app/components/fox_tail/popover_component.rb', line 35

def trigger_id
  options[:trigger_id] ||= :"#{id}_trigger"
end