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.
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
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
id | string | — | — | HTML id for the switch input. |
label | string | — | — | Label text. |
checked | boolean | — | — | Controlled checked state. |
disabled | boolean | false | — | Disable the switch. |
required | boolean | false | — | Mark field as required. |
hideLabel | boolean | false | — | Visually hide the label. |
icon | string | — | — | Icon name for the unchecked state. |
checkedIcon | string | — | — | Icon name for the checked state. |
color | Variants | — | — | Accent color variant. |
labelProps | LabelProps | — | — | Props forwarded to the label element. |
helperText | string | — | — | Helper text shown below. |
errorText | string | — | — | Error message. |
onChange | (event: ChangeEvent<HTMLInputElement>, checked: boolean) => void | — | — | Called when checked state changes. |
className | string | — | — | CSS class on root element. |
See
src/components/switch/Switch.model.tsfor the fullSwitchPropstype.
Design Tokens
Customise Switch via CSS custom properties on :root or a scoped ancestor.
| Token | Default | Description |
|---|---|---|
--pk-switch-track-width | 44px | Track width |
--pk-switch-track-height | 24px | Track height |
--pk-switch-track-bg | color-mix(in srgb, var(--pk-color-fg) 18%, transparent) | Unchecked track colour |
--pk-switch-track-checked-bg | var(--pk-color-brand) | Checked track colour |
--pk-switch-track-radius | 9999px | Track corner radius |
--pk-switch-thumb-size | 18px | Thumb diameter |
--pk-switch-thumb-bg | #ffffff | Thumb colour |
--pk-switch-label-fg | var(--pk-color-fg) | Label text colour |
--pk-switch-active | var(--pk-color-brand) | Active / focus accent |
--pk-switch-timing | 180ms | Transition 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
| Criterion | Name | Status | Note |
|---|---|---|---|
| 1.3.1 | Info and Relationships (A) | ✅ Fulfilled | Semantic structure (headings, lists, labels, landmarks) must be conveyed programmatically via HTML or ARIA. |
| 1.4.1 | Use of Color (A) | 🔍 Manual review | Color must not be the only means of conveying information (e.g. error states, required field markers). |
| 2.1.1 | Keyboard (A) | ✅ Fulfilled | All functionality must be operable via keyboard alone, without requiring specific timing. |
| 2.4.7 | Focus Visible (AA) | 🔍 Manual review | A visible keyboard focus indicator must be present on every interactive element. Verify against the applied product theme. |
| 3.3.2 | Labels or Instructions (A) | ✅ Fulfilled | Every form input requires a programmatically associated label or a visible instruction. |
| 4.1.2 | Name, Role, Value (A) | ✅ Fulfilled | Name, 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.