Module: UI::CheckboxBehavior
- Included in:
- Checkbox, CheckboxComponent
- Defined in:
- app/behaviors/ui/checkbox_behavior.rb
Overview
UI::CheckboxBehavior
Instance Method Summary collapse
- #checkbox_classes ⇒ Object
- #checkbox_data_attributes ⇒ Object
- #checkbox_html_attributes ⇒ Object
- #checkbox_id ⇒ Object
Instance Method Details
#checkbox_classes ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/behaviors/ui/checkbox_behavior.rb', line 39 def checkbox_classes classes_value = respond_to?(:classes, true) ? classes : @classes TailwindMerge::Merger.new.merge([ checkbox_base_classes, classes_value ].compact.join(" ")) end |
#checkbox_data_attributes ⇒ Object
48 49 50 51 52 53 |
# File 'app/behaviors/ui/checkbox_behavior.rb', line 48 def checkbox_data_attributes { controller: "ui--checkbox", state: @checked ? "checked" : "unchecked" } end |
#checkbox_html_attributes ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/behaviors/ui/checkbox_behavior.rb', line 23 def checkbox_html_attributes attributes_value = respond_to?(:attributes, true) ? attributes : @attributes { type: "checkbox", class: checkbox_classes, name: @name, id: checkbox_id, value: @value, checked: (@checked ? true : nil), disabled: (@disabled ? true : nil), required: (@required ? true : nil), data: checkbox_data_attributes, "aria-checked": @checked ? "true" : "false" }.merge(attributes_value).compact end |
#checkbox_id ⇒ Object
55 56 57 |
# File 'app/behaviors/ui/checkbox_behavior.rb', line 55 def checkbox_id @id || "checkbox-#{SecureRandom.hex(4)}" end |