feat(insights): premium animated wellness-score rings

Rebuild the wellness-score strip on /insights as a signature, high-end moment
instead of a flat dial.

- Five distinct per-metric hues — readiness green, recovery teal, sleep
  indigo-blue, stress amber, strain violet — hand-tuned per theme so each holds
  contrast on the white light-mode card. Fixes the dark-theme collapse to a
  cyan/green wash (the semantic info token resolved to the same cyan as three
  rings) and the light-theme wash-out of the raw cyan on white.
- A spring-eased arc sweep that overshoots ~6% then settles, a left-to-right
  staggered reveal with each number trailing its own arc, a conic specular
  sheen that sweeps once, a token-tinted bloom (a gentle breathing pulse only
  on a top-band ring), a segmented instrument-style track, and a faint
  film-grain tile surface for material depth.
- A "vs your normal" ghost arc under the live arc for recovery, stress and
  strain, derived from the trailing score series already on the payload, so the
  user sees today against their baseline at a glance.

The reveal plays once per browser session (sessionStorage-gated) so a
background sync refetch never re-triggers it. All motion is CSS-first — no
animation dependency, @property + a sampled linear() spring — and is fully
disabled under prefers-reduced-motion. The arc stays a hand-rolled SVG gauge;
the band semantic still rides data-band + the band word + the aria-label, never
colour alone.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.8 committed 2026-06-05 23:40:00 +02:00
1 parent 4a31ce41b2
commit 20d7187b0d
5 files changed
+508 -114

No files matched your search

+24 -8
View File
@@ -17,9 +17,9 @@ import { useEffect, useRef, useState } from "react";
*/
export function useCountUp(
target: number,
options: { durationMs?: number; enabled?: boolean } = {},
options: { durationMs?: number; enabled?: boolean; startDelayMs?: number } = {},
): number {
const { durationMs = 600, enabled = true } = options;
const { durationMs = 600, enabled = true, startDelayMs = 0 } = options;
// Seed at the final value so the reduced-motion / SSR path is already
// correct without any setState; only the animated path drives frames,
// and those setState calls all happen inside the rAF callback (async).
@@ -60,7 +60,7 @@ export function useCountUp(
return;
}
const start = performance.now();
let start = 0;
const tick = (now: number) => {
const elapsed = now - start;
@@ -76,20 +76,36 @@ export function useCountUp(
}
};
// First frame (and every subsequent one) runs inside the rAF callback,
// so the initial 0-state set is asynchronous — no cascading render.
frameRef.current = window.requestAnimationFrame((now) => {
// Hold the number at 0 during the stagger delay so it matches the empty
// ring, then start the rAF loop. Every setState runs inside a rAF/timeout
// callback (async) — never synchronously in the effect body — so there is
// no cascading render. `startDelayMs` lets the strip stagger each tile's
// count-up so the number trails its arc, left-to-right.
let timeoutId: ReturnType<typeof setTimeout> | null = null;
const begin = () => {
frameRef.current = window.requestAnimationFrame((now) => {
start = now;
tick(now);
});
};
const arm = window.requestAnimationFrame(() => {
setValue(0);
tick(now);
if (startDelayMs > 0) {
timeoutId = setTimeout(begin, startDelayMs);
} else {
begin();
}
});
return () => {
window.cancelAnimationFrame(arm);
if (timeoutId != null) clearTimeout(timeoutId);
if (frameRef.current != null) {
window.cancelAnimationFrame(frameRef.current);
frameRef.current = null;
}
};
}, [target, durationMs, enabled]);
}, [target, durationMs, enabled, startDelayMs]);
return value;
}