Merge pull request 'Add immediate opt-out for FadeIn and AnimatedNumber' (#3) from fix/motion-immediate into main
ci / build-and-design (push) Failing after 2s

This commit was merged in pull request #3.
This commit is contained in:
2026-08-20 17:18:48 -05:00
3 changed files with 17 additions and 5 deletions
+6 -2
View File
@@ -8,10 +8,13 @@ export function AnimatedNumber({
value,
format = defaultFormat,
className,
immediate = false,
}: {
value: number;
format?: (n: number) => string;
className?: string;
/** Count up on mount instead of waiting to scroll into view. Dashboards. */
immediate?: boolean;
}) {
const ref = React.useRef<HTMLSpanElement>(null);
const inView = useInView(ref, { once: true, margin: "-20% 0px" });
@@ -19,11 +22,12 @@ export function AnimatedNumber({
const mv = useMotionValue(0);
const spring = useSpring(mv, { stiffness: 90, damping: 20 });
const [display, setDisplay] = React.useState(format(0));
const active = immediate || inView;
React.useEffect(() => {
if (reduce) { setDisplay(format(value)); return; }
if (inView) mv.set(value);
}, [inView, value, reduce, mv, format]);
if (active) mv.set(value);
}, [active, value, reduce, mv, format]);
React.useEffect(() => spring.on("change", (v) => setDisplay(format(v))), [spring, format]);
+4 -1
View File
@@ -24,6 +24,8 @@ export interface StatCardProps {
intent?: StatIntent;
icon?: React.ReactNode;
className?: string;
/** Count up on mount. Pass through to AnimatedNumber. */
immediate?: boolean;
}
/** Dashboard metric tile. Pass `animate` for a count-up, or `value` for static. */
@@ -36,6 +38,7 @@ export function StatCard({
intent = "default",
icon,
className,
immediate,
}: StatCardProps) {
return (
<div className={cn("rounded-lg border border-border bg-surface p-4 shadow-sm", className)}>
@@ -44,7 +47,7 @@ export function StatCard({
{icon && <span className="text-muted [&_svg]:size-4">{icon}</span>}
</div>
<p className={cn("mt-1 font-display text-2xl font-bold", INTENT[intent])}>
{animate != null ? <AnimatedNumber value={animate} format={format} /> : value}
{animate != null ? <AnimatedNumber value={animate} format={format} immediate={immediate} /> : value}
</p>
{sub && <p className="mt-0.5 text-xs text-muted">{sub}</p>}
</div>
+7 -2
View File
@@ -9,19 +9,24 @@ export function FadeIn({
delay = 0,
y = 8,
className,
immediate = false,
}: {
children: React.ReactNode;
delay?: number;
y?: number;
className?: string;
/** Animate on mount instead of waiting to scroll into view. Dashboards. */
immediate?: boolean;
}) {
const reduce = useReducedMotion();
const visible = { opacity: 1, y: 0 };
return (
<motion.div
className={className}
initial={reduce ? false : { opacity: 0, y }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: "-10% 0px" }}
{...(immediate
? { animate: visible }
: { whileInView: visible, viewport: { once: true, margin: "-10% 0px" as const } })}
transition={reduce ? { duration: 0 } : { duration: 0.4, ease: easeOut, delay }}
>
{children}