Class: Polaris::BaseCheckbox

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/base_checkbox.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

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

#class_names

Constructor Details

#initialize(form: nil, attribute: nil, name: nil, checked: false, disabled: false, mulitple: false, value: "1", unchecked_value: "0", **system_arguments) ⇒ BaseCheckbox

Returns a new instance of BaseCheckbox.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/components/polaris/base_checkbox.rb', line 3

def initialize(
  form: nil,
  attribute: nil,
  name: nil,
  checked: false,
  disabled: false,
  mulitple: false,
  value: "1",
  unchecked_value: "0",
  **system_arguments
)
  @form = form
  @attribute = attribute
  @name = name
  @checked = checked
  @disabled = disabled
  @value = value
  @unchecked_value = unchecked_value
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



44
45
46
47
48
49
50
# File 'app/components/polaris/base_checkbox.rb', line 44

def call
  if @form.present? && @attribute.present?
    @form.check_box(@attribute, system_arguments, @value, @unchecked_value)
  else
    check_box_tag(@name, @value, @checked, system_arguments)
  end
end

#indeterminate?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/components/polaris/base_checkbox.rb', line 40

def indeterminate?
  @checked == :indeterminate
end

#system_argumentsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/components/polaris/base_checkbox.rb', line 24

def system_arguments
  @system_arguments.tap do |opts|
    opts[:checked] = true if @checked
    opts[:disabled] = true if @disabled
    opts[:multiple] = true if @multiple
    opts[:aria] ||= {}
    opts[:aria][:checked] = @checked
    if indeterminate?
      @system_arguments[:indeterminate] = true
      @system_arguments[:aria][:checked] = "mixed"
    end
    opts[:class] = opts.delete(:classes)
    opts[:form] = @form if @form.present? && @attribute.blank?
  end
end