Class: NitroKit::RadioGroup

Inherits:
Component
  • Object
show all
Includes:
ActionView::Helpers::FormTagHelper
Defined in:
app/components/nitro_kit/radio_group.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#data_merge, merge, #merge

Constructor Details

#initialize(name, value: nil, **options) ⇒ RadioGroup

Returns a new instance of RadioGroup.



5
6
7
8
9
# File 'app/components/nitro_kit/radio_group.rb', line 5

def initialize(name, value: nil, **options)
  super(**options)
  @name = name
  @group_value = value
end

Instance Attribute Details

#group_valueObject (readonly)

Returns the value of attribute group_value.



11
12
13
# File 'app/components/nitro_kit/radio_group.rb', line 11

def group_value
  @group_value
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'app/components/nitro_kit/radio_group.rb', line 11

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'app/components/nitro_kit/radio_group.rb', line 11

def name
  @name
end

Instance Method Details

#item(value, text = nil, **options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/nitro_kit/radio_group.rb', line 23

def item(value, text = nil, **options)
  render(
    RadioButton.new(
      name,
      id:,
      value:,
      checked: group_value.presence == value,
      **options
    )
  ) { text || yield }
end

#title(text = nil, **options) ⇒ Object



19
20
21
# File 'app/components/nitro_kit/radio_group.rb', line 19

def title(text = nil, **options)
  render(Label.new(**options)) { text || yield }
end

#view_templateObject



13
14
15
16
17
# File 'app/components/nitro_kit/radio_group.rb', line 13

def view_template
  div(class: "flex items-start flex-col gap-2") do
    yield
  end
end