Chewypixel component
Animated Number
A number that counts to its new value when it changes.
Installation
npx shadcn@latest add https://chewypixel.io/r/animated-number.jsonUsage
"use client";
import { useState } from "react";
import { AnimatedNumber } from "@/components/ui/animated-number";
import { Button } from "@/components/ui/button";
export function Revenue() {
const [revenue, setRevenue] = useState(12480);
return (
<div className="flex items-center gap-4">
<AnimatedNumber
value={revenue}
format={(value) => `$${Math.round(value).toLocaleString("en-US")}`}
className="text-3xl font-bold tabular-nums"
/>
<Button variant="outline" onClick={() => setRevenue(revenue + 1250)}>
Add a sale
</Button>
</div>
);
}Props
valueThe number to show.
number
formatFormats the value on each frame. Defaults to a rounded number with thousands separators.
(value: number) => string
durationHow long the count takes, in seconds.
number = 0.8
classNameClasses for the wrapping span.
string
Released under the MIT License.
More components
- Radio GroupRadio buttons that squish when pressed, with a dot that springs in when picked.
- TooltipA tooltip on a frosted panel that scales in from its trigger and fades out when you move away.
- DialogA dialog that springs up over a light overlay and animates out before it closes.
- SheetA side panel that slides in from any edge of the screen over a light overlay.
See them in a real app
These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.