animated-number
cult-ui/animated-numberUnverifiedComponent
Number component with smooth counting animations and customizable formatting
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/animated-number.jsonSource
1"use client"23import { useEffect } from "react"4import { motion, MotionValue, useSpring, useTransform } from "motion/react"56interface AnimatedNumberProps {7 value: number8 mass?: number9 stiffness?: number10 damping?: number11 precision?: number12 format?: (value: number) => string13 onAnimationStart?: () => void14 onAnimationComplete?: () => void15}1617export function AnimatedNumber({18 value,19 mass = 0.8,20 stiffness = 75,21 damping = 15,22 precision = 0,23 format = (num) => num.toLocaleString(),24 onAnimationStart,25 onAnimationComplete,26}: AnimatedNumberProps) {27 const spring = useSpring(value, { mass, stiffness, damping })28 const display: MotionValue<string> = useTransform(spring, (current) =>29 format(parseFloat(current.toFixed(precision)))30 )3132 useEffect(() => {33 spring.set(value)34 if (onAnimationStart) onAnimationStart()35 const unsubscribe = spring.on("change", () => {36 if (spring.get() === value && onAnimationComplete) onAnimationComplete()37 })38 return () => unsubscribe()39 }, [spring, value, onAnimationStart, onAnimationComplete])4041 return <motion.span>{display}</motion.span>42}
What it pulls in
npm packages
Files it writes
More from cult/ui
All 157 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-instructionsai-instructions | cult/ui | Components | Unverified | 2 deps | |
| ai-instructions-demoai-instructions-demo | cult/ui | Components | Unverified | no deps | |
| animated-number-demoanimated-number-demo | cult/ui | Components | Unverified | no deps | |
| bg-animate-buttonbg-animate-button | cult/ui | Components | Unverified | no deps | |
| bg-animate-button-demobg-animate-button-demo | cult/ui | Components | Unverified | no deps | |
| bg-animated-fractal-dot-gridbg-animated-fractal-dot-grid | cult/ui | Components | Unverified | 1 dep | |
| bg-animated-fractal-dot-grid-demobg-animated-fractal-dot-grid-demo | cult/ui | Components | Unverified | no deps | |
| bg-animated-gradientbg-animated-gradient | cult/ui | Components | Unverified | 1 dep |
