bookmark
An animated bookmark icon for React that draws an outlined bookmark ribbon as SVG and plays a squash-and-stretch wobble on hover. It can also be controlled imperatively through a ref with startAnimation and stopAnimation.
shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @heroicons-animated in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { BookmarkIcon } from "@/components/ui/bookmark";export default function Example() { return <BookmarkIcon className="text-foreground" size={28} />;}- Marking or saving an item, such as a bookmark, favorite, or read-later toggle in a list, article, or card
- Adding a lively hover affordance to a bookmark or save button without writing custom keyframes
- Triggering the wobble programmatically, for example after a successful save, by calling the ref handle
- Showing a playful, animated save or bookmark indicator in a navigation bar or toolbar
Examples
Basic hover animation
Hovering the icon plays the wobble automatically. No ref or handlers are needed.
import { BookmarkIcon } from "@/components/ui/bookmark";export default function BasicExample() { return ( <div className="flex items-center gap-4 text-zinc-900"> <BookmarkIcon size={32} /> </div> );}Save toggle button
A button wrapper that tints the icon when saved, using the className prop to set the color.
import { useState } from "react";import { BookmarkIcon } from "@/components/ui/bookmark";export default function SaveButton() { const [saved, setSaved] = useState(false); return ( <button type="button" aria-pressed={saved} aria-label={saved ? "Remove bookmark" : "Add bookmark"} onClick={() => setSaved((prev) => !prev)} className="inline-flex items-center justify-center rounded-md p-2" > <BookmarkIcon className={saved ? "text-amber-500" : "text-zinc-500"} /> </button> );}Imperative control through ref
Attaching the ref switches the component to controlled mode, so hover no longer animates automatically. Call startAnimation or stopAnimation from code instead.
import { useRef } from "react";import { BookmarkIcon, type BookmarkIconHandle } from "@/components/ui/bookmark";export default function ControlledExample() { const iconRef = useRef<BookmarkIconHandle>(null); return ( <div className="flex flex-col items-start gap-3"> <BookmarkIcon ref={iconRef} /> <div className="flex gap-2"> <button type="button" onClick={() => iconRef.current?.startAnimation()}> Play </button> <button type="button" onClick={() => iconRef.current?.stopAnimation()}> Reset </button> </div> </div> );}Animate on save success
Plays the wobble after an async save resolves, giving feedback without any hover.
import { useRef } from "react";import { BookmarkIcon, type BookmarkIconHandle } from "@/components/ui/bookmark";export default function SaveFeedback({ onSave }: { onSave: () => Promise<void> }) { const iconRef = useRef<BookmarkIconHandle>(null); async function handleClick() { await onSave(); iconRef.current?.startAnimation(); } return ( <button type="button" onClick={handleClick} aria-label="Save"> <BookmarkIcon ref={iconRef} /> </button> );}API reference
Accessibility
- The SVG has no title or aria-label, so it is decorative by default. When the icon is the only content of a control, put aria-label on the button or link, for example aria-label="Add bookmark".
- Reflect the state of a toggle with aria-pressed on the wrapping button instead of relying on the color change alone.
- The animation is a short transform. For users with prefers-reduced-motion, consider disabling the hover animation by using controlled mode and calling startAnimation only when motion is allowed.
- Because the outer element is a div with mouse handlers, place the icon inside a native button or link for keyboard and focus support. The div is not focusable by itself.
- Keep sufficient color contrast for the icon against its background, since the stroke uses currentColor.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "bookmark" component (heroicons-animated/bookmark) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/bookmark2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: size, className, onMouseEnter, onMouseLeave, ref, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { BookmarkIcon } from "@/components/ui/bookmark";export default function Example() { return <BookmarkIcon className="text-foreground" size={28} />;}```Files & dependencies
- bookmark.tsx