Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- EmptyNew
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input GroupNew
- KbdNew
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- SkeletonNew
- Slider
- SpinnerNew
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Resources
Toggle
A two-state button that can be on or off.
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return <Toggle>Toggle</Toggle>;
}
Installation
pnpm dlx shadcn@latest add @coss/toggle
Usage
import { Toggle } from "@/components/ui/toggle"<Toggle>Toggle</Toggle>Examples
Outline
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return <Toggle variant="outline">Outline Toggle</Toggle>;
}
With Icon
import { BoldIcon } from "lucide-react";
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return (
<Toggle aria-label="Toggle bold" variant="outline">
<BoldIcon />
</Toggle>
);
}
Small Size
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return (
<Toggle size="sm" variant="outline">
Small
</Toggle>
);
}
Large Size
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return (
<Toggle size="lg" variant="outline">
Large
</Toggle>
);
}
Disabled
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return (
<Toggle disabled variant="outline">
Disabled
</Toggle>
);
}
Icon Group
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle } from "@/components/ui/toggle";
export default function Particle() {
return (
<div className="flex items-center gap-1">
<Toggle aria-label="Toggle bold" variant="outline">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" variant="outline">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" variant="outline">
<UnderlineIcon />
</Toggle>
</div>
);
}
Comparing with Radix / shadcn
If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with coss ui quickly.
Quick Checklist
- If you used
asChildon parts, switch to therenderprop
Additional Notes
Size Comparison
coss ui toggle sizes are more compact compared to shadcn/ui, making them better suited for dense applications:
| Size | Height (shadcn/ui) | Height (coss ui) |
|---|---|---|
sm | 32px | 28px |
default | 36px | 32px |
lg | - | 36px |
So, for example, if you were using the default size in shadcn/ui and you want to preserve the original height, you should use the lg size in coss ui.