class Primer::Alpha::ToggleSwitch

make a POST request containing data of the form “value: 0 | 1”.
settings that should cause an immediate update. If configured with a “src” attribute, the component will
The ToggleSwitch component is a button that toggles between two boolean states. It is meant to be used for

def disabled?

def disabled?
  !enabled?
end

def enabled?

def enabled?
  @enabled
end

def initialize(src: nil, csrf_token: nil, checked: false, enabled: true, size: SIZE_DEFAULT, status_label_position: STATUS_LABEL_POSITION_DEFAULT, **system_arguments)

Parameters:
  • system_arguments (Hash) -- <%= link_to_system_arguments_docs %>
  • status_label_position (Symbol) -- Which side of the toggle switch to render the status label. <%= one_of(Primer::Alpha::ToggleSwitch::SIZE_OPTIONS) %>
  • size (Symbol) -- What size toggle switch to render. <%= one_of(Primer::Alpha::ToggleSwitch::STATUS_LABEL_POSITION_OPTIONS) %>
  • enabled (Boolean) -- Whether or not the toggle switch responds to user input.
  • checked (Boolean) -- Whether the toggle switch is on or off.
  • csrf_token (String) -- A CSRF token that will be sent to the server as "authenticity_token" when the toggle switch is toggled. Unused if `src` is `nil`.
  • src (String) -- The URL to POST to when the toggle switch is toggled. If `nil`, the toggle switch will not make any requests.
def initialize(src: nil, csrf_token: nil, checked: false, enabled: true, size: SIZE_DEFAULT, status_label_position: STATUS_LABEL_POSITION_DEFAULT, **system_arguments)
  @src = src
  @csrf_token = csrf_token
  @checked = checked
  @enabled = enabled
  @system_arguments = system_arguments
  @size = fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)
  @status_label_position = fetch_or_fallback(
    STATUS_LABEL_POSITION_OPTIONS, status_label_position, STATUS_LABEL_POSITION_DEFAULT
  )
  @system_arguments[:classes] = class_names(
    @system_arguments.delete(:classes),
    "ToggleSwitch",
    on? ? "ToggleSwitch--checked" : nil,
    enabled? ? nil : "ToggleSwitch--disabled",
    STATUS_LABEL_POSITION_MAPPINGS[@status_label_position],
    SIZE_MAPPINGS[@size]
  )
  @aria_arguments = {
    aria: merge_aria(
      @system_arguments,
      aria: { pressed: on? }
    )
  }
  @system_arguments[:src] = @src if @src
  return unless @src && @csrf_token
  @system_arguments[:csrf] = @csrf_token
end

def on?

def on?
  @checked
end