Class: Shadcn::FieldComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Shadcn::FieldComponent
- Defined in:
- app/components/shadcn/field_component.rb
Overview
Field component for form field wrapper with label, input, description, and error Provides a consistent pattern for form fields
Defined Under Namespace
Classes: DescriptionComponent, ErrorComponent
Constant Summary collapse
- BASE_CLASSES =
"space-y-2"
Instance Attribute Summary
Attributes inherited from BaseComponent
#class_name, #data, #html_options
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name: nil, id: nil, **options) ⇒ FieldComponent
constructor
A new instance of FieldComponent.
Methods inherited from BaseComponent
Methods included from Rails::Helpers::ClassNameHelper
Constructor Details
#initialize(name: nil, id: nil, **options) ⇒ FieldComponent
Returns a new instance of FieldComponent.
71 72 73 74 75 |
# File 'app/components/shadcn/field_component.rb', line 71 def initialize(name: nil, id: nil, **) super(**) @name = name @input_id = id || generate_id end |
Instance Method Details
#call ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/components/shadcn/field_component.rb', line 77 def call tag.div(class: merge_classes(BASE_CLASSES), **.merge(build_data)) do safe_join([ label, control || input, description, error ].compact) end end |