Class: LightningUiKit::DatePickerComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- LightningUiKit::DatePickerComponent
- Defined in:
- app/components/lightning_ui_kit/date_picker_component.rb
Instance Attribute Summary collapse
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(name:, selected: nil, form: nil, placeholder: "Pick a date", format: "%B %-d, %Y", **options) ⇒ DatePickerComponent
constructor
A new instance of DatePickerComponent.
- #input_name ⇒ Object
- #label_text ⇒ Object
- #panel_classes ⇒ Object
- #selected? ⇒ Boolean
- #selected_iso ⇒ Object
- #trigger_classes ⇒ Object
Constructor Details
#initialize(name:, selected: nil, form: nil, placeholder: "Pick a date", format: "%B %-d, %Y", **options) ⇒ DatePickerComponent
Returns a new instance of DatePickerComponent.
2 3 4 5 6 7 8 9 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 2 def initialize(name:, selected: nil, form: nil, placeholder: "Pick a date", format: "%B %-d, %Y", **) @name = name @selected = selected @form = form @placeholder = placeholder @format = format @options = end |
Instance Attribute Details
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
11 12 13 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 11 def placeholder @placeholder end |
Instance Method Details
#data ⇒ Object
47 48 49 50 51 52 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 47 def data { controller: "lui-date-picker", action: "keydown.esc@window->lui-date-picker#close click@window->lui-date-picker#closeOnOutside" }.merge(@options[:data] || {}) end |
#input_name ⇒ Object
32 33 34 35 36 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 32 def input_name return @name unless @form && @name "#{@form.object_name}[#{@name}]" end |
#label_text ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 23 def label_text return placeholder unless selected? date = @selected.respond_to?(:strftime) ? @selected : Date.parse(@selected.to_s) date.strftime(@format) rescue ArgumentError, TypeError selected_iso end |
#panel_classes ⇒ Object
43 44 45 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 43 def panel_classes "lui:hidden lui:absolute lui:left-0 lui:top-full lui:z-50 lui:mt-1.5" end |
#selected? ⇒ Boolean
13 14 15 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 13 def selected? !(@selected.nil? || @selected == "") end |
#selected_iso ⇒ Object
17 18 19 20 21 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 17 def selected_iso return nil unless selected? @selected.respond_to?(:strftime) ? @selected.strftime("%Y-%m-%d") : @selected.to_s end |
#trigger_classes ⇒ Object
38 39 40 41 |
# File 'app/components/lightning_ui_kit/date_picker_component.rb', line 38 def trigger_classes muted = selected? ? "" : " lui:text-foreground-muted" "lui:inline-flex lui:h-9 lui:w-56 lui:items-center lui:gap-2 lui:rounded-md lui:border lui:border-border lui:bg-surface-input lui:px-3 lui:text-left lui:text-sm lui:text-foreground lui:transition-colors lui:hover:bg-surface-hover lui:focus:outline-focus lui:cursor-pointer#{muted}" end |