Added Tailwind CSS and tw-animate-css imports to globals.css. Introduced a custom dark variant and an extensive @theme inline block with CSS variables for colors, radii, and animations. Included keyframes for shimmer-slide, spin-around, gradient, shine, and background-position-spin to enable consistent theming and dynamic UI effects across the application.
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
"use client"
|
|
|
|
import { ComponentPropsWithoutRef, useEffect, useRef } from "react"
|
|
import { useInView, useMotionValue, useSpring } from "motion/react"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
interface NumberTickerProps extends ComponentPropsWithoutRef<"span"> {
|
|
value: number
|
|
startValue?: number
|
|
direction?: "up" | "down"
|
|
delay?: number
|
|
decimalPlaces?: number
|
|
}
|
|
|
|
export function NumberTicker({
|
|
value,
|
|
startValue = 0,
|
|
direction = "up",
|
|
delay = 0,
|
|
className,
|
|
decimalPlaces = 0,
|
|
...props
|
|
}: NumberTickerProps) {
|
|
const ref = useRef<HTMLSpanElement>(null)
|
|
const motionValue = useMotionValue(direction === "down" ? value : startValue)
|
|
const springValue = useSpring(motionValue, {
|
|
damping: 60,
|
|
stiffness: 100,
|
|
})
|
|
const isInView = useInView(ref, { once: true, margin: "0px" })
|
|
|
|
useEffect(() => {
|
|
if (isInView) {
|
|
const timer = setTimeout(() => {
|
|
motionValue.set(direction === "down" ? startValue : value)
|
|
}, delay * 1000)
|
|
return () => clearTimeout(timer)
|
|
}
|
|
}, [motionValue, isInView, delay, value, direction, startValue])
|
|
|
|
useEffect(
|
|
() =>
|
|
springValue.on("change", (latest) => {
|
|
if (ref.current) {
|
|
ref.current.textContent = Intl.NumberFormat("en-US", {
|
|
minimumFractionDigits: decimalPlaces,
|
|
maximumFractionDigits: decimalPlaces,
|
|
}).format(Number(latest.toFixed(decimalPlaces)))
|
|
}
|
|
}),
|
|
[springValue, decimalPlaces]
|
|
)
|
|
|
|
return (
|
|
<span
|
|
ref={ref}
|
|
className={cn(
|
|
"inline-block tracking-wider text-black tabular-nums dark:text-white",
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{startValue}
|
|
</span>
|
|
)
|
|
}
|