Motion
Counter
Counts up when on screen. Screen readers and pages without JavaScript get the final number.
import { Counter, counterValue } from "@percentsa/motion";Examples
48
projects shipped
1,250,000
monthly users
Code
export function CounterExample() {
const t = useT();
const [key, setKey] = useState(0);
return (
<Stack gap={6}>
<Inline gap={12} key={key}>
<div>
<Counter value={48} className="display text-6xl" />
<Text size="sm" tone="muted">{t("projects shipped", "مشروعًا مُطلقًا")}</Text>
</div>
<div>
<Counter value={1250000} className="display text-6xl" />
<Text size="sm" tone="muted">{t("monthly users", "مستخدم شهريًا")}</Text>
</div>
</Inline>
<Button variant="secondary" size="sm" className="w-fit" onClick={() => setKey(key + 1)}>
{t("Replay", "أعد التشغيل")}
</Button>
</Stack>
);
}
const STEP_MS = 4000;