Class: NitroKit::Checkbox
- Includes:
- ActionView::Helpers::FormTagHelper
- Defined in:
- app/components/nitro_kit/checkbox.rb
Instance Attribute Summary collapse
-
#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: "1", label: nil, **attrs) ⇒ Checkbox
constructor
A new instance of Checkbox.
- #view_template ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(name, value: "1", label: nil, **attrs) ⇒ Checkbox
Returns a new instance of Checkbox.
5 6 7 8 9 10 |
# File 'app/components/nitro_kit/checkbox.rb', line 5 def initialize(name, value: "1", label: nil, **attrs) super(**attrs) @name = name @label_text = label end |
Instance Attribute Details
#label_text ⇒ Object (readonly)
Returns the value of attribute label_text.
12 13 14 |
# File 'app/components/nitro_kit/checkbox.rb', line 12 def label_text @label_text end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'app/components/nitro_kit/checkbox.rb', line 12 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
12 13 14 |
# File 'app/components/nitro_kit/checkbox.rb', line 12 def value @value end |
Instance Method Details
#view_template ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/components/nitro_kit/checkbox.rb', line 18 def view_template div(class: merge(["isolate inline-flex items-center gap-2", attrs[:class]])) do label(class: "relative flex shrink-0") do input( **attrs, type: "checkbox", class: class_names( "peer appearance-none shadow-sm size-4 rounded-sm border text-foreground", "checked:bg-primary checked:border-primary", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" ) ) checkmark end if label_text.present? render(Label.new(for: attrs[:id])) { label_text } end end end |