Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
Enable notifications
'use client';
import { useState } from 'react';
import { Switch } from '@/ui/forms/Switch';
export function SwitchDemo() {
const [isEnabled, setIsEnabled] = useState(false);
return (
<div className="flex items-center gap-3">
<Switch checked={isEnabled} onClick={() => setIsEnabled(!isEnabled)} />
<span className="text-b2 font-semibold">Enable notifications</span>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/switch.json
Usage
'use client';
import { useState } from 'react';
import { Switch } from '@/docs/lib/ui/forms/switch';
export function Component() {
const [isEnabled, setIsEnabled] = useState(false);
return (
<div className="flex items-center gap-3">
<Switch
checked={isEnabled}
onClick={() => setIsEnabled(!isEnabled)}
color="saffron"
/>
<span>Enable notifications</span>
</div>
);
}API Reference
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | undefined | The controlled checked state of the switch |
onClick | MouseEventHandler<HTMLButtonElement> | undefined | Click handler called when switch is clicked (not called when disabled) |
color | Colors | 'saffron' | Color theme for the switch when checked. Valid values: saffron, black, darkGrey, green, lavender, lightGrey, lightSand, marygold, orange, red, sand, sienna, ultramarine, verdigris, wave, white, current |
disabled | boolean | false | When true, disables the switch and prevents interaction |
className | string | undefined | Custom CSS classes applied to the button element |
The component also supports all standard button attributes via ComponentPropsWithoutRef<'button'>.
Notes
- Button-based component: The Switch is implemented as a
<button>element withrole="switch"for proper accessibility - No label text support: The Switch does not render children. Wrap it in an external container with label text if needed (see Usage example above)
- Controlled component: The
checkedprop determines the switch state - toggle it in youronClickhandler - Disabled state: When disabled, the
onClickhandler is not called, preventing interaction - Background colors:
- Unchecked:
bg-middleGrey - Checked: Uses the
colorprop (e.g.,bg-saffron,bg-green)
- Unchecked:
- Fixed size:
min-w-56(56px min-width) withp-4padding (4px) - size is not customizable - Visual structure: Displays an SVG icon containing:
- White circle (24px diameter)
- Grey center dot (middleGrey, 4px radius)
- Checkmark path (visible in both states)
- Accessibility:
- Uses
role="switch"for proper ARIA semantics - Sets
aria-checkedattribute to indicate state to assistive technologies - Supports keyboard navigation (space/enter to activate)
- Uses
- Data attributes: Sets
data-name="Switch"for testing and debugging - Client component: Requires
'use client'directive when used in React Server Components