Module: StimulusPlumbers::Helpers::ComboboxHelper

Included in:
StimulusPlumbers::Helpers
Defined in:
lib/stimulus_plumbers/helpers/combobox_helper.rb

Instance Method Summary collapse

Instance Method Details

#sp_combobox(value: nil, label: nil, id: nil, close_on_select: nil, **kwargs, &block) ⇒ Object

Single entry point; panel type chosen by a block method (c.dropdown/date/…).



7
8
9
10
11
12
13
14
15
16
# File 'lib/stimulus_plumbers/helpers/combobox_helper.rb', line 7

def sp_combobox(value: nil, label: nil, id: nil, close_on_select: nil, **kwargs, &block)
  Components::Combobox.new(self).render(
    id:              id || sp_dom_id,
    label:           label,
    input:           { value: value },
    close_on_select: close_on_select,
    **kwargs,
    &block
  )
end

#sp_combobox_date(value: nil, label: nil, **kwargs) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/stimulus_plumbers/helpers/combobox_helper.rb', line 18

def sp_combobox_date(value: nil, label: nil, **kwargs)
  sp_combobox(value: value, label: label, **kwargs) do |c|
    panel_opts = { value: value }
    panel_opts[:label] = label if label
    c.date(**panel_opts)
  end
end

#sp_combobox_dropdown(options: [], value: nil, label: nil, **kwargs) ⇒ Object



26
27
28
29
30
# File 'lib/stimulus_plumbers/helpers/combobox_helper.rb', line 26

def sp_combobox_dropdown(options: [], value: nil, label: nil, **kwargs)
  sp_combobox(value: value, label: label, **kwargs) do |c|
    c.dropdown(options: options, value: value, label: label)
  end
end

#sp_combobox_time(format: :h12, step: 1, value: nil, label: nil, **kwargs) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/stimulus_plumbers/helpers/combobox_helper.rb', line 38

def sp_combobox_time(format: :h12, step: 1, value: nil, label: nil, **kwargs)
  sp_combobox(value: value, label: label, **kwargs) do |c|
    panel_opts = { format: format, step: step, value: value }
    panel_opts[:label] = label if label
    c.time(**panel_opts)
  end
end

#sp_combobox_typeahead(options: [], value: nil, label: nil, url: nil, **kwargs) ⇒ Object



32
33
34
35
36
# File 'lib/stimulus_plumbers/helpers/combobox_helper.rb', line 32

def sp_combobox_typeahead(options: [], value: nil, label: nil, url: nil, **kwargs)
  sp_combobox(value: value, label: label, **kwargs) do |c|
    c.typeahead(options: options, value: value, label: label, url: url)
  end
end