Componentes
[ui] · motion

NumberTicker

Contador animado con spring que se dispara al entrar en viewport. Ideal para métricas y stats.

motion
@/components/ui/number-ticker
0clientes activos
1"use client";
2import { useEffect, useRef } from "react";
3import { useInView, useMotionValue, useSpring } from "motion/react"
4 
5import { cn } from "@/lib/utils"
6 
7export function NumberTicker({
8 value,
9 startValue = 0,
10 direction = "up",
11 delay = 0,
12 className,
13 decimalPlaces = 0,
14 ...props
15}) {
16 const ref = useRef(null)
17 const motionValue = useMotionValue(direction === "down" ? value : startValue)
18 const springValue = useSpring(motionValue, {
19 damping: 60,
20 stiffness: 100,
21 })
22 const isInView = useInView(ref, { once: true, margin: "0px" })
23 
24 useEffect(() => {
25 let timer = null
26 
27 if (isInView) {
28 timer = setTimeout(() => {
29 motionValue.set(direction === "down" ? startValue : value)
30 }, delay * 1000)
31 }
32 
33 return () => {
34 if (timer !== null) {
35 clearTimeout(timer)
36 }
37 };
38 }, [motionValue, isInView, delay, value, direction, startValue])
39 
40 useEffect(() =>
41 springValue.on("change", (latest) => {
42 if (ref.current) {
43 ref.current.textContent = Intl.NumberFormat("en-US", {
44 minimumFractionDigits: decimalPlaces,
45 maximumFractionDigits: decimalPlaces,
46 }).format(Number(latest.toFixed(decimalPlaces)))
47 }
48 }), [springValue, decimalPlaces])
49 
50 return (
51 <span
52 ref={ref}
53 className={cn(
54 "inline-block tracking-wider text-black tabular-nums dark:text-white",
55 className
56 )}
57 {...props}>
58 {startValue}
59 </span>
60 );
61}
62 

Uso

Props

PropTipoDefaultDescripción
valuenumber—Valor final.
startValuenumber0Valor inicial.
directionup | downupDirección del conteo.
delaynumber0Segundos de espera.
decimalPlacesnumber0Decimales a mostrar.

Acciones del componente

Search for a command to run...

Potenciá tu negocio con SFESS

Software a medida, IA integrada y ciberseguridad avanzada para empresas.

0años de ingeniería
0proyectos entregados
0% uptime
Servicios destacados
  • Consultoría SEO Avanzado & Analítica

    Auditoría técnica profunda para posicionar tu negocio en los primeros resultados de Google.

    SEO TécnicoGA4
  • Páginas Web Corporativas Complejas

    Plataformas empresariales masivas con múltiples secciones y animaciones fluidas.

    Framer MotionMulti-page
  • Integración de Inteligencia Artificial en Negocios

    Automatizamos la atención, las reservas y las ventas de tu negocio con agentes de IA.

    AI AgentsChatbots
Nuestro ecosistema
WORKENTA_OSSFESS_SOLUTIONSPRANALUZ_YOGAREMY_AI
Ver todos los servicios