cnippet
uianimated-numbersource: ok · refreshed
Animated Number
Smooth spring-based number interpolation
npx shadcn add "https://ui.cnippet.dev/r/animated-number.json"free
No selection tags yet — empty means no evidence, not lack of support.
Dependencies
Bundle weight · mediumanimationmotion
Files1 · source cached 10/8/2026, 8:49:01 AM
registry/default/motion/animated-number.tsx
"use client";
import {
motion,
type SpringOptions,
useSpring,
useTransform,
} from "motion/react";
import { type JSX, useEffect } from "react";
import { cn } from "@/lib/utils";
export type AnimatedNumberProps = {
value: number;
className?: string;
springOptions?: SpringOptions;
as?: React.ElementType;
};
export function AnimatedNumber({
value,
className,
springOptions,
as = "span",
}: AnimatedNumberProps) {
const MotionComponent = motion.create(as as keyof JSX.IntrinsicElements);
const spring = useSpring(value, springOptions);
const display = useTransform(spring, (current) =>
Math.round(current).toLocaleString(),
);
useEffect(() => {
spring.set(value);
}, [spring, value]);
return (
<MotionComponent className={cn("tabular-nums", className)}>
{display}
</MotionComponent>
);
}