Class: NitroKit::RadioButton
- Defined in:
- app/components/nitro_kit/radio_button.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
(also: #html_label)
readonly
Returns the value of attribute label.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#wrapper ⇒ Object
readonly
Returns the value of attribute wrapper.
Attributes inherited from Component
Instance Method Summary collapse
-
#initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs) ⇒ RadioButton
constructor
A new instance of RadioButton.
- #view_template ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs) ⇒ RadioButton
Returns a new instance of RadioButton.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/components/nitro_kit/radio_button.rb', line 5 def initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs) @label = label @id = id || "nk--" + SecureRandom.hex(4) @size = size @wrapper = wrapper super( attrs, id: @id, type: "radio", class: input_class ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'app/components/nitro_kit/radio_button.rb', line 21 def id @id end |
#label ⇒ Object (readonly) Also known as: html_label
Returns the value of attribute label.
21 22 23 |
# File 'app/components/nitro_kit/radio_button.rb', line 21 def label @label end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
21 22 23 |
# File 'app/components/nitro_kit/radio_button.rb', line 21 def size @size end |
#wrapper ⇒ Object (readonly)
Returns the value of attribute wrapper.
21 22 23 |
# File 'app/components/nitro_kit/radio_button.rb', line 21 def wrapper @wrapper end |
Instance Method Details
#view_template ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/nitro_kit/radio_button.rb', line 23 def view_template div(**mattr(wrapper, class: wrapper_class)) do html_label(class: merge_class("inline-grid *:[grid-area:1/1] shrink-0 place-items-center", size_class)) do input(**attrs) dot end if label.present? || block_given? render(Label.new(for: id)) do label || (block_given? ? yield : nil) end end end end |