Class: NitroKit::RadioButtonGroup
- Defined in:
- app/components/nitro_kit/radio_button_group.rb
Constant Summary collapse
- ORIENTATIONS =
%i[vertical horizontal].freeze
- PRESENTATIONS =
%i[list cards segmented].freeze
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#legend ⇒ Object
(also: #html_legend)
readonly
Returns the value of attribute legend.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#presentation ⇒ Object
readonly
Returns the value of attribute presentation.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(legend:, options:, name:, value: nil, id: nil, description: nil, orientation: :vertical, presentation: :list, disabled: false, required: false, size: :md, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ RadioButtonGroup
constructor
A new instance of RadioButtonGroup.
- #view_template ⇒ Object
Constructor Details
#initialize(legend:, options:, name:, value: nil, id: nil, description: nil, orientation: :vertical, presentation: :list, disabled: false, required: false, size: :md, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ RadioButtonGroup
Returns a new instance of RadioButtonGroup.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 10 def initialize( legend:, options:, name:, value: nil, id: nil, description: nil, orientation: :vertical, presentation: :list, disabled: false, required: false, size: :md, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @legend = validate_text!(:legend, legend) @options = Array().map { |choice| Choice.coerce(choice) }.freeze @name = validate_text!(:name, name) @value = value @id = id || deterministic_id(name) @description = validate_optional_text!(:description, description) @orientation = validate_choice!(:orientation, orientation, ORIENTATIONS) @presentation = validate_choice!(:presentation, presentation, PRESENTATIONS) @disabled = validate_boolean!(:disabled, disabled) @required = validate_boolean!(:required, required) @size = validate_choice!(:size, size, RadioButton::SIZES) raise ArgumentError, "options cannot be empty" if @options.empty? validate_unique_choices! super( component: :radio_button_group, size: @size, attributes: { id: @id, disabled: @disabled, aria: { required: @required ? "true" : nil }.compact, data: { orientation: @orientation, presentation: @presentation } }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def id @id end |
#legend ⇒ Object (readonly) Also known as: html_legend
Returns the value of attribute legend.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def legend @legend end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def @options end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def orientation @orientation end |
#presentation ⇒ Object (readonly)
Returns the value of attribute presentation.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def presentation @presentation end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def size @size end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
58 59 60 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 58 def value @value end |
Instance Method Details
#view_template ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 60 def view_template fieldset(**root_attributes) do html_legend(**slot_attributes(:legend)) { plain(legend) } if description p(**slot_attributes(:description, attributes: { id: description_id }.compact)) do plain(description.to_s) end end div(**slot_attributes(:choices)) do .each_with_index { |choice, index| render_choice(choice, index) } end end end |