Class: Fluxbit::Form::CheckboxInputComponent

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

Instance Method Summary collapse

Constructor Details

#initialize(form: nil, field: nil, label: nil, helper_text: nil, helper_popover: nil, helper_popover_placement: "right", **props) ⇒ CheckboxInputComponent

rubocop: enable Layout/LineLength



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

def initialize(form: nil, field: nil, label: nil, helper_text: nil, helper_popover: nil,
               helper_popover_placement: "right", **props)
  super
  @form = form
  @field = field
  @object = form&.object
  @props = props
  @label = label_value(label, @object, field, id)
  @helper_text = define_helper_text(helper_text, @object, field)
  @helper_popover = define_helper_popover(helper_popover, @object, field)
  @helper_popover_placement = helper_popover_placement

  @props[:type] = @props[:type].to_s.in?(%w[checkbox radio]) ? @props[:type].to_s : "checkbox"
  add(class: styles[:checkbox], to: @props, first_element: true) if @props[:type] == "checkbox"
  add(class: styles[:base], to: @props, first_element: true)
end

Instance Method Details

#callObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/components/fluxbit/form/checkbox_input_component.rb', line 45

def call
  if @helper_text
     :div, { class: "flex" } do
      concat (:div, input, { class: styles[:input_div] })
      concat (:div, { class: styles[:helper_div] }) do
        concat label
        concat helper_text
      end
    end
  else
     :div, { class: styles[:no_helper_div] } do
      concat input
      concat label
    end
  end
end

#inputObject



37
38
39
40
41
42
43
# File 'app/components/fluxbit/form/checkbox_input_component.rb', line 37

def input
  if @form.nil?
     :input, content, @props
  else
    @form.text_field(@field, **@props)
  end
end