Vercel Animate Count
unlumen-ui/animate-countFreeComponent
A number display that animates the transition between values with a blur + slide effect, with a hook to throttle rapid updates.
Live preview
live · rendered by the registry
Rendered by Unlumen Ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.unlumen.com/r/animate-count.jsonSource
1"use client";23import { useEffect, useState } from "react";4import { AnimatePresence, motion } from "motion/react";56import { cn } from "@/lib/utils";78export const ANIMATE_COUNT_DURATION_MS = 450;910const EASING = [0.23, 0.88, 0.26, 0.92] as const;1112interface AnimateCountProps {13 children: number;14 animate?: boolean;15 className?: string;16}1718function AnimateCount({19 children: count,20 animate = true,21 className,22}: AnimateCountProps) {23 const [prev, setPrev] = useState<number | null>(null);24 const [displayCount, setDisplayCount] = useState(count);2526 useEffect(() => {27 if (animate) setPrev(displayCount);28 setDisplayCount(count);29 // eslint-disable-next-line react-hooks/exhaustive-deps30 }, [count, animate]);3132 return (33 <div34 className={cn(35 "grid place-items-center tabular-nums tracking-tight",36 "[&>*]:col-start-1 [&>*]:row-start-1",37 className,38 )}39 >40 <AnimatePresence initial={false}>41 {animate && prev !== null && prev !== displayCount && (42 <motion.div43 key={`exit-${prev}-${displayCount}`}44 aria-hidden45 initial={{ opacity: 1, filter: "blur(0px)", y: 0 }}46 animate={{ opacity: 0, filter: "blur(2px)", y: -12 }}47 transition={{48 duration: ANIMATE_COUNT_DURATION_MS / 1000,49 ease: EASING,50 }}51 onAnimationComplete={() => setPrev(null)}52 >53 {prev}54 </motion.div>55 )}56 </AnimatePresence>57 <motion.div58 key={`enter-${displayCount}`}59 initial={animate ? { opacity: 0, filter: "blur(2px)", y: 8 } : false}60 animate={{ opacity: 1, filter: "blur(0px)", y: 0 }}61 transition={{62 duration: ANIMATE_COUNT_DURATION_MS / 1000,63 ease: EASING,64 }}65 >66 {displayCount}67 </motion.div>68 </div>69 );70}7172export { AnimateCount, type AnimateCountProps };
What it pulls in
npm packages
Files it writes
More from Unlumen Ui
All 233 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Chatai-chat | Unlumen Ui | Components | Paid | 2 deps | |
| Animate Digitsanimate-digits | Unlumen Ui | Components | Free | 1 dep | |
| Animated Inputanimate-text-input-typing | Unlumen Ui | Components | Paid | 1 dep | |
| Animated Listanimated-list | Unlumen Ui | Components | Free | 1 dep | |
| Apple Switchapple-switch | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Barsaurora-bars | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Bluraurora-blur | Unlumen Ui | Components | Free | 2 deps | |
| Aurora Cardaurora-card | Unlumen Ui | Components | Paid | 2 deps |
