Class: StimulusPlumbers::Components::DatePicker::Renderer

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

Constant Summary collapse

STIMULUS_CONTROLLER =
"datepicker"
POPOVER_CONTROLLER =
"popover"
CALENDAR_CONTROLLER =
Calendar::Renderer::OBSERVER_STIMULUS_CONTROLLER
CALENDAR_OUTLET =
"#{STIMULUS_CONTROLLER}_#{Calendar::Renderer::STIMULUS_CONTROLLER}_outlet".freeze
STIMULUS_DATA =
{
  controller: "#{STIMULUS_CONTROLLER} #{POPOVER_CONTROLLER}",
  action:     "#{CALENDAR_CONTROLLER}:selected->#{STIMULUS_CONTROLLER}#selected " \
              "#{CALENDAR_CONTROLLER}:selected->#{POPOVER_CONTROLLER}#hide"
}.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::HtmlOptions

#merge_html_options, #merge_string_option, #normalize_part

Constructor Details

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

Instance Method Details

#render(calendar_id: nil, calendar_dialog_id: nil, **kwargs) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stimulus_plumbers/components/date_picker/renderer.rb', line 17

def render(calendar_id: nil, calendar_dialog_id: nil, **kwargs)
  data         = calendar_id ? STIMULUS_DATA.merge(CALENDAR_OUTLET => "##{calendar_id}") : STIMULUS_DATA
  html_options = merge_html_options(
    { classes: theme.resolve(:datepicker).fetch(:classes, ""), data: data },
    kwargs
  )

  template.(:div, **html_options) do
    template.safe_join([display_input(calendar_dialog_id), hidden_input, popover(calendar_id, calendar_dialog_id)])
  end
end