Skip to content
Thrum
Docs · 07 of 09All pages

Motion

The motion rules every component follows, and reduced motion.

Thrum components move like the needle of a well-damped meter: quickly, and without passing the mark. Every duration, easing and spring comes from one file, lib/thrum-motion.ts, which is installed with your first component. You do not configure motion to use a component. This page is for knowing what to expect, and for making your own parts move the same way.

The tokens

These are the real values, read from the file when this page was built.

Durations

TokenValueUsed for
DUR.fast150 msHover, press and focus. Colour and opacity only.
DUR.base200 msChrome leaving. An exit is shorter than an entrance.
DUR.enter250 msChrome entering, and marks that grow from a baseline.
DUR.morph400 msA value changes: how long the data spring appears to take.
DUR.reveal700 msThe first draw of a line or area.

In code, durations are in seconds, as the motion library expects: DUR.reveal is 0.7.

Easings

TokenCurveUsed for
EASE.outcubic-bezier(0.23, 1, 0.32, 1)Entering: fast at first, then settling.
EASE.inOutcubic-bezier(0.77, 0, 0.175, 1)Not used by a preset yet.
EASE.standardcubic-bezier(0.2, 0, 0, 1)Hover, press and focus.

Springs

TokenSettingsUsed for
SPRING.controlstiffness 1400, damping 67Switches, thumbs, buttons. Under 1% overshoot.
SPRING.surfacestiffness 700, damping 48Cards, panels, popovers. Under 1% overshoot.
SPRING.datavisualDuration 0.4, bounce 0Every data mark: bar height, line shape, meter fill, number roll. No overshoot.
SPRING.followstiffness 3800, damping 123Anything that tracks the pointer, such as a chart cursor.

SPRING.data is set by how long it appears to take, in seconds, with no bounce. The other three are set by stiffness and damping, and are damped hard enough that they do not visibly pass their target.

Ready-made transitions

TokenSettingsUsed for
REVEALduration 0.7, ease linearFirst draw of a line: constant speed, like a pen on a strip chart.
ENTERduration 0.25, ease cubic-bezier(0.23, 1, 0.32, 1)Enter for chrome and for marks that grow from a baseline.
FASTduration 0.15, ease cubic-bezier(0.2, 0, 0, 1)Hover, press and focus.
INSTANTduration 0What every transition becomes under reduced motion.

staggerDelay(index, count) spaces a group of marks 40 ms apart, and closes the gaps in a large group so the last mark never starts more than 300 ms after the first. With 5 marks the last one starts after 160 ms; with 20 it starts after 300 ms.

The rules

  • No overshoot on data. A line, bar, arc or number never passes its true value, even for a frame. A chart that bounces shows, for a moment, a value that was never measured. Only chrome may spring.
  • Interruptible. A new value that arrives during an animation retargets it from where it is now. Nothing restarts and nothing queues, so a number that changes twice in a second rolls once, to the latest value.
  • Reveal follows the reading direction of the mark. A line or area is wiped in from left to right at constant speed, the way a recorder pen draws it. Marks with a baseline, such as bars, grow from that baseline, staggered.
  • The entrance plays once. After the first draw, a data change moves the marks from where they are to where they belong. If the number of points changes, the chart switches at once.
  • Nothing around it moves. An animating number reserves the width of its final value. A chart's frame has its final size before the data draws.
  • Data settles; feedback loops pause when asked. Charts, meters, numbers and controls animate when they appear or when their data changes and then come to rest. Feedback and ambient effect components (spinners, skeletons, text shimmer, marquees and border beams) loop gently while active and stop immediately under reduced motion.

Use the tokens in your own code

To make a part of your own move like the components, take its transition from the same file. useTransition returns the transition you pass, or an instant change when motion is reduced:

components/level-bar.tsx
"use client";

import { motion } from "motion/react";

import { SPRING, useTransition } from "@/lib/thrum-motion";

/**
 * A bar that grows to `level` (0 to 1) like a Thrum data mark:
 * no overshoot, and instant under reduced motion.
 */
export function LevelBar({ level }: { level: number }) {
  const transition = useTransition(SPRING.data);
  return (
    <div className="h-2 w-40 rounded-sm bg-muted">
      <motion.div
        className="h-full origin-left bg-primary"
        initial={false}
        animate={{ scaleX: level }}
        transition={transition}
      />
    </div>
  );
}

Reduced motion

Every component reads the visitor's system setting (prefers-reduced-motion). When it asks for less motion, components show their final state in the first frame: no wipe, no stagger, no rolling digits. Data still updates; it steps to the new state. There is nothing to set up.

You should see

Turn on “reduce motion” in your operating system's accessibility settings, or emulate it in your browser's developer tools, and reload. Charts appear complete. A changed value shows at once, with no movement. The cursor of a chart still follows the pointer, without easing.

Force reduced motion from your app

If your app has its own motion setting, wrap any part of the tree in MotionConfig from motion/react. Thrum components inside it reduce their motion whatever the system says:

An app-level motion switch
import { MotionConfig } from "motion/react";

export function Dashboard({ calm }: { calm: boolean }) {
  return (
    <MotionConfig reducedMotion={calm ? "always" : "user"}>
      <AreaChart data={data} label="Revenue" />
    </MotionConfig>
  );
}
  • "always" reduces motion for everything inside.
  • "user" follows the system setting. This is also what happens with no MotionConfig at all.
  • "never" does not override the visitor. If the system asks for reduced motion, Thrum components still reduce it.

The Motion switch in this site’s Appearance studio and status bar combines both layers: it sets data-motion="reduced" on <html> (which zeroes CSS transitions and keyframe animations) and passesreducedMotion="always" through MotionConfig. In your own components, useReducedMotion() from lib/thrum-motion.ts reads both MotionConfig and the systemprefers-reduced-motion setting and returns a boolean.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor