Class: Form::SwitchComponent

Inherits:
CheckboxComponent
  • Object
show all
Defined in:
app/components/spark/form/switch_component.rb

Constant Summary collapse

SIZE =
i[small medium].freeze
ALIGNMENT =
i[left right].freeze

Instance Method Summary collapse

Instance Method Details

#before_renderObject



11
12
13
14
# File 'app/components/spark/form/switch_component.rb', line 11

def before_render
  add_class(size)
  add_class(join_class("align-#{align}")) if align
end

#input_attrsObject



27
28
29
30
31
# File 'app/components/spark/form/switch_component.rb', line 27

def input_attrs
  super.merge({
    class: join_class("input")
  })
end

#renderObject



16
17
18
19
20
21
22
23
24
25
# File 'app/components/spark/form/switch_component.rb', line 16

def render
  (:div, class: classnames) do
    component("form/label", text: label, class: join_class("label")) do
      concat(tag(:input, input_attrs))
      concat (:span, class: join_class("panel")) {
        (:span, nil, class: join_class("tick"))
      }
    end
  end
end