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, multiple: 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_html_classes, #polaris_html_styles, #polaris_icon_source
Methods included from StylesListHelper
Methods included from OptionHelper
#append_option, #prepend_option
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested
Methods included from ClassNameHelper
Constructor Details
#initialize(form: nil, attribute: nil, name: nil, label: nil, label_hidden: false, checked: false, disabled: false, multiple: 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 59 60 |
# 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, multiple: 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 @multiple = multiple @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
70 71 72 |
# File 'app/components/polaris/checkbox_component.rb', line 70 def before_render validate! end |
#checkbox ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/components/polaris/checkbox_component.rb', line 74 def checkbox render Polaris::BaseCheckbox.new( form: @form, attribute: @attribute, name: @name, checked: @checked, disabled: @disabled, multiple: @multiple, value: @value, unchecked_value: @unchecked_value, **@input_options ) end |
#icon_name ⇒ Object
66 67 68 |
# File 'app/components/polaris/checkbox_component.rb', line 66 def icon_name indeterminate? ? "MinusIcon" : "CheckSmallIcon" end |
#indeterminate? ⇒ Boolean
62 63 64 |
# File 'app/components/polaris/checkbox_component.rb', line 62 def indeterminate? @checked == :indeterminate end |