Class: Fluxbit::Form::LabelComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/fluxbit/form/label_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(color: :default, form: nil, with_content: nil, helper_text: nil, sizing: :sm, helper_popover: nil, helper_popover_placement: "right", **props) ⇒ LabelComponent

Returns a new instance of LabelComponent.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/fluxbit/form/label_component.rb', line 23

def initialize(color: :default, form: nil, with_content: nil, helper_text: nil,
               sizing: :sm, helper_popover: nil, helper_popover_placement: "right", **props)
  super
  @props = props
  @sizing = sizing.in?(styles[:sizes].keys) ? sizing : :sm
  @with_content = with_content
  @helper_text = helper_text.is_a?(Array) ? helper_text : [ helper_text ]
  @helper_popover = helper_popover
  @helper_popover_placement = helper_popover_placement
  color = :default unless color.in? %i[info default success failure warning]
  add class: styles[:colors][color], to: @props, first_element: true
  add class: styles[:base], to: @props, first_element: true
  add class: styles[:sizes][@sizing], to: @props, first_element: true
end

Instance Method Details

#callObject



56
57
58
59
60
61
62
63
64
# File 'app/components/fluxbit/form/label_component.rb', line 56

def call
  safe_join(
    [
      (:label, safe_join([ content || @with_content, span_helper_popover ]), @props),
      helper_text,
      render_popover
    ]
  )
end

#render_popoverObject



50
51
52
53
54
# File 'app/components/fluxbit/form/label_component.rb', line 50

def render_popover
  return "" if @helper_popover.nil?

  Fluxbit::PopoverComponent.new(id: target).with_content(@helper_popover).render_in(view_context)
end

#span_helper_popoverObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/components/fluxbit/form/label_component.rb', line 38

def span_helper_popover
  return "" if @helper_popover.nil?

   :span,
              anyicon(icon: "heroicons_solid:question-mark-circle", class: "w-4 h-4"),
              {
                "data-popover-placement": @helper_popover_placement,
                "data-popover-target": target,
                class: styles[:helper_popover]
              }
end