Class: StimulusPlumbers::Components::Calendar::Turbo

Inherits:
Plumber::Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/components/calendar/turbo.rb,
lib/stimulus_plumbers/components/calendar/turbo/days_of_week.rb,
lib/stimulus_plumbers/components/calendar/turbo/days_of_month.rb,
lib/stimulus_plumbers/components/calendar/turbo/months_of_year.rb,
lib/stimulus_plumbers/components/calendar/turbo/years_of_decade.rb

Defined Under Namespace

Classes: DaysOfMonth, DaysOfWeek, MonthsOfYear, YearsOfDecade

Constant Summary collapse

STIMULUS_CONTROLLER =
"calendar-observer"
STIMULUS_ACTION =
"click->#{STIMULUS_CONTROLLER}#onSelect".freeze

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::Renderer

#set_slots, #slot_block_for, #slot_kwargs_for, #slot_renderable?

Methods included from Plumber::Options::Aria

#labelled_aria

Methods included from Plumber::Options::Html

#merge_html_options

Constructor Details

This class inherits a constructor from StimulusPlumbers::Plumber::Base

Instance Method Details

#decade(date: Date.today, today: Date.today, selected_date: nil, **kwargs) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/stimulus_plumbers/components/calendar/turbo.rb', line 52

def decade(date: Date.today, today: Date.today, selected_date: nil, **kwargs)
  html_options = merge_html_options(
    theme.resolve(:calendar_quarter_grid),
    kwargs,
    { role: "grid", aria: { label: "Decade view" } }
  )
  template.(:div, **html_options) do
    Turbo::YearsOfDecade.new(template, date: date, today: today, selected_date: selected_date).render
  end
end

#month(date: Date.today, today: Date.today, show_other_months: false, weekday_format: :short, **kwargs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stimulus_plumbers/components/calendar/turbo.rb', line 10

def month(
  date: Date.today,
  today: Date.today,
  show_other_months: false,
  weekday_format: :short,
  **kwargs
)
  selectable = kwargs.delete(:selectable) { false }
  selected_date = kwargs.delete(:selected_date) { nil }
  html_options = merge_html_options(
    theme.resolve(:calendar),
    kwargs,
    { data: { controller: STIMULUS_CONTROLLER, action: STIMULUS_ACTION } }
  )
  template.(:div, role: "grid", **html_options) do
    template.safe_join(
      [
        Turbo::DaysOfWeek.new(template, format: weekday_format).render,
        Turbo::DaysOfMonth.new(
          template,
          date:              date,
          today:             today,
          selectable:        selectable,
          selected_date:     selected_date,
          show_other_months: show_other_months
        ).render
      ]
    )
  end
end

#year(date: Date.today, today: Date.today, selected_date: nil, month_format: :short, **kwargs) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/stimulus_plumbers/components/calendar/turbo.rb', line 41

def year(date: Date.today, today: Date.today, selected_date: nil, month_format: :short, **kwargs)
  html_options = merge_html_options(
    theme.resolve(:calendar_quarter_grid),
    kwargs,
    { role: "grid", aria: { label: "Year view" } }
  )
  template.(:div, **html_options) do
    Turbo::MonthsOfYear.new(template, date: date, today: today, selected_date: selected_date, format: month_format).render
  end
end