Class: StimulusPlumbers::Components::Combobox::Date

Inherits:
Plumber::Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/components/combobox/date.rb

Overview

Renders the date picker popover body: navigation + calendar grid. Wires ComboboxDateController; dispatches combobox-date:selected → InputComboboxController.

Constant Summary collapse

PICKER_CONTROLLER =
"combobox-date"
CALENDAR_OUTLET_KEY =
"#{PICKER_CONTROLLER.tr("-", "_")}_calendar_month_outlet".freeze

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#merge_data_options, #merge_html_options, #merge_string_option, #normalize_part

Constructor Details

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

Class Method Details

.default_optsObject



12
13
14
15
16
17
# File 'lib/stimulus_plumbers/components/combobox/date.rb', line 12

def self.default_opts
  {
    input:   { data: { combobox_date_date_value: nil } },
    popover: { label: "Picker", role: "dialog", tag: :div }
  }
end

Instance Method Details

#render(value: nil, **_kwargs) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stimulus_plumbers/components/combobox/date.rb', line 19

def render(value: nil, **_kwargs)
  calendar_id = "combobox_date_#{SecureRandom.hex(8)}_calendar"

  template.(
    :div,
    data: {
      controller:        PICKER_CONTROLLER,
      CALENDAR_OUTLET_KEY => "##{calendar_id}",
      action:            [
        "calendar-month-observer:selected->#{PICKER_CONTROLLER}#onSelected",
        "#{PICKER_CONTROLLER}:selected->input-combobox#onSelected"
      ].join(" ")
    }.tap { |d| d["#{PICKER_CONTROLLER.tr("-", "_")}_date_value"] = value if value }
  ) do
    template.safe_join([navigation, calendar_month(id: calendar_id)])
  end
end