Components / Data
Slot Counter
A number whose digits roll into place like a slot machine.
48,213
GitHub stars
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/slot-counter.tsx. - 3
Use it
example.tsx"use client"; import { useState } from "react"; import { SlotCounter } from "@/components/ui/slot-counter"; export default function SlotCounterDemo() { const [value, setValue] = useState(48213); return ( <div className="flex flex-col items-center gap-5"> <div className="text-center"> <SlotCounter value={value} className="text-5xl font-semibold text-zinc-900 dark:text-white" /> <p className="mt-2 text-sm text-zinc-500">GitHub stars</p> </div> <div className="flex gap-2"> {[ ["+1", () => setValue((v) => v + 1)], ["+1,000", () => setValue((v) => v + 1000)], ["Random", () => setValue(Math.floor(Math.random() * 999999))], ].map(([label, run]) => ( <button key={label as string} type="button" onClick={run as () => void} className="rounded-lg border border-zinc-200 bg-white px-3 py-1.5 text-sm text-zinc-700 transition hover:bg-zinc-100 dark:border-white/10 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800" > {label as string} </button> ))} </div> </div> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | — | The number to show. Digits roll when it changes. |
| locale | string | "en-US" | Formatting locale for separators. |