Switch

Switch is a form element that allows the user to toggle between two states. It provides a way to turn an option on or off.

Design system docs

Examples Default switch
<dap-ds-switch label="Switch"></dap-ds-switch>
Sizes

The switch component comes in two sizes: small, and large. The default size is small.

<dap-ds-stack direction="column">
    <dap-ds-switch label="SM Switch"></dap-ds-switch>
    <dap-ds-switch label="LG Switch" size="lg"></dap-ds-switch>
  </dap-ds-stack>
Secondary text

The switch component allows for secondary text to be displayed. The secondary text can be placed above or below the switch, and aligned to the left or right.

<dap-ds-stack direction="column">
    <dap-ds-switch
      label="Option 1"
      description="Description bottom, aligned to the right"
      value="switch-1"
    ></dap-ds-switch>

    <dap-ds-switch
      label="Option 2"
      description="Description top, aligned to the right"
      descriptionPlacement="top"
      value="switch-2"
    ></dap-ds-switch>

    <dap-ds-switch
      label="Option 3"
      description="Description bottom, aligned to the left"
      labelPlacement="left"
      value="switch-3"
    ></dap-ds-switch>

    <dap-ds-switch
      label="Option 4"
      description="Description top, aligned to the left"
      descriptionPlacement="top"
      labelPlacement="left"
      value="switch-4"
    ></dap-ds-switch>
  </dap-ds-stack>
Statuses

The switch component comes in three statuses: checked, disabled, and invalid. The default status is unchecked.

<dap-ds-stack direction="column">
    <dap-ds-switch label="Checked" checked></dap-ds-switch>
    <dap-ds-switch label="Disabled" disabled></dap-ds-switch>
    <dap-ds-switch label="Invalid" invalid feedback="Wrong option" feedbackType="negative"></dap-ds-switch>
  </dap-ds-stack>
Switch group

The switch group component allows for multiple switches to be grouped together. Like any other form element, the input group can be used in a form and it has all the form element attributes.

<dap-ds-input-group
      required
      label="Switch Group"
      description="Switch group description"
      tooltip="Tooltip"
      status="error"
      feedback="Invalid switch"
      feedbackType="negative">
      <dap-ds-switch
        label="Label 1"
        description="Secondary label"></dap-ds-switch>
      <dap-ds-switch label="Label 2" checked></dap-ds-switch>
      <dap-ds-switch label="Label 3"></dap-ds-switch>
    </dap-ds-input-group>
Importing
import { DapDSSwitch } from 'dap-design-system/dist/dds'
Importing React
import { DapDSSwitchReact } from 'dap-design-system/dist/react'
Slots

No slots available.

Attributes
PropertyTypeDefaultDescription
size'sm' 'md' 'lg'The size of the switch. Default is md. Can be sm, md, or lg.
namestringThe name of the switch.
valuestringThe value of the switch.
checkedbooleanThe checked state of the switch.
disabledbooleanThe disabled state of the switch.
requiredbooleanThe required state of the switch.
labelstringThe label of the switch.
descriptionstringThe description of the switch.
labelPlacement'left' 'right'The placement of the label. Can be left or right. Default is right.
descriptionPlacement'top' 'bottom'The placement of the description. Can be top or bottom. Default is bottom.
ariaLabelCheckboxstring The aria label of the checkbox.
subtlebooleanThe weight of the label. Default is false
feedbackstringThe feedback of the switch.
feedbackType'info' 'success' 'error'The feedback type of the switch. Can be info, success, or error.
optionalbooleanThe optional state of the switch.
optionalLabelstringThe optional label of the switch.
Events
Event NameDescription
dds-changeFired when the input value changes.
dds-blurEmitted when the input loses focus.
dds-focusEmitted when the input gains focus.
dds-inputEmitted when the input receives input.
CSS Parts
Part NameDescription
baseThe main switch container.
baselabelThe main label container
labelThe label of the switch.
inputThe native input of the switch.
controlThe control of the switch.
descriptionThe description of the switch.