{
  "$schema": "../manifest.schema.json",
  "schemaVersion": "1.2.0",
  "name": "ds-switch",
  "description": "Toggle switch component",
  "docUrl": "https://design.soracom.io/design-system/elements/switch/",
  "category": "elements",
  "htmlElements": [
    "label",
    "div"
  ],
  "isWebComponent": false,
  "usageNotes": [
    "Nested .ds-icon elements default to the surrounding label text color through --ds-icon-color, including icons inside label wrappers. Set --color-* or --ds-icon-color on an icon to override its foreground. Shaped icons retain their normal inversion behavior. Built-in thumb icons use the switch icon properties independently.",
    "Color and visual-state modifiers on the switch set the visible label text color, preferring --color-text over --color. Explicit colors on the visible span or div take precedence. Toggle track and thumb colors retain their component defaults; hidden labels use the tooltip foreground.",
    "Use --left-label to place the text before the toggle; --text-left is an alias. Disable the native input with the disabled attribute; --disabled only applies the shared disabled styling.",
    "Size, theme, and radio-group variants adjust the default dimensions and colors. Set public overrides on the switch, or on an individual option label when that option has its own defaults. Thumb inner size and icon-selection properties are derived internally; use --icon-* modifiers to select icons."
  ],
  "modifiers": {
    "size": {
      "support": "subset",
      "values": [
        "--xsmall",
        "--small"
      ]
    },
    "color": {
      "support": "all"
    },
    "visual-state": {
      "support": "all"
    },
    "state": {
      "support": "subset",
      "values": [
        "--disabled"
      ]
    },
    "variant": {
      "support": "custom",
      "values": [
        "--hide-label",
        "--left-label",
        "--theme",
        "--plain"
      ],
      "aliases": {
        "--text-left": "--left-label"
      }
    },
    "icon": {
      "support": "all"
    }
  },
  "cssCustomProperties": [
    {
      "name": "--ds-switch-gap",
      "default": "10px",
      "description": "Default spacing between the toggle and its labels."
    },
    {
      "name": "--ds-switch-label-gap",
      "description": "Overrides the spacing between a toggle and its label, falling back to --ds-switch-gap. Radio option labels supply their own default."
    },
    {
      "name": "--ds-switch-container-background",
      "default": "var(--color-transparent)",
      "description": "Shared background behind the options in a radio-group switch."
    },
    {
      "name": "--ds-switch-toggle-border-size",
      "default": "2px",
      "description": "Thumb border thickness and inset, also used for the focus outline."
    },
    {
      "name": "--ds-switch-toggle-height",
      "default": "30px",
      "description": "Toggle track height."
    },
    {
      "name": "--ds-switch-toggle-width",
      "default": "60px",
      "description": "Toggle track width."
    },
    {
      "name": "--ds-switch-toggle-thumb-size",
      "default": "30px",
      "description": "Outer thumb size used to calculate its inner diameter and travel distance."
    },
    {
      "name": "--ds-switch-toggle-thumb-active",
      "default": "var(--color-background)",
      "description": "Thumb fill when the input is checked."
    },
    {
      "name": "--ds-switch-toggle-thumb-inactive",
      "default": "var(--color-background)",
      "description": "Thumb fill when the input is unchecked."
    },
    {
      "name": "--ds-switch-toggle-background-active",
      "default": "var(--color-highlight)",
      "description": "Track fill when the input is checked."
    },
    {
      "name": "--ds-switch-toggle-background-inactive",
      "default": "var(--color-background-darker)",
      "description": "Track fill when the input is unchecked."
    },
    {
      "name": "--ds-switch-toggle-icon-color-active",
      "default": "var(--color-default)",
      "description": "Thumb icon color when the input is checked."
    },
    {
      "name": "--ds-switch-toggle-icon-color-inactive",
      "default": "var(--color-default)",
      "description": "Thumb icon color when the input is unchecked."
    },
    {
      "name": "--ds-switch-toggle-border-color-active",
      "default": "var(--color-transparent)",
      "description": "Thumb border color when the input is checked."
    },
    {
      "name": "--ds-switch-toggle-border-color-inactive",
      "default": "var(--color-transparent)",
      "description": "Thumb border color when the input is unchecked."
    }
  ],
  "structure": {
    "parts": {
      "control": {
        "element": "input",
        "selector": "input[type=\"checkbox\"], input[type=\"radio\"]",
        "required": true,
        "repeatable": true
      },
      "label": {
        "element": "span",
        "alternativeElements": [
          "div"
        ],
        "required": true,
        "repeatable": true
      },
      "option": {
        "element": "label",
        "optional": true,
        "repeatable": true
      }
    },
    "patterns": {
      "checkbox": "<label class=\"ds-switch\"><input type=\"checkbox\"><span>{label}</span></label>",
      "dual-label": "<label class=\"ds-switch\"><input type=\"checkbox\"><span>{offLabel}</span><span>{onLabel}</span></label>",
      "radio": "<div class=\"ds-switch\"><label><input type=\"radio\" name=\"{name}\" value=\"{value}\"><span>{label}</span></label></div>",
      "theme": "<div class=\"ds-switch --theme --hide-label\"><label class=\"--icon-light-mode\"><input type=\"radio\" name=\"theme\" value=\"light\"><span>Light</span></label><label class=\"--icon-contrast\"><input type=\"radio\" name=\"theme\" value=\"system\"><span>System</span></label><label class=\"--icon-dark-mode\"><input type=\"radio\" name=\"theme\" value=\"dark\"><span>Dark</span></label></div>"
    }
  },
  "attributes": {
    "type": {
      "description": "Native input type for a binary or mutually exclusive switch control.",
      "values": [
        "checkbox",
        "radio"
      ],
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    },
    "name": {
      "description": "Form field name submitted with the switch control value.",
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    },
    "value": {
      "description": "Value submitted when the switch control is selected.",
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    },
    "checked": {
      "description": "Selects the switch control and applies its active appearance.",
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    },
    "disabled": {
      "description": "Disables the switch control and applies the SDS disabled appearance.",
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    },
    "required": {
      "description": "Marks the switch control as required for native form validation.",
      "appliesTo": [
        {
          "part": "control",
          "elements": [
            "input"
          ]
        }
      ]
    }
  },
  "dataAttributes": [],
  "examples": [
    {
      "name": "basic",
      "html": "<label class=\"ds-switch\"><input type=\"checkbox\" /><span>Toggle</span></label>"
    },
    {
      "name": "checked",
      "html": "<label class=\"ds-switch\"><input type=\"checkbox\" checked /><span>Enabled</span></label>"
    },
    {
      "name": "small",
      "html": "<label class=\"ds-switch --small\"><input type=\"checkbox\" /><span>Small switch</span></label>"
    },
    {
      "name": "xsmall",
      "html": "<label class=\"ds-switch --xsmall\"><input type=\"checkbox\" /><span>Extra small</span></label>"
    },
    {
      "name": "alert",
      "html": "<label class=\"ds-switch --alert\"><input type=\"checkbox\" checked /><span>Alert</span></label>"
    },
    {
      "name": "success",
      "html": "<label class=\"ds-switch --success\"><input type=\"checkbox\" checked /><span>Success</span></label>"
    },
    {
      "name": "color-blue",
      "html": "<label class=\"ds-switch --color-blue\"><input type=\"checkbox\" checked /><span>Blue</span></label>"
    },
    {
      "name": "with-icon",
      "html": "<label class=\"ds-switch --icon-lightning\"><input type=\"checkbox\" /><span>With icon</span></label>"
    },
    {
      "name": "icon-on-only",
      "html": "<label class=\"ds-switch\"><input type=\"checkbox\" class=\"--icon-lightning\" /><span>Icon on state only</span></label>"
    },
    {
      "name": "dual-icons",
      "html": "<label class=\"ds-switch --icon-cloud\"><input type=\"checkbox\" class=\"--icon-lightning\" /><span>Different on/off icons</span></label>"
    },
    {
      "name": "hide-label",
      "html": "<label class=\"ds-switch --hide-label\"><input type=\"checkbox\" /><span>Hidden label</span></label>"
    },
    {
      "name": "left-label",
      "html": "<label class=\"ds-switch --left-label\"><input type=\"checkbox\" /><span>Left label</span></label>"
    },
    {
      "name": "plain",
      "html": "<label class=\"ds-switch --plain\"><input type=\"checkbox\" /><span>Plain switch</span></label>"
    },
    {
      "name": "left-right-labels",
      "html": "<label class=\"ds-switch\"><input type=\"checkbox\" /><span>Off</span><span>On</span></label>"
    },
    {
      "name": "multi-radio",
      "html": "<div class=\"ds-switch\"><label><input type=\"radio\" name=\"group\" value=\"a\" checked /><span>Option A</span></label><label><input type=\"radio\" name=\"group\" value=\"b\" /><span>Option B</span></label><label><input type=\"radio\" name=\"group\" value=\"c\" /><span>Option C</span></label></div>"
    },
    {
      "name": "theme",
      "html": "<div class=\"ds-switch --theme --hide-label\"><label class=\"--icon-light-mode\"><input type=\"radio\" name=\"theme\" value=\"light\" /><span>Light</span></label><label class=\"--icon-contrast\"><input type=\"radio\" name=\"theme\" value=\"system\" checked /><span>System</span></label><label class=\"--icon-dark-mode\"><input type=\"radio\" name=\"theme\" value=\"dark\" /><span>Dark</span></label></div>"
    },
    {
      "name": "disabled",
      "html": "<label class=\"ds-switch\"><input type=\"checkbox\" disabled /><span>Disabled</span></label>"
    }
  ]
}
