Class: NitroKit::RadioButton
- Includes:
- ActionView::Helpers::FormTagHelper
- Defined in:
- app/components/nitro_kit/radio_button.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label_text ⇒ Object
readonly
Returns the value of attribute label_text.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Component
Instance Method Summary collapse
-
#initialize(name, value:, label: nil, **attrs) ⇒ RadioButton
constructor
A new instance of RadioButton.
- #view_template ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(name, value:, label: nil, **attrs) ⇒ RadioButton
Returns a new instance of RadioButton.
5 6 7 8 9 10 11 12 |
# File 'app/components/nitro_kit/radio_button.rb', line 5 def initialize(name, value:, label: nil, **attrs) super(**attrs) @name = name @value = value @label_text = label @id = "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}" end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'app/components/nitro_kit/radio_button.rb', line 14 def id @id end |
#label_text ⇒ Object (readonly)
Returns the value of attribute label_text.
14 15 16 |
# File 'app/components/nitro_kit/radio_button.rb', line 14 def label_text @label_text end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'app/components/nitro_kit/radio_button.rb', line 14 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
14 15 16 |
# File 'app/components/nitro_kit/radio_button.rb', line 14 def value @value end |
Instance Method Details
#view_template ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/nitro_kit/radio_button.rb', line 21 def view_template div(class: merge("inline-flex items-center gap-2", attrs[:class])) do label(class: "grid grid-cols-1 place-items-center shrink-0") do input( **attrs, type: "radio", name:, value:, id:, class: class_names( "peer row-start-1 col-start-1", "appearance-none size-5 shadow-sm rounded-full border text-foreground bg-background", "[&[aria-checked='true']]:bg-primary", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" ) ) dot end if label_text.present? render(Label.new(for: id)) { label_text } end end end |