Class: NitroKit::CheckboxGroup
- Defined in:
- app/components/nitro_kit/checkbox_group.rb
Constant Summary collapse
- ORIENTATIONS =
%i[vertical horizontal].freeze
- PRESENTATIONS =
%i[list cards].freeze
Constants inherited from Component
NitroKit::Component::ADDITIVE_DATA_ATTRIBUTES, NitroKit::Component::COMPONENT_OWNED_DATA_ATTRIBUTES, NitroKit::Component::FORBIDDEN_ATTRIBUTES, NitroKit::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: [], id: nil, description: nil, orientation: :vertical, presentation: :list, unchecked_value: "", include_hidden: true, disabled: false, required: false, size: :md, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ CheckboxGroup
constructor
A new instance of CheckboxGroup.
- #view_template ⇒ Object
Constructor Details
#initialize(legend:, options:, name:, value: [], id: nil, description: nil, orientation: :vertical, presentation: :list, unchecked_value: "", include_hidden: true, disabled: false, required: false, size: :md, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ CheckboxGroup
Returns a new instance of CheckboxGroup.
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 57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 10 def initialize( legend:, options:, name:, value: [], id: nil, description: nil, orientation: :vertical, presentation: :list, unchecked_value: "", include_hidden: true, 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 = multiple_name(validate_text!(:name, name)) @value = Array(value).map(&:to_s).freeze @id = id || deterministic_id(name) @description = validate_optional_text!(:description, description) @orientation = validate_choice!(:orientation, orientation, ORIENTATIONS) @presentation = validate_choice!(:presentation, presentation, PRESENTATIONS) @unchecked_value = unchecked_value @include_hidden = validate_boolean!(:include_hidden, include_hidden) @disabled = validate_boolean!(:disabled, disabled) @required = validate_boolean!(:required, required) @size = validate_choice!(:size, size, Checkbox::SIZES) raise ArgumentError, "options cannot be empty" if @options.empty? validate_unique_choices! if include_hidden && unchecked_value.nil? raise ArgumentError, "unchecked_value cannot be nil when include_hidden is true" end super( component: :checkbox_group, size: @size, attributes: { id: @id, disabled: @disabled, data: { orientation: @orientation, presentation: @presentation, required: @required ? "true" : nil }.compact }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def id @id end |
#legend ⇒ Object (readonly) Also known as: html_legend
Returns the value of attribute legend.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def legend @legend end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def @options end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def orientation @orientation end |
#presentation ⇒ Object (readonly)
Returns the value of attribute presentation.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def presentation @presentation end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def size @size end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
68 69 70 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 68 def value @value end |
Instance Method Details
#view_template ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/components/nitro_kit/checkbox_group.rb', line 70 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 render_hidden_control div(**slot_attributes(:choices)) do .each_with_index { |choice, index| render_choice(choice, index) } end end end |