Cart
An animated shopping cart SVG icon built with Motion that bounces and scales slightly on hover, and can also be triggered imperatively through a ref. It is a drop-in React component for e-commerce cart buttons and navigation.


shadcn add · no workarounds · theme neutral (none shipped)Installation
Usage
import { CartIcon } from "@/components/ui/cart";export function Example() { return <CartIcon />;}- Adding an animated cart icon to an add-to-cart or checkout button in an e-commerce UI
- Showing a playful hover feedback on a cart link in a site header or navigation bar
- Triggering the cart bounce programmatically, for example after an item is added, via the exposed ref methods
- Replacing a static cart glyph with a lightweight motion-based icon that inherits theme text color
Examples
Hover animation in a header link
Default hover behavior: the icon bounces when the pointer enters and resets when it leaves. Color is controlled through Tailwind text classes.
import { CartIcon } from "@/components/ui/cart";export function HeaderCart() { return ( <a href="/cart" aria-label="Shopping cart" className="inline-flex text-zinc-800 hover:text-indigo-600"> <CartIcon size={24} /> </a> );}Imperative control with a ref
Passing a ref switches the component to controlled mode, so hover no longer animates it. Call startAnimation and stopAnimation from your own logic, such as after adding an item.
import { useRef } from "react";import { CartIcon, type CartIconHandle } from "@/components/ui/cart";export function AddToCartButton() { const cartRef = useRef<CartIconHandle>(null); return ( <button type="button" onClick={() => { cartRef.current?.startAnimation(); setTimeout(() => cartRef.current?.stopAnimation(), 800); }} className="inline-flex items-center gap-2 rounded-md bg-black px-4 py-2 text-white" > <CartIcon ref={cartRef} size={18} /> Add to cart </button> );}Button with custom className and size
Shows a larger icon inside a styled button, with className applied to the outer wrapper div and hover events forwarded to the default animation.
import { CartIcon } from "@/components/ui/cart";export function CartButton() { return ( <button type="button" className="flex items-center gap-3 rounded-full border px-5 py-3 font-medium"> <CartIcon size={32} className="text-emerald-600" /> <span>Cart (3)</span> </button> );}API reference
Accessibility
- The component renders only an SVG with no title or role, so the parent interactive element must provide an accessible name, for example via aria-label on a link or button.
- Mark the decorative icon with aria-hidden="true" when visible text already labels the control, to avoid redundant announcements.
- The animation is a transform on hover only and does not convey information, so it does not need a prefers-reduced-motion fallback, but consider disabling it via your own logic if motion sensitivity is a concern.
- Because the wrapper is a div with mouse handlers, keyboard users do not trigger the hover bounce; use startAnimation through a focusable control's handler to give keyboard feedback.
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 "Cart" component (lucide-animated/cart) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/cart.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, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CartIcon } from "@/components/ui/cart";export function Example() { return <CartIcon />;}```Files & dependencies
- cart.tsx