Class: FoxTail::DropdownComponent

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

Defined Under Namespace

Classes: StimulusController

Instance Attribute Summary

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_attributes = {}, html_attributes = {}) ⇒ DropdownComponent

Returns a new instance of DropdownComponent.



40
41
42
43
44
45
46
47
48
49
# File 'app/components/fox_tail/dropdown_component.rb', line 40

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

  super(html_attributes)
end

Instance Method Details

#before_renderObject



55
56
57
58
59
60
61
62
# File 'app/components/fox_tail/dropdown_component.rb', line 55

def before_render
  super

  generate_unique_id
  html_attributes[:class] = classnames theme.apply(:root, self),
    theme.apply("root/hidden", self),
    html_class
end

#callObject



64
65
66
67
68
69
# File 'app/components/fox_tail/dropdown_component.rb', line 64

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

#stimulus_controller_optionsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/components/fox_tail/dropdown_component.rb', line 71

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

#trigger_idObject



51
52
53
# File 'app/components/fox_tail/dropdown_component.rb', line 51

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