Quantity Input
An e-commerce stepper: decrement and increment buttons around a number input, as one bordered control. Every committed value is clamped to [min, max] — the buttons stop and disable at the bounds, typing is clamped on commit, and an empty entry snaps back. The piece wraps the @magic-spells/quantity-input web component rather than reimplementing it.
Current: 1
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece quantity-input
It has one runtime dependency — the web component it wraps:
npm install @magic-spells/quantity-input
There is no stylesheet to merge. The component needs no CSS of its own, and its optional sheet ships hex colors and fixed control sizing — this piece styles itself with the pieces.css tokens instead (see Introduction).
Usage
import QuantityInput from '@/components/ui/QuantityInput.pzl';
<QuantityInput value={ qty } min={ 1 } max={ 10 } @change={ setQty } />Bounds
2–6 · Current: 2
Zero minimum
In cart: 1
Step
Steps of 5 · Current: 10
Disabled
Both buttons and the field are inert
Behavior
- Controlled — the parent owns
valueand stores what@changereports; the callback is value-first - Zero is a real value —
min={ 0 }reaches 0 instead of bottoming out at 1, which is what a cart row's "remove" state needs - Enter commits, it does not submit — the component preventDefaults the key and commits the typed value, so a stepper inside a form never navigates the page
- Empty or junk snaps back — clearing the field and blurring restores the committed value rather than leaving a dirty input
- Disabled is owned by the component — host
disableddisables all three controls, and each button is additionally disabled at its bound, recomputed on every change