Class: ViewComponent::InputComponent::InputRadioComponent

Inherits:
Object
  • Object
show all
Includes:
ComponentHelper
Defined in:
app/helpers/view_component/input_component/input_radio_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentHelper

#class_list, #resolve_error

Constructor Details

#initialize(form:, name:, label:, value:, disabled:, error:, label_position:, html_options:) ⇒ InputRadioComponent

Returns a new instance of InputRadioComponent.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 10

def initialize(form:, name:, label:, value:, disabled:, error:, label_position:, html_options:)
  self.form = form
  self.name = name
  self.label = label
  self.label_position = label_position
  self.value = value
  self.html_options = html_options
  self.disabled = disabled
  self.html_options[:disabled] = disabled
  self.html_options[:class] = 'hidden'
  self.error = resolve_error(form, name, error)
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def disabled
  @disabled
end

#errorObject

Returns the value of attribute error.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def error
  @error
end

#formObject

Returns the value of attribute form.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def form
  @form
end

#html_optionsObject

Returns the value of attribute html_options.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def html_options
  @html_options
end

#labelObject

Returns the value of attribute label.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def label
  @label
end

#label_positionObject

Returns the value of attribute label_position.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def label_position
  @label_position
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def name
  @name
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 8

def value
  @value
end

Instance Method Details

#label_styleObject



23
24
25
26
27
28
29
30
31
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 23

def label_style
  if disabled
    'text-disabled-color'
  elsif error
    'text-danger-dark'
  else
    'text-letter-color group-has-[input:checked]:text-primary group-hover:text-primary-light'
  end
end

#radio_circle_styleObject



33
34
35
36
37
38
39
40
41
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 33

def radio_circle_style
  if disabled
    'border-disabled-color'
  elsif error
    'border-danger-dark'
  else
    'border-slate-grey-50 group-hover:border-primary-light group-has-[input:checked]:border-primary'
  end
end

#radio_dot_styleObject



43
44
45
46
47
48
49
50
51
# File 'app/helpers/view_component/input_component/input_radio_component.rb', line 43

def radio_dot_style
  if disabled
    'bg-white'
  elsif error
    'group-has-[input:checked]:bg-danger-dark'
  else
    'group-has-[input:checked]:bg-primary'
  end
end