Skip to main content
Tactile Counter

Tactile Counter

Spring-animated stepper with pop-layout numerals.

Motion
14/16
142

1. Install Dependencies

$npm install framer-motion lucide-react

2. Copy Component Code

components/ui/TactileCounter.tsx
1"use client";
2
3import React, { useState } from "react";
4import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
5import { Minus, Plus } from "lucide-react";
6
7interface TactileCounterProps {
8 initialCount?: number;
9}
10
11export function TactileCounter({ initialCount = 142 }: TactileCounterProps) {
12 const [count, setCount] = useState(initialCount);
13 const prefersReducedMotion = useReducedMotion();
14
15 return (
16 <div className="flex items-center gap-3">
17 <motion.button
18 type="button"
19 onClick={() => setCount((c) => Math.max(0, c - 1))}
20 whileTap={prefersReducedMotion ? undefined : { scale: 0.92 }}
21 aria-label="Decrement counter"
22 className="inline-flex h-11 w-11 items-center justify-center rounded-full border border-black/[0.1] bg-white text-black hover:border-black/25 dark:border-white/[0.12] dark:bg-[#0A0A0A] dark:text-white dark:hover:border-white/25"
23 >
24 <Minus className="h-4 w-4" aria-hidden="true" />
25 </motion.button>
26
27 <div className="relative flex h-12 min-w-[88px] items-center justify-center overflow-hidden rounded-xl border border-black/[0.08] bg-white px-4 dark:border-white/[0.1] dark:bg-black">
28 <AnimatePresence mode="popLayout" initial={false}>
29 <motion.span
30 key={count}
31 initial={prefersReducedMotion ? false : { y: 18, opacity: 0 }}
32 animate={{ y: 0, opacity: 1 }}
33 exit={prefersReducedMotion ? undefined : { y: -18, opacity: 0 }}
34 transition={
35 prefersReducedMotion
36 ? { duration: 0 }
37 : { type: "spring", stiffness: 380, damping: 26 }
38 }
39 className="font-mono text-2xl font-semibold tabular-nums text-black dark:text-white"
40 >
41 {count}
42 </motion.span>
43 </AnimatePresence>
44 </div>
45
46 <motion.button
47 type="button"
48 onClick={() => setCount((c) => c + 1)}
49 whileTap={prefersReducedMotion ? undefined : { scale: 0.92 }}
50 aria-label="Increment counter"
51 className="inline-flex h-11 w-11 items-center justify-center rounded-full border border-emerald-500/35 bg-emerald-500/10 text-emerald-700 transition-colors hover:border-emerald-500/60 hover:bg-emerald-500/15 dark:text-emerald-400"
52 >
53 <Plus className="h-4 w-4" aria-hidden="true" />
54 </motion.button>
55 </div>
56 );
57}

Usage Example

import { TactileCounter } from "@/components/ui/TactileCounter";
export default function QuantityControl() {
return <TactileCounter initialCount={142} />;
}

3. Props Reference

Tactile Counter props API reference
PropTypeDefaultDescription
initialCountnumber142Starting numerical value for the stepper.