Guides · 01

Transitions

Every component takes one transition: a timing curve or a spring. How to choose, and what happens when a motion is interrupted.

Two kinds of transition

A transition is either { duration, easing } or { tempo: 'spring', spring }. Pass it to the transition prop of any component. Components that move several things at once take a second prop, such as layoutTransition on MotionList for items gliding to new positions.

transitions.js
// Timing: a duration and a curve.
{ duration: 300, easing: 'easeOut' }
{ duration: 600, easing: [0.22, 1, 0.36, 1] }

// Spring: physics that keeps its speed when interrupted.
{ tempo: 'spring', spring: { stiffness: 260, damping: 12 } }

// Spring with duration: calibrated to settle exactly then.
{ tempo: 'spring', spring: { stiffness: 260, damping: 12 }, duration: 500 }

Springs with a duration

A spring normally runs as long as its physics needs. Add duration and the spring is calibrated to settle exactly then, keeping its character (how much it bounces) while fitting your timing. Compare timing curves and springs on the same three components below.

Preparing the example…

Interruptions

Every component starts a new motion from what is on screen. A spring also keeps its current velocity, so a second click turns the motion around smoothly. A timing curve starts again from the current position with a fresh curve.

  • Numbers: a new value continues from the glyphs on screen.
  • Height and swaps: the size continues from the size on screen.
  • Lists: items moving to a new position keep their velocity.

Ready-made transitions

motionTokens collects a few consistent feels: four springs, four timing curves and four durations. They are plain objects, so spread one to change a single field.

tokens.js
import { motionTokens } from '@kkwaenggwari/animated-chorus';

motionTokens.spring.quick; // snappy UI feedback
motionTokens.spring.basic; // the default feel
motionTokens.spring.gentle; // panels and height
motionTokens.spring.bouncy; // playful numbers
motionTokens.easing.expoOut; // { duration: 420, easing: 'expoOut' }
motionTokens.duration.fast; // 140

Easing names

easing accepts linear, in, out, inOut, ease, easeIn, easeOut, easeInOut, expoOut, backOut, or a cubic Bézier array such as [0.22, 1, 0.36, 1].

Search

Type to search the documentation.