Class: FoxTail::TriggerBaseComponent

Inherits:
BaseComponent show all
Includes:
Concerns::HasStimulusController, Concerns::Identifiable
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_or_selector, selector_or_attributes = {}, html_attributes = {}, &block) ⇒ TriggerBaseComponent

Returns a new instance of TriggerBaseComponent.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/fox_tail/trigger_base_component.rb', line 11

def initialize(id_or_selector, selector_or_attributes = {}, html_attributes = {}, &block)
  if selector_or_attributes.is_a? Hash
    html_attributes = selector_or_attributes
    selector_or_attributes = id_or_selector
  else
    __id_argument_deprecated_warning
    html_attributes[:id] = id_or_selector
  end

  super(html_attributes)
  @selector = selector_or_attributes
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#selectorObject (readonly)

Returns the value of attribute selector.



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

def selector
  @selector
end

Instance Method Details

#before_renderObject



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

def before_render
  super

  generate_unique_id
  html_attributes[:class] = html_class
end

#block?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/components/fox_tail/trigger_base_component.rb', line 25

def block?
  !!block
end

#callObject



40
41
42
# File 'app/components/fox_tail/trigger_base_component.rb', line 40

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

#render?Boolean

Returns:

  • (Boolean)


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

def render?
  content? || block?
end

#stimulus_controller_optionsObject



44
45
46
47
48
49
# File 'app/components/fox_tail/trigger_base_component.rb', line 44

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