Numbers and words spin into their new value like slot-machine reels, with a little motion blur. Good for stats: projects, clients, years.
How to use
Make two files in your project's components folder: number-reels.tsx and number-reels.module.css.
Paste the code into each one, keeping the licence note at the top of the component.
It needs nothing beyond React. Your project needs CSS Modules, which Next.js and Vite already have.
Import it where you want it, then change the words, colours and sizes to yours.
The code
"use client";
import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore, type CSSProperties } from "react";
import styles from "./number-reels.module.css";
/**
* Text and numbers that spin into their new value like slot machine reels. Every character is a reel; digits count through
* the wheel in the direction the number moved, letters shuffle through the alphabet, and reels stop one after another from
* left to right with a soft, overshoot-free landing. Use it for prices, stats, and launch moments where a change deserves a beat.
*/
export interface NumberAnimationProps {
/** The value to show. Numbers pass through format; strings render as they are. */
This comes with paid plans
The code for every component comes with paid plans, along with the rest of the AI toolkit. The first component under each heading is free.
"use client";
import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore, type CSSProperties } from "react";
import styles from "./number-reels.module.css";
/**
* Text and numbers that spin into their new value like slot machine reels. Every character is a reel; digits count through
* the wheel in the direction the number moved, letters shuffle through the alphabet, and reels stop one after another from
* left to right with a soft, overshoot-free landing. Use it for prices, stats, and launch moments where a change deserves a beat.
*/
export interface NumberAnimationProps {
/** The value to show. Numbers pass through format; strings render as they are. */
This comes with paid plans
The code for every component comes with paid plans, along with the rest of the AI toolkit. The first component under each heading is free.