Components
Icon Toggle
A toggle button whose icon fills when on.
<IconToggle label="Like" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/icon-toggle.jsonimport { IconToggle } from "@/components/icon-toggle"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A toggle button whose icon fills and pops when it's on. It uses aria-pressed, so give it a label like "Like" or "Save".
import { IconToggle } from "@/components/icon-toggle";
export function LikeButton() {
return <IconToggle label="Like" onChange={(on) => console.log(on)} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | Accessible name. | |
icon | "heart" | "bookmark" | "star" | "heart" | Which icon. |
defaultPressed | boolean | false | Starting state. |
onChange | (pressed: boolean) => void | Called when it flips. | |
color | string | "#e11d48" | Fill colour when on. |
className | string | Classes for the wrapper. |
With reduced motion, the icon fills without popping.