Clip camera
$279
CartList and CartLine (photo, name, line total, quantity, remove) and OrderSummary (rows, a total screen readers hear change, your checkout action), usually in a Drawer. UI only: state, totals, payment and delivery stay in your app. To open the cart on add, call `show()` from `useDisclosure()` in ProductCard's `onAddToCart`, or show a toast instead.
$279
$129.99
"use client";import { useState } from "react";import { CartLine, CartList, OrderSummary } from "@/components/blocks/cart";import { ProductCard } from "@/components/blocks/product-card";import { Button } from "@/components/ui/button";import { Drawer, DrawerBody, DrawerContent, DrawerFooter, DrawerHeader, DrawerTitle,} from "@/components/ui/drawer";import { useDisclosure } from "@/lib/use-disclosure";type Product = { id: string; name: string; price: number; image: string };export function Shop({ products, onCheckout,}: { products: Product[]; onCheckout: () => void;}) { // One Drawer for the page. Adding opens it; call toast() there instead to stay on the page. const cart = useDisclosure(); const [lines, setLines] = useState<Record<string, number>>({}); const inCart = products.filter((product) => lines[product.id]); const total = inCart.reduce( (sum, product) => sum + product.price * (lines[product.id] ?? 0), 0, ); const setQuantity = (id: string, quantity: number) => setLines((current) => ({ ...current, [id]: quantity })); return ( <> <div className="grid gap-4 sm:grid-cols-3"> {products.map((product) => ( <ProductCard key={product.id} name={product.name} price={product.price} media={[<img key={product.image} src={product.image} alt="" />]} onAddToCart={() => { setQuantity(product.id, (lines[product.id] ?? 0) + 1); cart.show(); }} /> ))} </div> <Drawer {...cart.props}> <DrawerContent> <DrawerHeader> <DrawerTitle>Your cart</DrawerTitle> </DrawerHeader> <DrawerBody> <CartList> {inCart.map((product) => ( <CartLine key={product.id} name={product.name} price={product.price} quantity={lines[product.id]} media={<img src={product.image} alt="" />} onQuantityChange={(quantity) => setQuantity(product.id, quantity) } onRemove={() => setQuantity(product.id, 0)} /> ))} </CartList> </DrawerBody> <DrawerFooter className="border-t"> <OrderSummary className="w-full" lines={[{ label: "Shipping", amount: "Free" }]} total={total} // Payment and delivery plug in here: your app owns them. action={ <Button className="w-full" onClick={onCheckout}> Checkout </Button> } /> </DrawerFooter> </DrawerContent> </Drawer> </> );}The list of CartLines.
Also accepts every <ul> prop (none of its own).
One product in the cart: photo, name, line total, quantity field and remove button.
name requiredstringprice requirednumbercurrencystringdetailsReactNodehrefstringlocalestringmaxnumbermediaReactNode<img>).onQuantityChange(quantity: number) => voidonRemove() => voidquantityDefault 1numberonQuantityChange it shows as text, when above 1.quantityLabelDefault "Quantity of"stringremoveLabelDefault "Remove"string| Prop | Type | Default |
|---|---|---|
name requiredProduct name. | string | — |
price requiredPrice of one item in major units; the line shows price × quantity. | number | — |
currencyISO 4217 code for the price. | string | — |
detailsMuted line under the name, e.g. "Size M, black". | ReactNode | — |
hrefProduct page link for the name. | string | — |
localeBCP 47 locale for number formatting. | string | — |
maxHighest quantity, e.g. what is in stock. | number | — |
mediaSquare photo ( <img>). | ReactNode | — |
onQuantityChangeShows the quantity field; called with the new quantity, at least 1. | (quantity: number) => void | — |
onRemoveShows the remove button; called when it is pressed. Focus moves to the next line once this one is gone. | () => void | — |
quantityHow many. Without onQuantityChange it shows as text, when above 1. | number | 1 |
quantityLabelNames the quantity field, before the product name. | string | "Quantity of" |
removeLabelNames the remove button, before the product name. | string | "Remove" |
required
Also accepts every <li> prop.
Subtotal, shipping and the total as a description list. It adds nothing up: the numbers are yours.
total requirednumberactionReactNodecurrencystringlinesDefault []OrderSummaryLine[]localestringnoteReactNodetotalLabelDefault "Total"string| Prop | Type | Default |
|---|---|---|
total requiredWhat to pay. Your app computes it, and screen readers hear it change. | number | — |
actionUnder everything, e.g. a checkout Button. | ReactNode | — |
currencyISO 4217 code for the amounts. | string | — |
linesRows above the total, in order. | OrderSummaryLine[] | [] |
localeBCP 47 locale for number formatting. | string | — |
noteSmall print under the total, e.g. "Taxes calculated at checkout". | ReactNode | — |
totalLabelLabel of the total row. | string | "Total" |
required
Also accepts every <div> prop.
Every component also takes className.