Updated
Stepper Button
Customize
Max9
Solid
Medium
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/stepper-button.jsonInstall the packages
npm install @number-flow/react @tabler/icons-react motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/stepper-button/stepper-button.tsx"use client"; import NumberFlow from "@number-flow/react"; import { IconMinus, IconPlus, IconTrash } from "@tabler/icons-react"; import { AnimatePresence, motion } from "motion/react"; import { useEffect, useRef, useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 12, font: 13, icon: 14, count: 20 }, md: { height: 40, padX: 15, font: 14, icon: 16, count: 24 }, lg: { height: 48, padX: 18, font: 15, icon: 18, count: 28 }, } as const; // `pill` is the shape's own look; `press` is the hover wash on the buttons // inside it, which has to read against that look. const VARIANTS = { solid: { pill: "bg-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900", press: "hover:bg-white/10 focus-visible:bg-white/15 dark:hover:bg-black/5 dark:focus-visible:bg-black/10", },
Adds the files to
components/uibrik/stepper-button and installs @number-flow/react, @tabler/icons-react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/stepper-button.Usage
import { StepperButton } from "@/components/uibrik/stepper-button/stepper-button";<StepperButton label="Add to cart" max={9} variant="solid" size="md" trashAtOne radius={12} defaultValue={0} onChange={(quantity) => {}}/>Where to use Stepper Button
Add to cart
An add button reshaping into a quantity stepper in the same pill saves space.
Pairs with Cart Flight
Grocery and food apps
Adjusting quantity right on the product card speeds up ordering.
Ticket quantities
The same pill works for seats and tickets.
Props
StepperButton- label
- Type string
- "Add to cart"
- Button text.
- max
- Type number
- 9
- Highest quantity allowed.
- variant
- Type "solid" | "soft" | "outline"
- "solid"
- Primary, or a quieter look.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- trashAtOne
- Type boolean
- true
- At one, show a trash icon in place of minus, since the next tap removes it.
- radius
- Type number
- 12
- Corner radius.
- defaultValue
- Type number
- 0
- Starting quantity. 0 shows the add button.
- onChange
- Type (quantity: number) => void
- –
- Called with the new quantity after each change.
- className
- Type string
- –
- Classes for the wrapper.