Class: IronAdmin::Form::DatePickerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Form::DatePickerComponent
- Defined in:
- app/components/iron_admin/form/date_picker_component.rb
Overview
Renders a date/time picker input.
Constant Summary collapse
- TYPES =
Supported date/time types.
%i[date datetime datetime_local time].freeze
Instance Attribute Summary collapse
-
#disabled ⇒ Boolean
readonly
Whether input is disabled.
-
#has_error ⇒ Boolean
readonly
Whether input has error state.
-
#max ⇒ Date?
readonly
Maximum date.
-
#min ⇒ Date?
readonly
Minimum date.
-
#name ⇒ String
readonly
Input name attribute.
-
#type ⇒ Symbol
readonly
Picker type (:date, :datetime, :datetime_local, :time).
-
#value ⇒ Date, ...
readonly
Current value.
Instance Method Summary collapse
-
#call ⇒ String
Renders the date picker input.
-
#formatted_value ⇒ String?
private
Value formatted for HTML input.
-
#initialize(name:, value: nil, type: :datetime_local, min: nil, max: nil, disabled: false, has_error: false) ⇒ DatePickerComponent
constructor
A new instance of DatePickerComponent.
-
#input_classes ⇒ String
private
CSS classes for date input field.
-
#input_type ⇒ String
private
HTML input type attribute value.
-
#theme ⇒ IronAdmin::Configuration::Theme
private
Theme configuration.
Constructor Details
#initialize(name:, value: nil, type: :datetime_local, min: nil, max: nil, disabled: false, has_error: false) ⇒ DatePickerComponent
Returns a new instance of DatePickerComponent.
46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 46 def initialize(name:, value: nil, type: :datetime_local, min: nil, max: nil, disabled: false, has_error: false) @name = name @value = value @type = type.to_sym @min = min @max = max @disabled = disabled @has_error = has_error end |
Instance Attribute Details
#disabled ⇒ Boolean (readonly)
Returns Whether input is disabled.
30 31 32 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 30 def disabled @disabled end |
#has_error ⇒ Boolean (readonly)
Returns Whether input has error state.
33 34 35 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 33 def has_error @has_error end |
#max ⇒ Date? (readonly)
Returns Maximum date.
27 28 29 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 27 def max @max end |
#min ⇒ Date? (readonly)
Returns Minimum date.
24 25 26 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 24 def min @min end |
#name ⇒ String (readonly)
Returns Input name attribute.
15 16 17 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 15 def name @name end |
#type ⇒ Symbol (readonly)
Returns Picker type (:date, :datetime, :datetime_local, :time).
21 22 23 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 21 def type @type end |
#value ⇒ Date, ... (readonly)
Returns Current value.
18 19 20 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 18 def value @value end |
Instance Method Details
#call ⇒ String
Renders the date picker input.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 102 def call tag.input( type: input_type, name: name, id: name, value: formatted_value, min: min, max: max, disabled: disabled, class: input_classes ) end |
#formatted_value ⇒ 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 Value formatted for HTML input.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 85 def formatted_value return nil unless value case @type when :date value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value when :datetime, :datetime_local value.respond_to?(:strftime) ? value.strftime("%Y-%m-%dT%H:%M") : value when :time value.respond_to?(:strftime) ? value.strftime("%H:%M") : value else value end 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 date input field.
75 76 77 78 79 80 81 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 75 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 disabled base end |
#input_type ⇒ 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 HTML input type attribute value.
65 66 67 68 69 70 71 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 65 def input_type case @type when :datetime_local then "datetime-local" when :datetime then "datetime-local" else @type.to_s end 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.
59 60 61 |
# File 'app/components/iron_admin/form/date_picker_component.rb', line 59 def theme IronAdmin.configuration.theme end |