tsimport {XDSSwitch} from '@xds/core/Switch'
| Guidance | Practices |
|---|---|
| Do | Use for settings that apply immediately — the toggle should take effect without a separate save action. |
| Do | Pair with a clear, concise label that describes the setting being controlled. |
| Don't | Use for options that require a form submission to take effect — use a checkbox instead. |
| Don't | Use a switch for multi-state values — it's strictly on/off. |
tsx'use client';import {useState} from 'react';import {XDSSwitch} from '@xds/core/Switch';import {XDSCenter} from '@xds/core/Center';export default function SwitchDisabled() {const [value, setValue] = useState(false);return (<XDSCenter><XDSSwitchlabel="Premium feature"description="Upgrade to enable this option"value={value}onChange={setValue}isDisabled/></XDSCenter>);}
tsx'use client';import {useState} from 'react';import {XDSSwitch} from '@xds/core/Switch';import {XDSCard} from '@xds/core/Card';import {XDSVStack} from '@xds/core/Layout';import {XDSCenter} from '@xds/core/Center';export default function SwitchSettingsPanel() {const [notifications, setNotifications] = useState(false);const [darkMode, setDarkMode] = useState(true);const [autoSave, setAutoSave] = useState(false);return (<XDSCenter width={350}><XDSCard><XDSVStack gap={4}><XDSSwitchlabel="Enable notifications"value={notifications}onChange={setNotifications}labelPosition="start"labelSpacing="spread"/><XDSSwitchlabel="Dark mode"value={darkMode}onChange={setDarkMode}labelPosition="start"labelSpacing="spread"/><XDSSwitchlabel="Auto-save"value={autoSave}onChange={setAutoSave}labelPosition="start"labelSpacing="spread"/></XDSVStack></XDSCard></XDSCenter>);}
tsx'use client';import {useState} from 'react';import {XDSSwitch} from '@xds/core/Switch';import {XDSCenter} from '@xds/core/Center';export default function SwitchWithDescription() {const [value, setValue] = useState(false);return (<XDSCenter><XDSSwitchlabel="Dark mode"description="Switch to a darker color scheme for reduced eye strain."value={value}onChange={setValue}/></XDSCenter>);}
tsx'use client';import {useState} from 'react';import {XDSSwitch} from '@xds/core/Switch';import {XDSVStack} from '@xds/core/Layout';import {XDSCenter} from '@xds/core/Center';export default function SwitchWithStatus() {const [terms, setTerms] = useState(false);const [sharing, setSharing] = useState(true);const [twoFactor, setTwoFactor] = useState(true);return (<XDSCenter width={400}><XDSVStack gap={6}><XDSSwitchlabel="Accept terms and conditions"value={terms}onChange={setTerms}isRequiredstatus={{type: 'error',message: 'You must accept the terms to continue',}}/><XDSSwitchlabel="Share usage data"description="Help us improve by sharing anonymous usage statistics"value={sharing}onChange={setSharing}status={{type: 'warning',message: 'This data may be shared with partners',}}/><XDSSwitchlabel="Two-factor authentication"value={twoFactor}onChange={setTwoFactor}status={{type: 'success', message: 'Your account is now more secure'}}/></XDSVStack></XDSCenter>);}
tsx'use client';import {XDSSwitch} from '@xds/core/Switch';export default function SwitchShowcase() {return (<XDSSwitchlabel="Enable notifications"value={false}onChange={() => {}}/>);}