Class: Polaris::CheckboxComponent
- Includes:
- ActiveModel::Validations
- Defined in:
- app/components/polaris/checkbox_component.rb
Constant Summary
Constants included from ViewHelper
ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
Instance Method Summary collapse
- #before_render ⇒ Object
- #checkbox ⇒ Object
- #icon_name ⇒ Object
- #indeterminate? ⇒ Boolean
-
#initialize(form: nil, attribute: nil, name: nil, label: nil, label_hidden: false, checked: false, disabled: false, help_text: nil, error: nil, value: "1", unchecked_value: "0", wrapper_arguments: {}, input_options: {}, **system_arguments) ⇒ CheckboxComponent
constructor
A new instance of CheckboxComponent.
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(form: nil, attribute: nil, name: nil, label: nil, label_hidden: false, checked: false, disabled: false, help_text: nil, error: nil, value: "1", unchecked_value: "0", wrapper_arguments: {}, input_options: {}, **system_arguments) ⇒ CheckboxComponent
Returns a new instance of CheckboxComponent.
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 |
# File 'app/components/polaris/checkbox_component.rb', line 11 def initialize( form: nil, attribute: nil, name: nil, label: nil, label_hidden: false, checked: false, disabled: false, help_text: nil, error: nil, value: "1", unchecked_value: "0", wrapper_arguments: {}, input_options: {}, **system_arguments ) @form = form @attribute = attribute @name = name @checked = checked @disabled = disabled @value = value @unchecked_value = unchecked_value @system_arguments = system_arguments @system_arguments[:tag] = "span" @system_arguments[:classes] = class_names( @system_arguments[:classes], "Polaris-Checkbox", "Polaris-Checkbox--labelHidden": label_hidden, "Polaris-Checkbox--error": error.present? ) @wrapper_arguments = { label: label, label_hidden: label_hidden, disabled: disabled, help_text: help_text, error: error }.merge(wrapper_arguments) @input_options = @input_options[:classes] = class_names( @input_options[:classes], "Polaris-Checkbox__Input", "Polaris-Checkbox__Input--indeterminate": indeterminate? ) end |
Instance Attribute Details
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
7 8 9 |
# File 'app/components/polaris/checkbox_component.rb', line 7 def checked @checked end |
Instance Method Details
#before_render ⇒ Object
68 69 70 |
# File 'app/components/polaris/checkbox_component.rb', line 68 def before_render validate! end |
#checkbox ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/components/polaris/checkbox_component.rb', line 72 def checkbox render Polaris::BaseCheckbox.new( form: @form, attribute: @attribute, name: @name, checked: @checked, disabled: @disabled, value: @value, unchecked_value: @unchecked_value, **@input_options ) end |
#icon_name ⇒ Object
64 65 66 |
# File 'app/components/polaris/checkbox_component.rb', line 64 def icon_name indeterminate? ? "MinusMinor" : "TickSmallMinor" end |
#indeterminate? ⇒ Boolean
60 61 62 |
# File 'app/components/polaris/checkbox_component.rb', line 60 def indeterminate? @checked == :indeterminate end |