Examples

Basic

Preview

Required by your organisation.

Example.tsx
import { Stack, Switch } from '@reactloom/ui';

export default function Example() {
  return (
    <Stack gap="3">
      <Switch label="Email notifications" defaultChecked />
      <Switch label="Desktop notifications" />
      <Switch label="Audit logging" defaultChecked disabled description="Required by your organisation." />
    </Stack>
  );
}

Settings list

labelPosition="start" for list layouts.

Preview

Security

Changes apply immediately to all members.

Members can create keys scoped to their own projects.

Example.tsx
import { Card, Separator, Stack, Switch } from '@reactloom/ui';

export default function Example() {
  return (
    <Card style={{ width: '100%', maxWidth: 440 }}>
      <Card.Header>
        <Card.Title level={3}>Security</Card.Title>
        <Card.Description>Changes apply immediately to all members.</Card.Description>
      </Card.Header>
      <Stack gap="3">
        <Switch labelPosition="start" label="Require two-factor authentication" defaultChecked />
        <Separator />
        <Switch labelPosition="start" label="Allow personal API keys" description="Members can create keys scoped to their own projects." />
        <Separator />
        <Switch labelPosition="start" label="Restrict sign-in to SSO" />
      </Stack>
    </Card>
  );
}

API reference

Switch props
PropTypeDefault
label · description · error
ReactNode—
checked / defaultChecked
boolean—
onCheckedChange
(checked: boolean) => void—
labelPosition
'start' | 'end''end'
size
'sm' | 'md' | 'lg''md'

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-invalid]present when on
[data-label-position]start · end
[data-size]present when on
[data-type]present when on

Theme tokens it reads

--pl-color-accent-solid --pl-color-bg-muted --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-input --pl-color-danger-border --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-focus-ring-color --pl-focus-ring-offset --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-full --pl-shadow-xs

Accessibility

  • Announced as “switch, on/off”.
  • The thumb animation respects reduced motion.
Keyboard interactions
KeyAction
SpaceToggle

Usage guidelines

Do

  • Apply the change immediately and confirm it.

Don’t

  • Don’t use a switch inside a form that needs a Submit button — use Checkbox.