Class: IronAdmin::Form::SelectComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Form::SelectComponent
- Includes:
- Concerns::FormInputBehavior
- Defined in:
- app/components/iron_admin/form/select_component.rb
Overview
Renders a select dropdown field.
Instance Attribute Summary collapse
-
#has_error ⇒ Boolean
readonly
Whether input has error state.
-
#include_blank ⇒ String?
readonly
Blank option text.
-
#name ⇒ String
readonly
Select name attribute.
-
#options ⇒ Array
readonly
Available options.
-
#selected ⇒ String?
readonly
Currently selected value.
Instance Method Summary collapse
-
#chevron_style ⇒ String
private
Inline CSS style for dropdown chevron.
-
#initialize(name:, options:, selected: nil, include_blank: nil, disabled: false, has_error: false, field: nil, current_user: nil) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
-
#select_classes ⇒ String
private
CSS classes for select element.
Constructor Details
#initialize(name:, options:, selected: nil, include_blank: nil, disabled: false, has_error: false, field: nil, current_user: nil) ⇒ SelectComponent
Returns a new instance of SelectComponent.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/iron_admin/form/select_component.rb', line 40 def initialize(name:, options:, selected: nil, include_blank: nil, disabled: false, has_error: false, field: nil, current_user: nil) @name = name @options = @selected = selected @include_blank = include_blank @disabled = disabled @has_error = has_error @field = field @current_user = current_user end |
Instance Attribute Details
#has_error ⇒ Boolean (readonly)
Returns Whether input has error state.
30 31 32 |
# File 'app/components/iron_admin/form/select_component.rb', line 30 def has_error @has_error end |
#include_blank ⇒ String? (readonly)
Returns Blank option text.
27 28 29 |
# File 'app/components/iron_admin/form/select_component.rb', line 27 def include_blank @include_blank end |
#name ⇒ String (readonly)
Returns Select name attribute.
18 19 20 |
# File 'app/components/iron_admin/form/select_component.rb', line 18 def name @name end |
#options ⇒ Array (readonly)
Returns Available options.
21 22 23 |
# File 'app/components/iron_admin/form/select_component.rb', line 21 def @options end |
#selected ⇒ String? (readonly)
Returns Currently selected value.
24 25 26 |
# File 'app/components/iron_admin/form/select_component.rb', line 24 def selected @selected end |
Instance Method Details
#chevron_style ⇒ 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 Inline CSS style for dropdown chevron.
65 66 67 68 69 70 |
# File 'app/components/iron_admin/form/select_component.rb', line 65 def chevron_style "background-image: url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' " \ "viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' " \ "stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e\"); background-position: right 0.5rem center; " \ "background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem;" end |
#select_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 select element.
54 55 56 57 58 59 60 61 |
# File 'app/components/iron_admin/form/select_component.rb', line 54 def select_classes base = "block w-full appearance-none 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? base end |