Class: BetterUi::Forms::BaseComponent Abstract
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Forms::BaseComponent
- Defined in:
- app/components/better_ui/forms/base_component.rb
Overview
Subclasses must implement the #call method to render the specific input type.
Base component for all form input components in the BetterUi::Forms namespace.
This abstract class provides a common structure and behavior for form input components, including label positioning (vertical/above input), hint text display, error message handling, and consistent sizing/styling across all input types.
Direct Known Subclasses
NumberInputComponent, SelectComponent, TextInputComponent, TextareaComponent
Constant Summary collapse
- SIZES =
Available size variants for form inputs. Each size adjusts font size, padding, and spacing proportionally.
%i[xs sm md lg xl].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
-
#call ⇒ String
abstract
Renders the component markup.
-
#initialize(name:, value: nil, label: nil, hint: nil, placeholder: nil, size: :md, disabled: false, readonly: false, required: false, errors: nil, shadow: :sm, container_classes: nil, label_classes: nil, input_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ BaseComponent
constructor
Initializes a new form input component with common form field attributes.
Constructor Details
#initialize(name:, value: nil, label: nil, hint: nil, placeholder: nil, size: :md, disabled: false, readonly: false, required: false, errors: nil, shadow: :sm, container_classes: nil, label_classes: nil, input_classes: nil, hint_classes: nil, error_classes: nil, **options) ⇒ BaseComponent
Initializes a new form input component with common form field attributes.
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 119 120 |
# File 'app/components/better_ui/forms/base_component.rb', line 84 def initialize( name:, value: nil, label: nil, hint: nil, placeholder: nil, size: :md, disabled: false, readonly: false, required: false, errors: nil, shadow: :sm, container_classes: nil, label_classes: nil, input_classes: nil, hint_classes: nil, error_classes: nil, ** ) @name = name @value = value @label = label @hint = hint @placeholder = placeholder @size = validate_size(size) @disabled = disabled @readonly = readonly @required = required @errors = Array(errors).compact.reject(&:blank?) @shadow = normalize_shadow(shadow) @container_classes = container_classes @label_classes = label_classes @input_classes = input_classes @hint_classes = hint_classes @error_classes = error_classes @options = end |
Instance Method Details
#call ⇒ String
Subclasses must implement this method
Renders the component markup.
This method must be implemented by subclasses to define the specific rendering logic for each input type (text, number, select, etc.).
130 131 132 |
# File 'app/components/better_ui/forms/base_component.rb', line 130 def call raise NotImplementedError, "Subclasses must implement the #call method" end |