Class: BetterUi::Forms::CheckboxComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Forms::CheckboxComponent
- Defined in:
- app/components/better_ui/forms/checkbox_component.rb
Overview
A checkbox input component with support for labels, hints, errors, and color variants.
This component provides a styled checkbox with customizable colors, sizes, and label positioning. Unlike text inputs, the label appears inline (left or right) with the checkbox rather than above.
Constant Summary collapse
- SIZES =
Available size variants for checkbox inputs. Each size adjusts the checkbox dimensions and spacing proportionally.
%i[xs sm md lg xl].freeze
- LABEL_POSITIONS =
Available label positions relative to the checkbox.
%i[left right].freeze
Constants inherited from ApplicationComponent
ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED
Instance Method Summary collapse
-
#initialize(name:, value: "1", checked: false, label: nil, hint: nil, variant: :primary, size: :md, label_position: :right, disabled: false, readonly: false, required: false, errors: nil, container_classes: nil, label_classes: nil, checkbox_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ CheckboxComponent
constructor
Initializes a new checkbox component.
Constructor Details
#initialize(name:, value: "1", checked: false, label: nil, hint: nil, variant: :primary, size: :md, label_position: :right, disabled: false, readonly: false, required: false, errors: nil, container_classes: nil, label_classes: nil, checkbox_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ CheckboxComponent
Initializes a new checkbox component.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/components/better_ui/forms/checkbox_component.rb', line 78 def initialize( name:, value: "1", checked: false, label: nil, hint: nil, variant: :primary, size: :md, label_position: :right, disabled: false, readonly: false, required: false, errors: nil, container_classes: nil, label_classes: nil, checkbox_classes: nil, hint_classes: nil, error_classes: nil, ** ) @name = name @value = value @checked = checked @label = label @hint = hint @variant = validate_variant(variant) @size = validate_size(size) @label_position = validate_label_position(label_position) @disabled = disabled @readonly = readonly @required = required @errors = Array(errors).compact.reject(&:blank?) @container_classes = container_classes @label_classes = label_classes @checkbox_classes = checkbox_classes @hint_classes = hint_classes @error_classes = error_classes @options = end |