Skip to content
All blocks

[37] E-commerce

Shopping Cart

Cart items with quantity and remove, beside an order summary with a promo code and the checkout button.

1280px

Copy the code

One file with one component and its sample data. It needs @vaneui/ui and its stylesheet, set up as in the installation guide.

cart.tsx

import type { ReactNode } from "react";
import { Button, Card, Col, Container, Divider, IconButton, Input, PageTitle, Row, Section, Select, Text, Title } from "@vaneui/ui";
function Shot({ children }: { children: ReactNode }) {
return (
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
{children}
</svg>
);
}
function TrashIcon() {
return (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3" />
</svg>
);
}
const items: { name: string; options: string; price: string; qty: number; tone: object; shot: ReactNode }[] = [
{ name: "Everyday tee", options: "Sand, M", price: "$64.00", qty: 2, tone: { warning: true },
shot: <Shot><path d="M8 3 3 6l2 5 3-1v11h8V10l3 1 2-5-5-3a4 4 0 0 1-8 0z" /></Shot> },
{ name: "Stoneware mug", options: "Sage, 350 ml", price: "$18.00", qty: 1, tone: { success: true },
shot: <Shot><path d="M5 8h12v6a5 5 0 0 1-5 5h-2a5 5 0 0 1-5-5zM17 10h1.5a2.5 2.5 0 0 1 0 5H17M8 3v2M12 3v2" /></Shot> },
{ name: "Gift box", options: "Kraft", price: "$6.00", qty: 1, tone: { info: true },
shot: <Shot><path d="m12 3 8 4.5v9L12 21l-8-4.5v-9z" /><path d="m4 7.5 8 4.5 8-4.5M12 12v9" /></Shot> },
];
const lines = [["Subtotal", "$88.00"], ["Shipping", "Free"], ["Tax", "$7.04"]];
export function Cart() {
return (
<Section>
<Container itemsStretch>
<Col lg>
<PageTitle>Shopping cart</PageTitle>
<Row tabletStack itemsStart xl>
<Col tag="ul" flex1 noGap wFull aria-label="Items in your cart">
{items.map((it, i) => (
<Row key={it.name} tag="li" itemsStart paddingY borderT={i > 0}>
<Card {...it.tone} noPadding itemsCenter justifyCenter aspectSquare noShrink className="w-24" aria-hidden="true">
{it.shot}
</Card>
<Col xs flex1 className="min-w-0">
<Row justifyBetween itemsStart>
<Col noGap>
<Title tag="h2" sm>{it.name}</Title>
<Text sm secondary>{it.options}</Text>
</Col>
<Text fontSemibold className="tabular-nums">{it.price}</Text>
</Row>
<Row sm>
<Select aria-label={`Quantity of ${it.name}`} defaultValue={String(it.qty)} wFit>
{[1, 2, 3, 4, 5].map((n) => <option key={n} value={n}>Qty {n}</option>)}
</Select>
<IconButton ghost secondary aria-label={`Remove ${it.name}`}><TrashIcon /></IconButton>
</Row>
</Col>
</Row>
))}
</Col>
<Card tabletWFull className="w-96">
<Title tag="h2">Order summary</Title>
<Col sm>
{lines.map(([label, value]) => (
<Row key={label} justifyBetween>
<Text sm secondary>{label}</Text>
<Text sm className="tabular-nums">{value}</Text>
</Row>
))}
</Col>
<Input aria-label="Promo code" placeholder="Promo code" endSection={<Button type="button" ghost>Apply</Button>} />
<Divider />
<Row justifyBetween>
<Text fontSemibold>Total</Text>
<Text fontBold className="tabular-nums">$95.04</Text>
</Row>
<Button href="/checkout" filled md wFull>Check out</Button>
<Text xs tertiary textCenter>Free returns within 30 days.</Text>
</Card>
</Row>
</Col>
</Container>
</Section>
);
}

How it adapts

  • 1024px and up: the items beside a 384px summary card.
  • Below 1024px: the summary moves under the items at full width.
  • Long item names wrap while the price stays on the right.

How these props work is in responsive page sections without breakpoint classes.

Adapt it with your coding agent

Add the VaneUI MCP server, and your agent reads the component docs and prop tables while it changes the block: the copy, the sample data or the layout.

$ claude mcp add vaneui -- npx -y @vaneui/mcp

Setup for other editors is in the AI assistants guide.