Class: StimulusPlumbers::Components::Combobox::Renderer

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

Constant Summary collapse

STIMULUS_CONTROLLER =
"input-combobox"
FORMAT_CONTROLLER =
"input-format"
FORMAT_ACTION =
"input-combobox:changed->input-format#format"

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

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_data_options, #merge_html_options, #merge_string_option, #normalize_part

Constructor Details

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

Instance Method Details

#render(base_id:, options: {}, **kwargs) ⇒ Object



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
# File 'lib/stimulus_plumbers/components/combobox/renderer.rb', line 11

def render(base_id:, options: {}, **kwargs)
  popover_id    = "#{base_id}_popover"
  initial_value = options.dig(:input, :value)

  base_data = {
    controller: "#{STIMULUS_CONTROLLER} #{FORMAT_CONTROLLER}",
    action:     FORMAT_ACTION
  }
  base_data[:input_combobox_value_value] = initial_value if initial_value.present?

  html_options = merge_html_options({ data: base_data }, kwargs)

  template.(:div, **html_options) do
    template.safe_join(
      [
        trigger_input(
          popover_id,
          options.dig(:popover, :haspopup) || options.dig(:popover, :role) || "dialog",
          options.fetch(:trigger, {})
        ),
        hidden_input(options.fetch(:input, {})),
        popover_element(popover_id, options.fetch(:popover, {}))
      ]
    )
  end
end