Download web/src/components/CountUp.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/CountUp.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/components/CountUp.tsx
-
curl -L -o CountUp.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/CountUp.tsx
1.35 kB
| import { useEffect, useRef, useState } from 'react'; | |
| /** A number that counts up from 0 to its value when it first shows, with an expo ease (the Sheryians feel). The final | |
| * value is what screen readers and copy/paste get; reduced motion shows it straight away. */ | |
| export function CountUp({ value, suffix = '', duration = 1100 }: { value: number; suffix?: string; duration?: number }) { | |
| const [shown, setShown] = useState(value); | |
| const from = useRef(0); | |
| useEffect(() => { | |
| const still = typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches; | |
| if (still || typeof requestAnimationFrame === 'undefined') { setShown(value); return; } | |
| const start = performance.now(); | |
| const a = from.current; | |
| let id = 0; | |
| const tick = (t: number) => { | |
| const p = Math.min(1, (t - start) / duration); | |
| const eased = 1 - Math.pow(2, -10 * p); // expo out | |
| setShown(Math.round(a + (value - a) * (p === 1 ? 1 : eased))); | |
| if (p < 1) id = requestAnimationFrame(tick); else from.current = value; | |
| }; | |
| id = requestAnimationFrame(tick); | |
| return () => cancelAnimationFrame(id); | |
| }, [value, duration]); | |
| return ( | |
| <span className="pw-countup" aria-label={`${value}${suffix}`}> | |
| <span aria-hidden>{shown}{suffix}</span> | |
| </span> | |
| ); | |
| } | |