Skip to Content
zjkm-ui
Components

Icon Toggle

A toggle button whose icon fills when on.

Props
<IconToggle label="Like" />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/icon-toggle.json
import { 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

PropTypeDefaultDescription
labelstringAccessible name.
icon"heart" | "bookmark" | "star""heart"Which icon.
defaultPressedbooleanfalseStarting state.
onChange(pressed: boolean) => voidCalled when it flips.
colorstring"#e11d48"Fill colour when on.
classNamestringClasses for the wrapper.

With reduced motion, the icon fills without popping.

On this page