Skip to content
All blocks

[38] E-commerce

Checkout

Contact, address, delivery options as radio cards and payment fields, beside an order summary that updates.

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. It passes an onSubmit handler, so in the Next.js App Router add "use client" at the top of its file.

checkout.tsx

import { useState } from "react";
import { Button, Card, Col, Container, Divider, Field, Grid2, PageTitle, Radio, RadioGroup, Row, Section, Text,
Title } from "@vaneui/ui";
const deliveries = [
{ value: "standard", label: "Standard", time: "3 to 5 business days", price: "Free" },
{ value: "express", label: "Express", time: "1 to 2 business days", price: "$12.00" },
{ value: "pickup", label: "Pick up in store", time: "Ready tomorrow", price: "Free" },
];
const items = [
{ name: "Everyday tee", detail: "Sand, M, 2 pcs", price: "$64.00" },
{ name: "Stoneware mug", detail: "Sage, 350 ml", price: "$18.00" },
{ name: "Gift box", detail: "Kraft", price: "$6.00" },
];
export function Checkout() {
const [delivery, setDelivery] = useState("standard");
const shipping = delivery === "express" ? 12 : 0;
const total = (88 + 7.04 + shipping).toFixed(2);
return (
<Section>
<Container itemsStretch>
<Col lg>
<PageTitle>Checkout</PageTitle>
<Row tabletStack itemsStart xl>
<Col tag="form" xl flex1 wFull className="min-w-0" onSubmit={(e) => e.preventDefault()}>
<Col>
<Title tag="h2">Contact</Title>
<Field type="email" label="Email" name="email" autoComplete="email" description="We send the receipt and tracking here." required />
</Col>
<Col>
<Title tag="h2">Shipping address</Title>
<Grid2>
<Field type="text" label="First name" name="firstName" autoComplete="given-name" required />
<Field type="text" label="Last name" name="lastName" autoComplete="family-name" required />
</Grid2>
<Field type="text" label="Address" name="address" autoComplete="street-address" required />
<Grid2>
<Field type="text" label="City" name="city" autoComplete="address-level2" required />
<Field type="text" label="Postal code" name="postalCode" autoComplete="postal-code" required />
</Grid2>
<Field select label="Country" name="country" defaultValue="DE" autoComplete="country">
<option value="DE">Germany</option>
<option value="FR">France</option>
<option value="NL">Netherlands</option>
<option value="ES">Spain</option>
</Field>
</Col>
<Col>
<Title tag="h2" id="delivery-label">Delivery</Title>
<RadioGroup name="delivery" value={delivery} onChange={(e) => setDelivery(e.target.value)} aria-labelledby="delivery-label" sm>
{deliveries.map((d) => (
<Card key={d.value} tag="label" sm row justifyBetween itemsCenter cursorPointer strongBorder={d.value === delivery}>
<Row sm>
<Radio value={d.value} />
<Col noGap>
<Text sm fontMedium>{d.label}</Text>
<Text xs secondary>{d.time}</Text>
</Col>
</Row>
<Text sm fontMedium className="tabular-nums">{d.price}</Text>
</Card>
))}
</RadioGroup>
</Col>
<Col>
<Title tag="h2">Payment</Title>
<Field type="text" label="Card number" name="cardNumber" inputMode="numeric" autoComplete="cc-number" placeholder="1234 1234 1234 1234" required />
<Grid2>
<Field type="text" label="Expiry date" name="expiry" autoComplete="cc-exp" placeholder="MM / YY" required />
<Field type="text" label="Security code" name="cvc" inputMode="numeric" autoComplete="cc-csc" placeholder="CVC" required />
</Grid2>
</Col>
<Button type="submit" filled md wFull>Pay ${total}</Button>
</Col>
<Card tabletWFull sticky className="w-96">
<Title tag="h2">Order summary</Title>
<Col>
{items.map((it) => (
<Row key={it.name} justifyBetween itemsStart>
<Col noGap>
<Text sm fontMedium>{it.name}</Text>
<Text xs secondary>{it.detail}</Text>
</Col>
<Text sm className="tabular-nums">{it.price}</Text>
</Row>
))}
</Col>
<Divider />
<Col sm>
{[["Subtotal", "$88.00"], ["Shipping", shipping ? `$${shipping.toFixed(2)}` : "Free"], ["Tax", "$7.04"]].map(([label, value]) => (
<Row key={label} justifyBetween>
<Text sm secondary>{label}</Text>
<Text sm className="tabular-nums">{value}</Text>
</Row>
))}
</Col>
<Divider />
<Row justifyBetween>
<Text fontSemibold>Total</Text>
<Text fontBold className="tabular-nums">${total}</Text>
</Row>
</Card>
</Row>
</Col>
</Container>
</Section>
);
}

How it adapts

  • 1024px and up: the form beside a 384px summary that stays in view while the form scrolls.
  • Below 1024px: the summary moves under the form.
  • Below 768px: paired fields stack. Picking Express adds its price to the summary and the pay button.

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.