Bookmark X
BookmarkX is an animated bookmark icon built with motion/react. On hover, the bookmark shape squashes and stretches, and an X mark draws itself inside it, then it returns to its normal state on mouse leave.


shadcn add · no workarounds · theme neutral (none shipped)Installation
Usage
import { BookmarkXIcon } from "@/components/ui/bookmark-x";export function Example() { return <BookmarkXIcon className="text-foreground" />;}- Bookmark, save, or favorite toggles where a playful confirmation micro-interaction is wanted
- Remove, dismiss, or clear-bookmark affordances that should visually signal deletion with an X
- Hover-driven icon feedback inside cards, lists, or toolbars
- Imperatively triggered animations (e.g. after a save action succeeds) via a ref
Examples
Basic hover icon
Hovering the icon plays the bookmark squash and X draw animation. Color is set via className using currentColor.
import { BookmarkXIcon } from "@/components/ui/bookmark-x";export default function BasicExample() { return ( <div className="flex items-center gap-4 text-neutral-900"> <BookmarkXIcon size={28} /> </div> );}Imperative control via ref
Attaching a ref switches the icon to controlled mode: hover no longer animates it automatically, and startAnimation or stopAnimation are called from code.
import { useRef } from "react";import { BookmarkXIcon, type BookmarkXIconHandle } from "@/components/ui/bookmark-x";export default function ControlledExample() { const iconRef = useRef<BookmarkXIconHandle>(null); return ( <div className="flex items-center gap-3"> <BookmarkXIcon ref={iconRef} size={32} className="text-blue-600" /> <button type="button" onClick={() => iconRef.current?.startAnimation()} className="rounded-md border px-3 py-1 text-sm"> Play </button> <button type="button" onClick={() => iconRef.current?.stopAnimation()} className="rounded-md border px-3 py-1 text-sm"> Reset </button> </div> );}Clickable remove-bookmark button
Wrap the icon in an accessible button, with the label provided by aria-label, and trigger the animation on click using the ref.
import { useRef, useState } from "react";import { BookmarkXIcon, type BookmarkXIconHandle } from "@/components/ui/bookmark-x";export default function RemoveBookmarkExample() { const iconRef = useRef<BookmarkXIconHandle>(null); const [saved, setSaved] = useState(true); const handleClick = () => { iconRef.current?.startAnimation(); setSaved(false); }; return ( <button type="button" aria-label={saved ? "Remove bookmark" : "Bookmark removed"} onClick={handleClick} disabled={!saved} className="rounded-full p-2 text-amber-500 hover:bg-amber-50 disabled:opacity-50" > <BookmarkXIcon ref={iconRef} size={22} /> </button> );}API reference
Accessibility
- The icon is decorative by default: the svg has no title or role, so screen readers may announce nothing. Provide meaning through the surrounding control, for example a button with aria-label such as "Remove bookmark".
- When used as a standalone interactive control, make it a button or link (or give the wrapper role="button", tabIndex={0}, and Enter/Space key handling). The component itself is a non-focusable div.
- Animation is purely visual and does not convey state by itself. Do not rely on the motion alone to communicate that a bookmark was removed; update text or aria-live status as well.
- Respect reduced motion preferences: wrap triggers with a prefers-reduced-motion check or skip startAnimation when the user prefers reduced motion.
- Stroke uses currentColor, so keep sufficient contrast against the background (WCAG 3:1 for non-text graphical objects).
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 X" component (lucide-animated/bookmark-x) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/bookmark-x.json2. 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, ...props (HTMLAttributes<HTMLDivElement>).Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { BookmarkXIcon } from "@/components/ui/bookmark-x";export function Example() { return <BookmarkXIcon className="text-foreground" />;}```Files & dependencies
- bookmark-x.tsx