Class: LightningUiKit::CalendarComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/lightning_ui_kit/calendar_component.rb

Instance Method Summary collapse

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, **options)
  @name = name
  @selected = selected
  @month = month
  @form = form
  @options = options
end

Instance Method Details

#classesObject



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

#dataObject



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_monthObject



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_nameObject



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


36
37
38
# File 'app/components/lightning_ui_kit/calendar_component.rb', line 36

def nav_button_classes
  "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_isoObject



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