Class: LightningUiKit::CalendarComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- LightningUiKit::CalendarComponent
- Defined in:
- app/components/lightning_ui_kit/calendar_component.rb
Instance Method Summary collapse
- #classes ⇒ Object
- #data ⇒ Object
- #initial_month ⇒ Object
-
#initialize(name: nil, selected: nil, month: nil, form: nil, **options) ⇒ CalendarComponent
constructor
A new instance of CalendarComponent.
- #input_name ⇒ Object
- #nav_button_classes ⇒ Object
- #selected_iso ⇒ Object
Constructor Details
#initialize(name: nil, selected: nil, month: nil, form: nil, **options) ⇒ CalendarComponent
Returns a new instance of CalendarComponent.
2 3 4 5 6 7 8 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 2 def initialize(name: nil, selected: nil, month: nil, form: nil, **) @name = name @selected = selected @month = month @form = form @options = end |
Instance Method Details
#classes ⇒ Object
29 30 31 32 33 34 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 29 def classes merge_classes([ "lui:inline-block lui:w-fit lui:rounded-lg lui:border lui:border-border lui:bg-surface lui:p-3 lui:text-foreground", @options[:class] ].compact.join(" ")) end |
#data ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 40 def data { controller: "lui-calendar", lui_calendar_selected_value: selected_iso, lui_calendar_month_value: initial_month }.compact.merge(@options[:data] || {}) end |
#initial_month ⇒ Object
16 17 18 19 20 21 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 16 def initial_month return @month if @month iso = selected_iso iso ? iso[0, 7] : nil end |
#input_name ⇒ Object
23 24 25 26 27 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 23 def input_name return @name unless @form && @name "#{@form.object_name}[#{@name}]" end |
#nav_button_classes ⇒ Object
36 37 38 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 36 def "lui:inline-flex lui:size-7 lui:items-center lui:justify-center lui:rounded-md lui:text-foreground-muted lui:transition-colors lui:hover:bg-surface-hover lui:hover:text-foreground lui:cursor-pointer" end |
#selected_iso ⇒ Object
10 11 12 13 14 |
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 10 def selected_iso return nil if @selected.nil? || @selected == "" @selected.respond_to?(:strftime) ? @selected.strftime("%Y-%m-%d") : @selected.to_s end |