Class: FoxTail::FABComponent

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

Defined Under Namespace

Classes: StimulusController

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_attributes

Class Method Summary collapse

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(html_attributes = {}) ⇒ FABComponent

Returns a new instance of FABComponent.



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

def initialize(html_attributes = {})
  super

  html_attributes[:id] ||= :"fab_#{SecureRandom.hex(4)}"
  options[:item_placement] = calculate_item_placement if item_placement == :auto
  options[:label_placement] = calculate_label_placement if label_placement == :auto
end

Class Method Details

.stimulus_controller_nameObject



118
119
120
# File 'app/components/fox_tail/f_a_b_component.rb', line 118

def stimulus_controller_name
  :fab
end

Instance Method Details

#before_renderObject



45
46
47
48
49
50
51
52
53
54
# File 'app/components/fox_tail/f_a_b_component.rb', line 45

def before_render
  super

  with_icon "plus" unless icon?

  html_attributes[:class] = classnames theme.apply(:root, self),
    placement.is_a?(String) && placement,
    theme.apply("root/hidden", self),
    html_class
end

#callObject



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

def call
   :div, html_attributes do
    concat render_items if items? && render_items_first?
    concat icon
    concat render_items if items? && !render_items_first?
  end
end

#horizontal?Boolean

Returns:

  • (Boolean)


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

def horizontal?
  !vertical?
end

#stimulus_controller_optionsObject



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

def stimulus_controller_options
  {
    trigger_type: trigger_type,
    visible_classes: theme.apply("root/visible", self),
    hidden_classes: theme.apply("root/hidden", self)
  }
end

#vertical?Boolean

Returns:

  • (Boolean)


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

def vertical?
  %i[top bottom].include? item_placement
end