Class: NitroKit::RadioButtonGroup
- Defined in:
- app/components/nitro_kit/radio_button_group.rb
Instance Attribute Summary collapse
-
#group_value ⇒ Object
readonly
Returns the value of attribute group_value.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from Component
Instance Method Summary collapse
-
#initialize(options_arg = nil, options: [], name: nil, value: nil, **attrs) ⇒ RadioButtonGroup
constructor
A new instance of RadioButtonGroup.
- #item(text = nil, value_as_arg = nil, value: nil, **attrs, &block) ⇒ Object
- #title(text = nil, **attrs, &block) ⇒ Object
- #view_template ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(options_arg = nil, options: [], name: nil, value: nil, **attrs) ⇒ RadioButtonGroup
Returns a new instance of RadioButtonGroup.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 5 def initialize( = nil, options: [], name: nil, value: nil, **attrs) @options = || @name = name @group_value = value super( attrs, name: @name, class: "flex items-start flex-col gap-2" ) end |
Instance Attribute Details
#group_value ⇒ Object (readonly)
Returns the value of attribute group_value.
18 19 20 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 18 def group_value @group_value end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 18 def @options end |
Instance Method Details
#item(text = nil, value_as_arg = nil, value: nil, **attrs, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 38 def item(text = nil, value_as_arg = nil, value: nil, **attrs, &block) builder do value ||= value_as_arg render( RadioButton.new( **mattr( attrs, name: attrs.fetch(:name, name), value:, checked: group_value.presence == value ) ) ) do text_or_block(text, &block) end end end |
#title(text = nil, **attrs, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 30 def title(text = nil, **attrs, &block) builder do render(Label.new(**attrs)) do text_or_block(text, &block) end end end |
#view_template ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/components/nitro_kit/radio_button_group.rb', line 20 def view_template div(**attrs) do if block_given? yield else .map { |o| item(*o) } end end end |