Class: Arara::SwitchComponent
- Inherits:
-
ActionView::Component::Base
- Object
- ActionView::Component::Base
- Arara::SwitchComponent
- Includes:
- BaseComponent
- Defined in:
- app/components/arara/switch_component.rb
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #default_data_controller ⇒ Object
- #default_html_class ⇒ Object
-
#initialize(id:, checked: false, **kw) ⇒ SwitchComponent
constructor
A new instance of SwitchComponent.
- #input_options ⇒ Object
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
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
4 5 6 |
# File 'app/components/arara/switch_component.rb', line 4 def checked @checked end |
#id ⇒ Object (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_controller ⇒ Object
17 18 19 |
# File 'app/components/arara/switch_component.rb', line 17 def default_data_controller "mdc-switch" end |
#default_html_class ⇒ Object
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_options ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/components/arara/switch_component.rb', line 21 def opts = { type: "checkbox", id: id, class: "mdc-switch__native-control", role: "switch", aria: { checked: checked } } opts[:checked] = "" if checked opts end |