Class: Arara::RadioButtonComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

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

Constructor Details

#initialize(id:, name:, value:, checked: false, type: "radio", **kw) ⇒ RadioButtonComponent

Returns a new instance of RadioButtonComponent.



7
8
9
10
11
12
13
14
15
# File 'app/components/arara/radio_button_component.rb', line 7

def initialize(id:, name:, value:, checked: false, type: "radio", **kw)
  @id = id
  @name = name
  @checked = checked
  @value = value
  @type = type

  super(tag: "div", **kw)
end

Instance Attribute Details

#checkedObject (readonly)

Returns the value of attribute checked.



5
6
7
# File 'app/components/arara/radio_button_component.rb', line 5

def checked
  @checked
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'app/components/arara/radio_button_component.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'app/components/arara/radio_button_component.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'app/components/arara/radio_button_component.rb', line 5

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'app/components/arara/radio_button_component.rb', line 5

def value
  @value
end

Instance Method Details

#default_html_classObject



31
32
33
# File 'app/components/arara/radio_button_component.rb', line 31

def default_html_class
  "mdc-radio"
end

#html_input_optionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/arara/radio_button_component.rb', line 17

def html_input_options
  opts = {
    class: "mdc-radio__native-control",
    type: type,
    id: id,
    name: name,
    value: value
  }

  opts[:checked] = "" if checked

  opts
end