Quantity Field
Quantity stepper input: minus and plus buttons around a numeric field that accepts only in-range whole numbers, grouped as one input. Read-only locks the buttons; with a name it submits through a hidden input in cart and checkout forms.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
Installation
pnpm dlx shadcn@latest add @01orbital/quantity-fieldnpx shadcn@latest add @01orbital/quantity-fieldyarn dlx shadcn@latest add @01orbital/quantity-fieldbunx --bun shadcn@latest add @01orbital/quantity-fieldUsage
"use client"
import { useState } from "react"
import { QuantityField } from "@/components/store/quantity-field"
// The copy: change text here, not in the markup.
const COPY = {
name: "Ink Rings",
detail: "A2, 42 × 59 cm",
left: "left",
decrease: "Decrease quantity",
increase: "Increase quantity",
quantity: "Quantity",
} as const
// Knobs: the print's price in dollars and how many are in stock.
const PRICE = 72
const STOCK = 5
const IMAGE = {
url: "https://01orbital.dev/art/kit/thomas-v2-596378.png",
alt: "Print of concentric rings of heavy black dashes on white.",
}
const MONEY = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0,
})
// One cart line: the stepper stops at the stock left, and the line total
// follows the quantity.
export default function QuantityFieldDemo() {
const [quantity, setQuantity] = useState(1)
return (
<div className="flex w-full max-w-md items-center gap-4 p-6">
<img
src={IMAGE.url}
alt={IMAGE.alt}
className="aspect-4/5 w-16 shrink-0 bg-muted object-cover"
/>
<div className="grid min-w-0 flex-1 gap-0.5">
<p className="text-sm/5 font-medium">{COPY.name}</p>
<p className="text-sm/5 text-muted-foreground">{COPY.detail}</p>
<p className="text-sm/5 text-muted-foreground tabular-nums">
{MONEY.format(PRICE)} · {STOCK} {COPY.left}
</p>
</div>
<div className="grid justify-items-end gap-2">
<QuantityField
aria-label={COPY.quantity}
value={quantity}
onValueChange={setQuantity}
max={STOCK}
decrementLabel={COPY.decrease}
incrementLabel={COPY.increase}
/>
<p aria-live="polite" className="text-sm/5 tabular-nums">
{MONEY.format(PRICE * quantity)}
</p>
</div>
</div>
)
}This example installs with everything it uses:
pnpm dlx shadcn@latest add @01orbital/quantity-field-demonpx shadcn@latest add @01orbital/quantity-field-demoyarn dlx shadcn@latest add @01orbital/quantity-field-demobunx --bun shadcn@latest add @01orbital/quantity-field-demoAPI reference
A stepper, never a select: minus, a typed number, plus. Typing keeps a draft; only an in-range number is applied, and leaving the field or pressing Enter restores it. With a name, a form submits the applied quantity, never the draft.
Prop
Type
It also accepts the HTML attributes of the element it renders.
Dependencies
npm: @phosphor-icons/react, cn. The CLI installs them for you.
Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Used in blocks
5 blocks are built with Quantity Field:
Cart Page with Order Summary
Limited Edition Orb Product Page
Product Page with Image Grid
Product Page with Thumbnail Gallery
Slide-Over Cart Drawer
Last updated on