Class: IronAdmin::Form::TextInputComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Form::TextInputComponent
- Includes:
- Concerns::FormInputBehavior
- Defined in:
- app/components/iron_admin/form/text_input_component.rb
Overview
Renders a text input field.
Instance Attribute Summary collapse
-
#has_error ⇒ Boolean
readonly
Whether input has error state.
-
#name ⇒ String
readonly
Input name attribute.
-
#placeholder ⇒ String?
readonly
Placeholder text.
-
#readonly ⇒ Boolean
readonly
Whether input is read-only.
-
#type ⇒ Symbol
readonly
Input type (:text, :email, :password, etc.).
-
#value ⇒ String?
readonly
Current value.
Instance Method Summary collapse
-
#call ⇒ String
Renders the text input.
-
#initialize(name:, value: nil, type: :text, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) ⇒ TextInputComponent
constructor
A new instance of TextInputComponent.
-
#input_classes ⇒ String
private
CSS classes for text input field.
Constructor Details
#initialize(name:, value: nil, type: :text, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) ⇒ TextInputComponent
Returns a new instance of TextInputComponent.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 39 def initialize(name:, value: nil, type: :text, placeholder: nil, disabled: false, readonly: false, has_error: false, field: nil, current_user: nil) @name = name @value = value @type = type @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 input has error state.
28 29 30 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 28 def has_error @has_error end |
#name ⇒ String (readonly)
Returns Input name attribute.
13 14 15 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 13 def name @name end |
#placeholder ⇒ String? (readonly)
Returns Placeholder text.
22 23 24 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 22 def placeholder @placeholder end |
#readonly ⇒ Boolean (readonly)
Returns Whether input is read-only.
25 26 27 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 25 def readonly @readonly end |
#type ⇒ Symbol (readonly)
Returns Input type (:text, :email, :password, etc.).
19 20 21 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 19 def type @type end |
#value ⇒ String? (readonly)
Returns Current value.
16 17 18 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 16 def value @value end |
Instance Method Details
#call ⇒ String
Renders the text input.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 65 def call tag.input( type: type, name: name, id: name, value: value, placeholder: placeholder, disabled: effectively_disabled?, readonly: readonly, class: input_classes ) end |
#input_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 text input field.
55 56 57 58 59 60 61 |
# File 'app/components/iron_admin/form/text_input_component.rb', line 55 def input_classes base = "block w-full border px-3 py-2 text-sm shadow-sm outline-none transition duration-150 ease-in-out " \ "#{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 |