Class: Spina::Forms::TextFieldComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Spina::Forms::TextFieldComponent
- Defined in:
- app/components/spina/forms/text_field_component.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#autofocus ⇒ Object
Returns the value of attribute autofocus.
-
#f ⇒ Object
Returns the value of attribute f.
-
#method ⇒ Object
Returns the value of attribute method.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #controllers ⇒ Object
- #error_messages ⇒ Object
- #error_styles ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(f, method, size: "md", autofocus: false, placeholder: nil) ⇒ TextFieldComponent
constructor
A new instance of TextFieldComponent.
- #placeholder ⇒ Object
- #size_styles ⇒ Object
Constructor Details
#initialize(f, method, size: "md", autofocus: false, placeholder: nil) ⇒ TextFieldComponent
Returns a new instance of TextFieldComponent.
6 7 8 9 10 11 12 |
# File 'app/components/spina/forms/text_field_component.rb', line 6 def initialize(f, method, size: "md", autofocus: false, placeholder: nil) @f = f @method = method @size = size @autofocus = autofocus @placeholder = placeholder end |
Instance Attribute Details
#autofocus ⇒ Object
Returns the value of attribute autofocus.
4 5 6 |
# File 'app/components/spina/forms/text_field_component.rb', line 4 def autofocus @autofocus end |
#f ⇒ Object
Returns the value of attribute f.
4 5 6 |
# File 'app/components/spina/forms/text_field_component.rb', line 4 def f @f end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'app/components/spina/forms/text_field_component.rb', line 4 def method @method end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'app/components/spina/forms/text_field_component.rb', line 4 def size @size end |
Instance Method Details
#controllers ⇒ Object
14 15 16 17 18 |
# File 'app/components/spina/forms/text_field_component.rb', line 14 def controllers contr = [] contr << "autofocus" if autofocus contr.join(" ") end |
#error_messages ⇒ Object
37 38 39 |
# File 'app/components/spina/forms/text_field_component.rb', line 37 def f.object.errors[method.to_sym] end |
#error_styles ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/components/spina/forms/text_field_component.rb', line 29 def error_styles if has_errors? "border-red-500 ring-red-500 ring-1" else "" end end |
#has_errors? ⇒ Boolean
41 42 43 |
# File 'app/components/spina/forms/text_field_component.rb', line 41 def has_errors? .present? end |
#placeholder ⇒ Object
45 46 47 |
# File 'app/components/spina/forms/text_field_component.rb', line 45 def placeholder @placeholder || f.object.class.human_attribute_name(method) end |
#size_styles ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/components/spina/forms/text_field_component.rb', line 20 def size_styles case size when "lg" "px-4 py-3" else "text-sm" end end |