Class: FoxTail::TriggerBaseComponent

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

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, selector, html_attributes = {}, &block) ⇒ TriggerBaseComponent

Returns a new instance of TriggerBaseComponent.



10
11
12
13
14
15
# File 'app/components/fox_tail/trigger_base_component.rb', line 10

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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#selectorObject (readonly)

Returns the value of attribute selector.



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

def selector
  @selector
end

Instance Method Details

#before_renderObject



21
22
23
24
25
26
# File 'app/components/fox_tail/trigger_base_component.rb', line 21

def before_render
  super

  html_attributes[:id] = id
  html_attributes[:class] = html_class
end

#block?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/fox_tail/trigger_base_component.rb', line 17

def block?
  !!block
end

#callObject



32
33
34
# File 'app/components/fox_tail/trigger_base_component.rb', line 32

def call
  block? ? view_context.capture(self, &block) : content
end

#render?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/components/fox_tail/trigger_base_component.rb', line 28

def render?
  content? || block?
end

#stimulus_controller_optionsObject



36
37
38
39
40
41
# File 'app/components/fox_tail/trigger_base_component.rb', line 36

def stimulus_controller_options
  {
    selector: selector,
    trigger_type: trigger_type
  }
end