Class: IronAdmin::Form::FieldWrapperComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Form::FieldWrapperComponent
- Defined in:
- app/components/iron_admin/form/field_wrapper_component.rb
Overview
Wraps form fields with label, error messages, and hints.
Instance Attribute Summary collapse
-
#errors ⇒ Array<String>
readonly
Error messages.
-
#hint ⇒ String?
readonly
Hint text.
-
#label ⇒ String?
readonly
Label text.
-
#name ⇒ Symbol, String
readonly
Field name.
-
#required ⇒ Boolean
readonly
Whether field is required.
-
#span_full ⇒ Boolean
readonly
Whether to span full width.
Instance Method Summary collapse
-
#error_classes ⇒ String
private
CSS classes for error container.
-
#has_errors? ⇒ Boolean
private
Whether there are validation errors.
-
#initialize(name:, label: nil, errors: [], required: false, hint: nil, span_full: false) ⇒ FieldWrapperComponent
constructor
A new instance of FieldWrapperComponent.
-
#label_classes ⇒ String
private
CSS classes for label element.
-
#theme ⇒ IronAdmin::Configuration::Theme
private
Theme configuration.
-
#wrapper_classes ⇒ String
private
CSS classes for wrapper element.
Constructor Details
#initialize(name:, label: nil, errors: [], required: false, hint: nil, span_full: false) ⇒ FieldWrapperComponent
Returns a new instance of FieldWrapperComponent.
36 37 38 39 40 41 42 43 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 36 def initialize(name:, label: nil, errors: [], required: false, hint: nil, span_full: false) @name = name @label = label || name.to_s.humanize @errors = Array(errors) @required = required @hint = hint @span_full = span_full end |
Instance Attribute Details
#errors ⇒ Array<String> (readonly)
Returns Error messages.
19 20 21 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 19 def errors @errors end |
#hint ⇒ String? (readonly)
Returns Hint text.
25 26 27 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 25 def hint @hint end |
#label ⇒ String? (readonly)
Returns Label text.
16 17 18 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 16 def label @label end |
#name ⇒ Symbol, String (readonly)
Returns Field name.
13 14 15 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 13 def name @name end |
#required ⇒ Boolean (readonly)
Returns Whether field is required.
22 23 24 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 22 def required @required end |
#span_full ⇒ Boolean (readonly)
Returns Whether to span full width.
28 29 30 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 28 def span_full @span_full end |
Instance Method Details
#error_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS classes for error container.
71 72 73 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 71 def error_classes "flex items-center gap-1.5 mt-1.5" end |
#has_errors? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Whether there are validation errors.
53 54 55 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 53 def has_errors? errors.any? end |
#label_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS classes for label element.
65 66 67 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 65 def label_classes "block text-sm font-medium #{theme.label_text} mb-1.5" end |
#theme ⇒ IronAdmin::Configuration::Theme
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Theme configuration.
47 48 49 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 47 def theme IronAdmin.configuration.theme end |
#wrapper_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS classes for wrapper element.
59 60 61 |
# File 'app/components/iron_admin/form/field_wrapper_component.rb', line 59 def wrapper_classes span_full ? "md:col-span-2 2xl:col-span-3" : "" end |