Motion tokens
Shared durations, easings and springs, plus a reduced-motion hook. Data marks settle without overshoot; only chrome may spring.
Install
npx shadcn@latest add https://thrumui.dev/r/thrum-motion.jsonAdds lib/thrum-motion.ts and installs motion. Nothing else in your project changes.
import { staggerDelay } from "@/lib/thrum-motion";Source
"use client";
/**
* Shared motion tokens. Every component animates with these, never with a library default.
* The rule they encode: data marks settle without overshoot; only chrome may spring.
*/
import { useContext } from "react";
import { MotionConfigContext, useReducedMotion as useSystemReducedMotion, type Transition } from "motion/react";
/** Durations in seconds. */
export const DUR = { fast: 0.15, base: 0.2, enter: 0.25, morph: 0.4, reveal: 0.7 } as const;
export const EASE = {
out: [0.23, 1, 0.32, 1],
inOut: [0.77, 0, 0.175, 1],
standard: [0.2, 0, 0, 1],
} as const satisfies Record<string, readonly [number, number, number, number]>;
export const SPRING = {
/** Switches, thumbs, buttons. Under 1% overshoot. */
control: { type: "spring", stiffness: 1400, damping: 67 },
/** Cards, panels, popovers. Under 1% overshoot. */
surface: { type: "spring", stiffness: 700, damping: 48 },
/** Every data mark: bar height, line morph, meter fill, number roll. No overshoot. */
data: { type: "spring", visualDuration: DUR.morph, bounce: 0 },
/** Things that track the pointer. */
follow: { type: "spring", stiffness: 3800, damping: 123 },
} as const satisfies Record<string, Transition>;
/** First draw of a line: constant speed, like a strip-chart recorder. */
export const REVEAL: Transition = { duration: DUR.reveal, ease: "linear" };
/** Enter for chrome and for marks that grow from a baseline. */
export const ENTER: Transition = { duration: DUR.enter, ease: EASE.out };
/** Hover, press, focus: colour and opacity only. */
export const FAST: Transition = { duration: DUR.fast, ease: EASE.standard };
export const INSTANT: Transition = { duration: 0 };
/** Delay for item `index` of `count`: 40 ms apart, and never more than 300 ms for the whole group. */
export function staggerDelay(index: number, count: number): number {
const step = count > 1 ? Math.min(0.04, 0.3 / (count - 1)) : 0;
return index * step;
}
/**
* True when motion should be reduced: the visitor's system setting, or an enclosing
* `<MotionConfig reducedMotion="always">`. Components then show their final state at once.
*/
export function useReducedMotion(): boolean {
const system = useSystemReducedMotion();
const configured = useContext(MotionConfigContext).reducedMotion;
return configured === "always" || Boolean(system);
}
/** `transition` when motion is allowed, an instant change when it is reduced. */
export function useTransition(transition: Transition): Transition {
return useReducedMotion() ? INSTANT : transition;
}Files and dependencies
- Adds
lib/thrum-motion.ts- Packages
motion- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-02First release.