Class: Maglev::Uikit::Form::SelectComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Maglev::Uikit::Form::SelectComponent
- Defined in:
- app/components/maglev/uikit/form/select_component.rb
Instance Attribute Summary collapse
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#input_action ⇒ Object
readonly
Returns the value of attribute input_action.
-
#input_data ⇒ Object
readonly
Returns the value of attribute input_data.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #dom_id ⇒ Object
- #error ⇒ Object
- #html_choices ⇒ Object
-
#initialize(label:, name:, choices:, options: {}, html_options: {}) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #input_tag_data ⇒ Object
- #input_tag_options ⇒ Object
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 = @html_options = @input_data = .delete(:data) || {} @input_action = input_data.delete(:action) || {} end |
Instance Attribute Details
#choices ⇒ Object (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_options ⇒ Object (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 end |
#input_action ⇒ Object (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_data ⇒ Object (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 |
#label ⇒ Object (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 |
#name ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/components/maglev/uikit/form/select_component.rb', line 7 def @options end |
Instance Method Details
#dom_id ⇒ Object
19 20 21 |
# File 'app/components/maglev/uikit/form/select_component.rb', line 19 def dom_id name.to_s.parameterize.underscore end |
#error ⇒ Object
23 24 25 |
# File 'app/components/maglev/uikit/form/select_component.rb', line 23 def error [:error] end |
#html_choices ⇒ Object
46 47 48 |
# File 'app/components/maglev/uikit/form/select_component.rb', line 46 def html_choices helpers.(choices, [:value]) end |
#input_tag_data ⇒ Object
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_options ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/components/maglev/uikit/form/select_component.rb', line 27 def { id: dom_id, value: [:value], **.slice(:multiple, :disabled, :include_blank, :prompt), data: input_tag_data } end |