terra vidhal

Sliding Number

Component

About

An odometer-style number where every digit rolls independently with spring physics.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Sliding Number to your project and fits it to your theme.

Code

How Sliding Number is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

/**
 * PrequelUI Animate — MIT — https://prequeluianimate.terravidhal.me
 */

import * as React from "react";
import { Minus, Plus, Shuffle } from "lucide-react";
import { SlidingNumber } from "@/components/ui/sliding-number";

export default function SlidingNumberDemo() {
  const [value, setValue] = React.useState(12480);

  const increment = () => setValue((current) => current + 1);
  const decrement = () => setValue((current) => Math.max(0, current - 1));
  const randomize = () =>
    setValue(() => Math.floor(1000 + Math.random() * 99000));

  return (
    <div className="flex min-h-screen items-center justify-center bg-gradient-to-b from-slate-50 to-slate-200 p-6 text-slate-900 dark:from-slate-950 dark:to-black dark:text-slate-100">
      <div className="w-full max-w-lg rounded-[2rem] border border-black/5 bg-white/80 p-10 text-center shadow-xl shadow-slate-900/5 backdrop-blur dark:border-white/10 dark:bg-white/5 dark:shadow-black/40">
        <p className="text-[11px] uppercase tracking-[0.35em] text-slate-400 dark:text-slate-500">
          Monthly downloads
        </p>

        <SlidingNumber
          id="sliding-number-display"
          data-slot="sliding-number-display"
          number={value}
          fromNumber={0}
          thousandSeparator=","
          className="mt-4 text-6xl font-semibold tracking-tight text-slate-900 dark:text-white"
        />

        <p className="mt-3 text-sm text-slate-500 dark:text-slate-400">
          Every digit rolls on its own spring.
        </p>

        <div className="mt-9 flex items-center justify-center gap-2">
          <button
            id="sliding-decrement"
            data-slot="sliding-decrement"
            type="button"
            onClick={decrement}
            aria-label="Decrease value"
            className="inline-flex h-11 w-11 items-center justify-center rounded-xl border border-black/10 bg-white text-slate-700 transition hover:bg-slate-100 active:scale-95 dark:border-white/10 dark:bg-white/10 dark:text-white dark:hover:bg-white/20"
          >
            <Minus className="size-4" />
          </button>
          <button
            id="sliding-increment"
            data-slot="sliding-increment"
            type="button"
            onClick={increment}
            aria-label="Increase value"
            className="inline-flex h-11 w-11 items-center justify-center rounded-xl border border-black/10 bg-white text-slate-700 transition hover:bg-slate-100 active:scale-95 dark:border-white/10 dark:bg-white/10 dark:text-white dark:hover:bg-white/20"
          >
            <Plus className="size-4" />
          </button>
          <button
            id="sliding-randomize"
            data-slot="sliding-randomize"
            type="button"
            onClick={randomize}
            className="inline-flex h-11 items-center gap-2 rounded-xl border border-black/10 bg-white px-4 text-sm font-medium text-slate-700 transition hover:bg-slate-100 active:scale-95 dark:border-white/10 dark:bg-white/10 dark:text-white dark:hover:bg-white/20"
          >
            <Shuffle className="size-4" />
            Randomize
          </button>
        </div>
      </div>
    </div>
  );
}

Dependencies

More by terra vidhal

View all
  • Morphing Text

    Morphing Text

  • Image Zoom

    Image Zoom

  • File Drop

    File Drop

  • Liquid Button

    Liquid Button

  • Gravity Stars Background

    Gravity Stars Background

Explore more

Part of PrequelUI Animate — browse the full library on 21st.dev.