Components
- Accordion
- Add to Cart
- Animated List
- Carousel
- Collapsible Sidebarnew
- Dynamic Island
- Expandable Cardnew
- Expanding Searchnew
- Filter Grid
- Kanban Board
- Layout Switcher
- Morphing Popover
- Number Flip
- Page Transition
- Product Gallery
- Segmented Control
- Sortable Table
- Stack Navigator
- Status Button
- Step Wizard
- Tabs
- Text Morphnew
- Theme Mode Switch
- Theme Morph Button
- Theme Toggle Button
- Theme Toggle Switch
- Theme Transition
- Toast Stacknew
Studio Goods
Subtotal $0
Aurora Lamp
$89
Field Notebook
$24
Ceramic Mug
$32
Installation
$ pnpm dlx shadcn@latest add @transition-kit/add-to-cartUsage
import {
AddToCartButton,
CartButton,
CartProvider,
useCart,
} from "@/components/transitions/add-to-cart";const ProductCard = ({ product }) => {
const imageRef = React.useRef<HTMLImageElement>(null);
return (
<div>
<img ref={imageRef} src={product.image} alt={product.name} />
<AddToCartButton
productId={product.id}
src={product.image}
source={imageRef}
/>
</div>
);
};
<CartProvider>
<CartButton />
<ProductCard product={product} />
</CartProvider>;const { items, count, add, remove, clear } = useCart();API Reference
CartProvider
| Prop | Type | Default | Description |
|---|---|---|---|
items | CartItem[] | - | Controlled cart contents, where CartItem is { id: string; quantity: number }. |
defaultItems | CartItem[] | [] | Initial cart contents when uncontrolled. |
onItemsChange | (items: CartItem[]) => void | - | Called with the new items after each change. |
AddToCartButton
| Prop | Type | Default | Description |
|---|---|---|---|
productId | string | - | Id added to the cart on click. |
quantity | number | 1 | Amount added per click. |
image | ReactNode | - | Custom artwork that flies into the cart; without image or src, the item is added with no flight. |
src | string | - | Image URL used to build the flying <img> when image is not given. |
source | RefObject<HTMLElement | null> | the button | Element the product image flies from. |
children | ReactNode | "Add to cart" | Idle button label. |
addedLabel | ReactNode | "Added" | Label shown after adding. |
resetAfter | number | 1500 | Milliseconds before the label returns to its idle text. |
useCart
| Field | Type | Description |
|---|---|---|
items | CartItem[] | Current cart contents. |
count | number | Total quantity across items. |
add | (id: string, quantity?: number) => void | Adds a quantity of an item; the badge rolls with no flight. |
remove | (id: string) => void | Removes the item with the given id; the badge rolls with no flight. |
clear | () => void | Empties the cart; the badge rolls with no flight. |