Skip to main content
Version: latest
Works everywhere

Switch works in both server and client environments. Always use the standard import (e.g. @prokodo/ui/switch) — the library detects the runtime automatically.

Switch

Switch renders a toggle switch (ARIA role="switch") for binary on/off states. Visually distinct from Checkbox — use Switch for settings and preference toggles.

Live demo →

Overview

import { Switch } from "@prokodo/ui/switch"
;<Switch
name="notifications"
label="Email notifications"
checked={enabled}
onChange={e => setEnabled(e.target.checked)}
/>

Import

import { Switch } from "@prokodo/ui/switch"

CSS:

import "@prokodo/ui/switch.css"

Props

PropTypeDefaultRequiredDescription
idstringHTML id for the switch input.
labelstringLabel text.
checkedbooleanControlled checked state.
disabledbooleanfalseDisable the switch.
requiredbooleanfalseMark field as required.
hideLabelbooleanfalseVisually hide the label.
iconstringIcon name for the unchecked state.
checkedIconstringIcon name for the checked state.
colorVariantsAccent color variant.
labelPropsLabelPropsProps forwarded to the label element.
helperTextstringHelper text shown below.
errorTextstringError message.
onChange(event: ChangeEvent<HTMLInputElement>, checked: boolean) => voidCalled when checked state changes.
classNamestringCSS class on root element.

See src/components/switch/Switch.model.ts for the full SwitchProps type.


Design Tokens

Customise Switch via CSS custom properties on :root or a scoped ancestor.

TokenDefaultDescription
--pk-switch-track-width44pxTrack width
--pk-switch-track-height24pxTrack height
--pk-switch-track-bgcolor-mix(in srgb, var(--pk-color-fg) 18%, transparent)Unchecked track colour
--pk-switch-track-checked-bgvar(--pk-color-brand)Checked track colour
--pk-switch-track-radius9999pxTrack corner radius
--pk-switch-thumb-size18pxThumb diameter
--pk-switch-thumb-bg#ffffffThumb colour
--pk-switch-label-fgvar(--pk-color-fg)Label text colour
--pk-switch-activevar(--pk-color-brand)Active / focus accent
--pk-switch-timing180msTransition duration

AIC Note

Use the standard import path in application code:

import { Switch } from "@prokodo/ui/switch"

No separate /client or /lazy import selection is required in consumer code.

AIC components also support a priority flag for critical above-the-fold elements. This is most visible on Image (native preloading via <link rel="preload"> for above-the-fold content).


WCAG 2.2 Status

CriterionNameStatusNote
1.3.1Info and Relationships (A)✅ FulfilledSemantic structure (headings, lists, labels, landmarks) must be conveyed programmatically via HTML or ARIA.
1.4.1Use of Color (A)🔍 Manual reviewColor must not be the only means of conveying information (e.g. error states, required field markers).
2.1.1Keyboard (A)✅ FulfilledAll functionality must be operable via keyboard alone, without requiring specific timing.
2.4.7Focus Visible (AA)🔍 Manual reviewA visible keyboard focus indicator must be present on every interactive element. Verify against the applied product theme.
3.3.2Labels or Instructions (A)✅ FulfilledEvery form input requires a programmatically associated label or a visible instruction.
4.1.2Name, Role, Value (A)✅ FulfilledName, role, and state of all interactive UI components must be programmatically determinable via native HTML semantics or ARIA.

Test coverage: 3 jest-axe assertion(s) across 4 test file(s) · 3 ARIA attribute occurrence(s) in source scan. Criteria marked 🔍 require manual verification in the final product integration and theme context.

Storybook

👉 Open Switch in Storybook


Source

src/components/switch/Switch.model.ts