Class: Autocomplete::OptionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/autocomplete/option_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(label:, multiple: false, **system_arguments) ⇒ OptionComponent

Returns a new instance of OptionComponent.



3
4
5
6
7
8
9
10
11
# File 'app/components/polaris/autocomplete/option_component.rb', line 3

def initialize(
  label:,
  multiple: false,
  **system_arguments
)
  @label = label
  @multiple = multiple
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
# File 'app/components/polaris/autocomplete/option_component.rb', line 27

def call
  if @multiple
    render OptionList::CheckboxComponent.new(**system_arguments)
  else
    render OptionList::RadioButtonComponent.new(**system_arguments)
  end
end

#system_argumentsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/polaris/autocomplete/option_component.rb', line 13

def system_arguments
  @system_arguments.tap do |args|
    args[:label] = @label

    args[:wrapper_arguments] ||= {}
    args[:wrapper_arguments][:data] ||= {}
    args[:wrapper_arguments][:data][:polaris_autocomplete_target] = "option"
    args[:wrapper_arguments][:data][:label] = @label

    args[:data] ||= {}
    prepend_option(args[:data], :action, "polaris-autocomplete#select")
  end
end