Skip to content

Animated numeric ranges

Read as Markdown

Compose endpoint interpolation with the existing target-driven animation hook.

Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".

import {
FocusManagement,
Text,
easing,
signal,
tween,
useAnimatedValue,
} from "@pibbl/core";
import { pibblSync } from '@pibbl/core/sync';
import { interpolateNumericRange, type NumericDomain } from "@pibbl/core/viz";
const intent = signal<NumericDomain>([18, 42]);
function Readout() {
const shown = useAnimatedValue(intent, {
initial: [0, 12],
animation: tween<NumericDomain>({
duration: 180,
easing: easing.easeOut,
interpolate: interpolateNumericRange,
}),
equals: (a, b) => a[0] === b[0] && a[1] === b[1],
});
const [start, end] = shown.get();
return (
<Text
style={{ left: 16, top: 18, font: "13px sans-serif", fill: "#18283d" }}
>
{`Animated range: ${start.toFixed(1)} – ${end.toFixed(1)}`}
</Text>
);
}
export function NumericRangeInterpolationExample() {
return (
<FocusManagement>
<Readout />
</FocusManagement>
);
}
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 220;
document.body.append(canvas);
const app = pibblSync(canvas, <NumericRangeInterpolationExample />);
window.addEventListener("pagehide", () => app.dispose(), { once: true });

Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.