Class: IronAdmin::Form::TextareaComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Form::TextareaComponent
- Includes:
- Concerns::FormInputBehavior
- Defined in:
- app/components/iron_admin/form/textarea_component.rb
Overview
Renders a textarea field.
Instance Attribute Summary collapse
-
#has_error ⇒ Boolean
readonly
Whether textarea has error state.
-
#name ⇒ String
readonly
Textarea name attribute.
-
#placeholder ⇒ String?
readonly
Placeholder text.
-
#readonly ⇒ Boolean
readonly
Whether textarea is read-only.
-
#rows ⇒ Integer
readonly
Number of rows.
-
#value ⇒ String?
readonly
Current value.
Instance Method Summary collapse
-
#call ⇒ String
Renders the textarea.
-
#initialize(name:, value: nil, rows: 4, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) ⇒ TextareaComponent
constructor
A new instance of TextareaComponent.
-
#textarea_classes ⇒ String
private
CSS classes for textarea element.
Constructor Details
#initialize(name:, value: nil, rows: 4, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) ⇒ TextareaComponent
Returns a new instance of TextareaComponent.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 43 def initialize(name:, value: nil, rows: 4, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) @name = name @value = value @rows = rows @placeholder = placeholder || name.to_s.humanize @disabled = disabled @readonly = readonly @has_error = has_error @field = field @current_user = current_user end |
Instance Attribute Details
#has_error ⇒ Boolean (readonly)
Returns Whether textarea has error state.
32 33 34 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 32 def has_error @has_error end |
#name ⇒ String (readonly)
Returns Textarea name attribute.
17 18 19 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 17 def name @name end |
#placeholder ⇒ String? (readonly)
Returns Placeholder text.
26 27 28 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 26 def placeholder @placeholder end |
#readonly ⇒ Boolean (readonly)
Returns Whether textarea is read-only.
29 30 31 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 29 def readonly @readonly end |
#rows ⇒ Integer (readonly)
Returns Number of rows.
23 24 25 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 23 def rows @rows end |
#value ⇒ String? (readonly)
Returns Current value.
20 21 22 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 20 def value @value end |
Instance Method Details
#call ⇒ String
Renders the textarea.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 69 def call tag.textarea( value, name: name, id: name, rows: rows, placeholder: placeholder, disabled: effectively_disabled?, readonly: readonly, class: textarea_classes ) end |
#textarea_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 textarea element.
59 60 61 62 63 64 65 |
# File 'app/components/iron_admin/form/textarea_component.rb', line 59 def textarea_classes base = "block w-full border px-3 py-2 text-sm shadow-sm outline-none transition duration-150 ease-in-out " \ "resize-y #{theme.border_radius} #{theme.input_border} #{theme.card_bg} #{theme.body_text} #{theme.input_focus}" base += " !border-red-400 !focus:border-red-500 !focus:ring-red-500/20" if has_error base += " bg-gray-50 cursor-not-allowed" if effectively_disabled? || readonly base end |