AddButton

Add + that opens into a stepper in place. The plus never moves, so a second tap lands where the first did. At one the minus becomes a bin; hold to repeat. Buttons.

Open playground
Quantity of Croissant2 Croissant in cart

Hold + or − to repeat. Push past the limit.

About

AddButton is a React component in the Buttons category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { AddButton } from "@ashutoshswamy/smoui" and set quantity, max, name among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { AddButton } from "@ashutoshswamy/smoui";

<AddButton name="Oat milk" max={6} onQuantityChange={(n) => console.log(n)} />

Props 5

quantity / defaultQuantity

Controlled or starting amount. 0 shows Add.

number
max

Most one order can hold. Past it the count shakes and a note appears. Default 9.

number
name

Used in the labels screen readers hear.

string
label

Closed-state text. Default Add.

string
onQuantityChange

Fires on every change.

(quantity: number) => void