Class: Arara::SwitchComponent

Inherits:
ActionView::Component::Base
  • Object
show all
Includes:
BaseComponent
Defined in:
app/components/arara/switch_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

#default_html_tag, #html_class, #html_content, #html_data, #html_options, #html_tag, included

Constructor Details

#initialize(id:, checked: false, **kw) ⇒ SwitchComponent

Returns a new instance of SwitchComponent.



6
7
8
9
10
# File 'app/components/arara/switch_component.rb', line 6

def initialize(id:, checked: false, **kw)
  super(tag: "div", **kw)
  @id = id
  @checked = checked
end

Instance Attribute Details

#checkedObject (readonly)

Returns the value of attribute checked.



4
5
6
# File 'app/components/arara/switch_component.rb', line 4

def checked
  @checked
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'app/components/arara/switch_component.rb', line 4

def id
  @id
end

Instance Method Details

#default_data_controllerObject



17
18
19
# File 'app/components/arara/switch_component.rb', line 17

def default_data_controller
  "mdc-switch"
end

#default_html_classObject



12
13
14
15
# File 'app/components/arara/switch_component.rb', line 12

def default_html_class
  return "mdc-switch mdc-switch--checked" if checked
  "mdc-switch"
end

#input_optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/arara/switch_component.rb', line 21

def input_options
  opts = {
    type: "checkbox",
    id: id,
    class: "mdc-switch__native-control",
    role: "switch",
    aria: {
      checked: checked
    }
  }
  opts[:checked] = "" if checked
  opts
end