Class: BetterUi::Forms::CheckboxGroupComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Forms::CheckboxGroupComponent
- Defined in:
- app/components/better_ui/forms/checkbox_group_component.rb
Overview
A checkbox group component for selecting multiple options from a collection.
This component renders a group of checkboxes within a fieldset, allowing users to select multiple values. It supports both vertical and horizontal orientations, and integrates seamlessly with Rails form builders for array attribute submission.
Constant Summary collapse
- SIZES =
Available size variants for checkbox groups. Each size adjusts checkbox dimensions and spacing proportionally.
%i[xs sm md lg xl].freeze
- ORIENTATIONS =
Available orientation options for checkbox group layout.
%i[vertical horizontal].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:, collection: [], selected: [], legend: nil, hint: nil, variant: :primary, size: :md, orientation: :vertical, disabled: false, required: false, errors: nil, container_classes: nil, legend_classes: nil, items_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ CheckboxGroupComponent
constructor
Initializes a new checkbox group component.
Constructor Details
#initialize(name:, collection: [], selected: [], legend: nil, hint: nil, variant: :primary, size: :md, orientation: :vertical, disabled: false, required: false, errors: nil, container_classes: nil, legend_classes: nil, items_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ CheckboxGroupComponent
Initializes a new checkbox group component.
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 117 118 |
# File 'app/components/better_ui/forms/checkbox_group_component.rb', line 82 def initialize( name:, collection: [], selected: [], legend: nil, hint: nil, variant: :primary, size: :md, orientation: :vertical, disabled: false, required: false, errors: nil, container_classes: nil, legend_classes: nil, items_classes: nil, hint_classes: nil, error_classes: nil, ** ) @name = name @collection = collection @selected = Array(selected).map(&:to_s) @legend = legend @hint = hint @variant = validate_variant(variant) @size = validate_size(size) @orientation = validate_orientation(orientation) @disabled = disabled @required = required @errors = Array(errors).compact.reject(&:blank?) @container_classes = container_classes @legend_classes = legend_classes @items_classes = items_classes @hint_classes = hint_classes @error_classes = error_classes @options = end |