Class: Polaris::SelectComponent
- Defined in:
- app/components/polaris/select_component.rb
Constant Summary
Constants included from ViewHelper
ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #hides_label? ⇒ Boolean
-
#initialize(options:, form: nil, attribute: nil, name: nil, selected: nil, disabled_options: nil, label: nil, label_hidden: false, label_inline: false, label_action: nil, disabled: false, required: false, help_text: nil, error: false, wrapper_arguments: {}, select_options: {}, input_options: {}, **system_arguments) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #selected_option ⇒ Object
Methods included from ViewHelper
#polaris_body_styles, #polaris_icon_source, #polaris_inversed_colors
Methods included from OptionHelper
#append_option, #prepend_option
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(options:, form: nil, attribute: nil, name: nil, selected: nil, disabled_options: nil, label: nil, label_hidden: false, label_inline: false, label_action: nil, disabled: false, required: false, help_text: nil, error: false, wrapper_arguments: {}, select_options: {}, input_options: {}, **system_arguments) ⇒ SelectComponent
Returns a new instance of SelectComponent.
5 6 7 8 9 10 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/components/polaris/select_component.rb', line 5 def initialize( options:, form: nil, attribute: nil, name: nil, selected: nil, disabled_options: nil, label: nil, label_hidden: false, label_inline: false, label_action: nil, disabled: false, required: false, help_text: nil, error: false, wrapper_arguments: {}, select_options: {}, input_options: {}, **system_arguments ) @form = form @attribute = attribute @name = name @options = @selected = selected @disabled_options = @label = label @label_hidden = label_hidden @label_inline = label_inline @disabled = disabled @system_arguments = system_arguments @system_arguments[:tag] = "div" @system_arguments[:data] ||= {} prepend_option(@system_arguments[:data], :controller, "polaris-select") prepend_option(@system_arguments[:data], :selected_value, @selected) @system_arguments[:classes] = class_names( @system_arguments[:classes], "Polaris-Select", "Polaris-Select--disabled": disabled, "Polaris-Select--error": error ) @wrapper_arguments = { form: form, attribute: attribute, name: name, label: label, label_hidden: hides_label?, label_action: label_action, required: required, help_text: help_text, error: error }.merge(wrapper_arguments) @select_options = @input_options = @input_options.deep_merge!() unless @form @input_options[:class] = class_names(@input_options[:classes], "Polaris-Select__Input") @input_options[:disabled] = disabled @input_options[:data] ||= {} prepend_option(@input_options[:data], :polaris_select_target, "select") prepend_option(@input_options[:data], :action, "polaris-select#update") end |
Instance Method Details
#hides_label? ⇒ Boolean
71 72 73 |
# File 'app/components/polaris/select_component.rb', line 71 def hides_label? @label_hidden || @label_inline end |
#selected_option ⇒ Object
75 76 77 78 79 80 |
# File 'app/components/polaris/select_component.rb', line 75 def selected_option option = @options.to_a.find { |i| i.last.to_s == @selected.to_s } return unless option option.first end |