# Quantity stepper

> Minus and plus buttons around a number that slides up or down each time it changes.

- Category: [Inputs](https://library.aimran.es/components/inputs)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/animated-quantity
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A quantity picker shows up wherever people order things: the cart of an online shop, concert tickets, portions in a food delivery app or rooms in a hotel booking. The sliding number makes each tap visible, so nobody adds three bottles of wine by accident. A quantity stepper sounds boring, but people touch it more than almost anything.

Set a sensible maximum for your case, like your real stock or the most tickets per order. It stops at zero by default; if zero makes no sense, for example in a cart line, start the minimum at one instead.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Minus, Plus } from "lucide-react";

interface AnimatedQuantityProps {
  value?: number;
  defaultValue?: number;
  max?: number;
  onChange?: (value: number) => void;
}

export default function AnimatedQuantity({
  value,
  defaultValue = 2,
  max = 12,
  onChange,
}: AnimatedQuantityProps) {
  const [internal, setInternal] = useState(defaultValue);
  const n = value ?? internal;

  const set = (next: number) => {
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="flex items-center gap-5 rounded-full bg-white p-2 text-[#1d1d1f] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#1c1c1e] dark:text-[#f5f5f7]">
      <button
        type="button"
        aria-label="Decrease"
        onClick={() => set(Math.max(0, n - 1))}
        className="grid h-9 w-9 place-items-center rounded-full bg-black/5 dark:bg-white/10"
      >
        <Minus className="h-4 w-4" />
      </button>
      <AnimatePresence mode="popLayout" initial={false}>
        <motion.strong
          key={n}
          initial={{ y: 12, opacity: 0 }}
          animate={{ y: 0, opacity: 1 }}
          exit={{ y: -12, opacity: 0 }}
          className="w-7 text-center"
        >
          {n}
        </motion.strong>
      </AnimatePresence>
      <button
        type="button"
        aria-label="Add"
        onClick={() => set(Math.min(max, n + 1))}
        className="grid h-9 w-9 place-items-center rounded-full bg-black/5 dark:bg-white/10"
      >
        <Plus className="h-4 w-4" />
      </button>
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Quantity stepper” block (Inputs) from AIMRAN Library to my project.

## What it is
Minus and plus buttons around a number that slides up or down each time it changes.

## Chosen settings
- Initial value: 2 (from 0 to 8)
- Maximum: 12 (from 2 to 20)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Minus, Plus } from "lucide-react";

interface AnimatedQuantityProps {
  value?: number;
  defaultValue?: number;
  max?: number;
  onChange?: (value: number) => void;
}

export default function AnimatedQuantity({
  value,
  defaultValue = 2,
  max = 12,
  onChange,
}: AnimatedQuantityProps) {
  const [internal, setInternal] = useState(defaultValue);
  const n = value ?? internal;

  const set = (next: number) => {
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="flex items-center gap-5 rounded-full bg-white p-2 text-[#1d1d1f] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#1c1c1e] dark:text-[#f5f5f7]">
      <button
        type="button"
        aria-label="Decrease"
        onClick={() => set(Math.max(0, n - 1))}
        className="grid h-9 w-9 place-items-center rounded-full bg-black/5 dark:bg-white/10"
      >
        <Minus className="h-4 w-4" />
      </button>
      <AnimatePresence mode="popLayout" initial={false}>
        <motion.strong
          key={n}
          initial={{ y: 12, opacity: 0 }}
          animate={{ y: 0, opacity: 1 }}
          exit={{ y: -12, opacity: 0 }}
          className="w-7 text-center"
        >
          {n}
        </motion.strong>
      </AnimatePresence>
      <button
        type="button"
        aria-label="Add"
        onClick={() => set(Math.min(max, n + 1))}
        className="grid h-9 w-9 place-items-center rounded-full bg-black/5 dark:bg-white/10"
      >
        <Plus className="h-4 w-4" />
      </button>
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
