Class: Maglev::Uikit::Form::SelectComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/maglev/uikit/form/select_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, name:, choices:, options: {}, html_options: {}) ⇒ SelectComponent

Returns a new instance of SelectComponent.



9
10
11
12
13
14
15
16
17
# File 'app/components/maglev/uikit/form/select_component.rb', line 9

def initialize(label:, name:, choices:, options: {}, html_options: {})
  @label = label
  @name = name
  @choices = choices
  @options = options
  @html_options = html_options
  @input_data = html_options.delete(:data) || {}
  @input_action = input_data.delete(:action) || {}
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def choices
  @choices
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def html_options
  @html_options
end

#input_actionObject (readonly)

Returns the value of attribute input_action.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def input_action
  @input_action
end

#input_dataObject (readonly)

Returns the value of attribute input_data.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def input_data
  @input_data
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/components/maglev/uikit/form/select_component.rb', line 7

def options
  @options
end

Instance Method Details

#dom_idObject



19
20
21
# File 'app/components/maglev/uikit/form/select_component.rb', line 19

def dom_id
  name.to_s.parameterize.underscore
end

#errorObject



23
24
25
# File 'app/components/maglev/uikit/form/select_component.rb', line 23

def error
  options[:error]
end

#html_choicesObject



46
47
48
# File 'app/components/maglev/uikit/form/select_component.rb', line 46

def html_choices
  helpers.options_for_select(choices, options[:value])
end

#input_tag_dataObject



36
37
38
39
40
41
42
43
44
# File 'app/components/maglev/uikit/form/select_component.rb', line 36

def input_tag_data
  {
    action: [
      'change->uikit-form-select#change',
      **input_action
    ].join(' '),
    **input_data
  }
end

#input_tag_optionsObject



27
28
29
30
31
32
33
34
# File 'app/components/maglev/uikit/form/select_component.rb', line 27

def input_tag_options
  {
    id: dom_id,
    value: options[:value],
    **options.slice(:multiple, :disabled, :include_blank, :prompt),
    data: input_tag_data
  }
end