Class: SdrViewComponents::Forms::ToggleOptionComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Forms::ToggleOptionComponent
- Defined in:
- app/components/sdr_view_components/forms/toggle_option_component.rb
Overview
Component for a toggle option
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(form:, field_name:, label:, value:, data: {}, position: :left) ⇒ ToggleOptionComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #label_classes ⇒ Object
Methods inherited from BaseComponent
#args_for, #merge_actions, #merge_classes
Constructor Details
#initialize(form:, field_name:, label:, value:, data: {}, position: :left) ⇒ ToggleOptionComponent
rubocop:disable Metrics/ParameterLists
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 7 def initialize(form:, field_name:, label:, value:, data: {}, position: :left) # rubocop:disable Metrics/ParameterLists raise ArgumentError, 'position must be :left or :right' unless %i[left right].include?(position) @form = form @field_name = field_name @label = label @value = value @data = data @position = position super() end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 19 def data @data end |
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
19 20 21 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 19 def field_name @field_name end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
19 20 21 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 19 def form @form end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
19 20 21 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 19 def label @label end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
19 20 21 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 19 def value @value end |
Instance Method Details
#label_classes ⇒ Object
21 22 23 |
# File 'app/components/sdr_view_components/forms/toggle_option_component.rb', line 21 def label_classes merge_classes('btn', @position == :left ? 'rounded-start-pill' : 'rounded-end-pill') end |