HextaUI

Toggle: Filled when on

Add group-data-pressed/toggle:fill-current to an outline icon and it fills in as the toggle turns on.

import { IconBookmark, IconHeart, IconStar } from "@tabler/icons-react"

import { Toggle } from "@/components/ui/toggle"

export function ToggleFilledIcon() {
  return (
    <div className="flex items-center gap-1">
      <Toggle aria-label="Like" defaultPressed>
        <IconHeart className="group-data-pressed/toggle:fill-current" />
      </Toggle>
      <Toggle aria-label="Star">
        <IconStar className="group-data-pressed/toggle:fill-current" />
      </Toggle>
      <Toggle aria-label="Save">
        <IconBookmark className="group-data-pressed/toggle:fill-current" />
      </Toggle>
    </div>
  )
}

This adds the example as components/examples/toggle/filled-icon.tsx, together with the Toggle component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/toggle-filled-icon.json

To add only the component, follow the Toggle installation.

Props in this example

The Toggle props this example sets, from the API reference.

PropTypeDefault
defaultPressed
booleanfalse

Every prop is in the Toggle API reference.

See them all, with keyboard support and accessibility notes, on the Toggle page.