Getting Started
Components
- Accordion
- Advanced Toast
- AlertMessage
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- Carousel
- Chapters
- ChatBody
- ChatButton
- ChatHeader
- ChatInput
- ChatMessageActions
- ChatMessageEditor
- ChatMessage
- ChatTypingIndicator
- ChatWindowCsatPrompt
- ChatWindowQuote
- ChatWindow
- CheckboxSelect
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- ContentReview
- Countdown
- CriteriaDates
- CriteriaParticipants
- CriteriaTransports
- Date Field
- Datepicker
- Dropdown
- ElasticHeight
- ExpandableCard
- ExpandableText
- Filter
- FloatingLabelTextField
- Form Control
- Form Label
- Frame
- HamburgerIcon
- Heading
- Image
- JourneyCard
- LayerHeader
- Layer
- Link
- Loader
- Number Field
- PageNavigation
- Pagination
- Paragraph
- Password
- Phone Field
- Popin
- Portal
- ProductThumbnail
- Promises
- Prose
- Radio Group
- RadioSelect
- Radio
- Range
- Scrollbar
- Select
- SidebarLayout
- SliderFrame
- SparkleWrapper
- Spinner
- Switch
- Table
- Tabs
- Tag
- TextField
- Toggle
- Tooltip
- ValidationMessage
Active: Our selection
'use client';
import { useState } from 'react';
import { Toggle } from '@/ui/Toggle';
export function ToggleDemo() {
const [active, setActive] = useState(0);
const labels = ['Our selection', 'Exclusive Collection', 'Safari'];
return (
<div className="space-y-16">
<Toggle
aria-label="Choose a collection"
items={[
{ color: 'saffron', label: 'Our selection', id: 'id1' },
{ color: 'ultramarine', label: 'Exclusive Collection', id: 'id2' },
{ color: 'sienna', label: 'Safari', id: 'id3' },
]}
index={active}
onClick={setActive}
/>
<p className="text-b3">Active: {labels[active]}</p>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/toggle.json
Usage
import { Toggle } from '@/ui/Toggle';
export function Component() {
const [active, setActive] = useState(0);
return (
<Toggle
index={active}
onClick={setActive}
items={[
{ color: 'saffron', label: 'Our selection', id: 'selection' },
{ color: 'ultramarine', label: 'Exclusive Collection', id: 'exclusive' },
{ color: 'sienna', label: 'Safari', id: 'safari' },
]}
/>
);
}Small size
Use size="small" for a compact variant suited to inline or space-constrained contexts.
Active: Year
'use client';
import { useState } from 'react';
import { Toggle } from '@/ui/Toggle';
export function ToggleSmallDemo() {
const [active, setActive] = useState(0);
const labels = ['Year', 'Month'];
return (
<div className="space-y-16">
<Toggle
aria-label="Choose a period"
size="small"
items={[
{ color: 'saffron', label: 'Year', id: 'id1' },
{ color: 'saffron', label: 'Month', id: 'id2' },
]}
index={active}
onClick={setActive}
/>
<p className="text-b3">Active: {labels[active]}</p>
</div>
);
}
API Reference
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
items | Item[] | [] | Required. Array of items to display as buttons. |
index | number | 0 | The index of the currently active item. |
onClick | (index: number) => void | undefined | Callback fired with the index of the clicked item. |
size | 'default' | 'small' | 'default' | Controls button padding and text size. small uses compact padding for inline use. |
className | string | undefined | Additional CSS classes for the outer container. |
Item
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | — | Required. Unique identifier for the item. |
color | Colors | — | Required. Background color applied when the item is active. |
label | ReactNode | — | Required. The label rendered inside the button. |
className | string | undefined | Additional CSS classes for the button. |
All other standard button HTML attributes are also accepted per item.
Notes
- Renders nothing when
itemsis empty - Each button exposes
aria-pressedfor accessibility - The active pill background transitions smoothly using a CSS custom property
--toggle-color - The
indexprop syncs with an internaluseState, so the component works both controlled and uncontrolled