About
A slide-in shopping cart with a count badge, free-shipping progress bar, quantity steppers, remove with Undo, subtotal and Checkout. Traps focus, closes on Esc or backdrop click, and locks page scroll while open.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Cart Drawer to your project and fits it to your theme.
Code
How Cart Drawer is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
// This is a file with a demo for your component
// That's what users will see in the preview
// Create new files in this directory to add more demos
"use client";
import * as React from "react";
import { Layers, Plus } from "lucide-react";
import { Component, type CartItem } from "@/components/ui/cart-drawer";
const START: CartItem[] = [
{ id: "tee", name: "Everyday Heavyweight Tee", variant: "Signal / M", price: 38, quantity: 1 },
{ id: "tote", name: "Waxed Canvas Tote", variant: "Natural", price: 24, quantity: 1 },
{ id: "mug", name: "Stoneware Mug", variant: "Set of 2", price: 16, quantity: 1 },
];
export default function DemoOne() {
const [items, setItems] = React.useState<CartItem[]>(START);
const [message, setMessage] = React.useState("");
// Adds a product from outside the drawer, the way a product page would
const addHoodie = () => {
setItems((current) => {
const existing = current.find((i) => i.id === "hoodie");
if (existing) return current.map((i) => (i.id === "hoodie" ? { ...i, quantity: Math.min(10, i.quantity + 1) } : i));
return [...current, { id: "hoodie", name: "Fleece Zip Hoodie", variant: "Stone / L", price: 72, quantity: 1 }];
});
};
return (
<div className="flex min-h-[560px] w-full flex-col bg-background text-foreground">
<header className="flex h-16 items-center justify-between border-b border-border bg-card px-4 sm:px-8">
<div className="flex items-center gap-2.5">
<span className="grid size-8 place-items-center rounded-lg bg-primary text-primary-foreground">
<Layers className="size-4" aria-hidden="true" />
</span>
<span className="text-sm font-semibold">Northwind Shop</span>
</div>
<Component items={items} onChange={setItems} onCheckout={(list) => setMessage("Checkout started with " + list.reduce((n, i) => n + i.quantity, 0) + " items")} />
</header>
<main className="flex flex-1 flex-col items-center justify-center gap-4 px-4 py-12">
<button
type="button"
onClick={addHoodie}
className="inline-flex h-11 items-center gap-2 rounded-xl border border-border bg-card px-5 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<Plus className="size-4" aria-hidden="true" />
Add a Fleece Zip Hoodie
</button>
<p className="h-5 text-sm text-muted-foreground" role="status">
{message || "Open the cart from the top right."}
</p>
</main>
</div>
);
}








