Number Ticker
Smoothly interpolate between supplied numeric values.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/number-ticker.jsonUse it
Scroll horizontally for long lines
"use client";
import { useState } from "react";
import { Badge } from "@/components/jez-ui/ui/badge";
import { NumberTicker } from "@/components/jez-ui/ui/number-ticker";
import { Button } from "@/components/jez-ui/ui/button";
import { Plus } from "lucide-react";
export default function Example() {
const [count, setCount] = useState(128);
return (
<>
<div className="grid w-full max-w-md gap-7">
<div className="flex items-center justify-between">
<h3 className="text-2xl">A growing idea.</h3>
<Badge tone="positive">Live demo</Badge>
</div>
<NumberTicker
value={count}
className="font-display text-8xl tracking-tight"
/>
<div className="flex items-center justify-between border-t border-border pt-5">
<p className="text-sm text-muted-foreground">People on the list</p>
<Button
variant="outline"
onClick={() => setCount((c) => c + 17)}
>
Add 17 <Plus size={14} />
</Button>
</div>
</div>
</>
);
}
Props & types
Scroll horizontally for long lines
Omit<
React.ComponentProps<"span">,
keyof {
value: number;
decimals?: number;
className?: string;
}
> & {
value: number;
decimals?: number;
className?: string;
}Source
View 2 source files
registry/ui/number-ticker.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { animate, useReducedMotion } from "motion/react";
export function NumberTicker({
children,
value,
decimals = 0,
className,
...rootProps
}: Omit<
React.ComponentProps<"span">,
keyof {
value: number;
decimals?: number;
className?: string;
}
> & {
value: number;
decimals?: number;
className?: string;
}) {
const [display, setDisplay] = React.useState(value);
const previous = React.useRef(value);
const reduce = useReducedMotion();
React.useEffect(() => {
const controls = animate(previous.current, value, {
duration: reduce ? 0 : 0.6,
onUpdate: setDisplay,
});
previous.current = value;
return () => controls.stop();
}, [value, reduce]);
return (
<span
{...rootProps}
className={cn("tabular-nums", className)}
aria-label={value.toFixed(decimals)}
>
{children !== undefined ? (
children
) : (
<>
<span aria-hidden="true">{display.toFixed(decimals)}</span>
</>
)}
</span>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
motion@13.2.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · lucide-react@0.577.0
Accessibility & behaviour
Respect reduced-motion preferences. Decorative effects must not carry essential information. WebGL scenes include a static fallback and only render while visible.
Read the accessibility and performance guide →