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