PeakUI

Animation

The easing and animation tokens, and how a component animates a state

Motion comes from three places: easing and animation tokens in the theme, the data attributes a component sets as its state changes, and the reduced-motion variant that stands all of it down. It is CSS throughout — the entry and exit utilities come from tw-animate-css, which @peakui/styles imports for you, and there is no JavaScript motion library.

Easing

Each curve is a custom property and a Tailwind utility of the same name.

TokenValueUsed by
--ease-outcubic-bezier(0.16, 1, 0.3, 1)46 stylesheets — the default for a transition
--ease-smoothease35 stylesheets — hover, press and focus changes
--ease-out-quartcubic-bezier(0.165, 0.84, 0.44, 1)Modal, Drawer, AlertDialog, Dropdown, MenuItem, ListBoxItem, CloseButton
--ease-out-fluidcubic-bezier(0.32, 0.72, 0, 1)SegmentedControl, Switch, Tabs, Toast — a part that slides into place
--ease-out-quadcubic-bezier(0.25, 0.46, 0.45, 0.94)Accordion and Disclosure, opening and closing
--ease-linearlinearCheckbox, for the icon's scale and opacity
--ease-in-out-cubiccubic-bezier(0.645, 0.045, 0.355, 1)Your own CSS: the library uses it nowhere
--ease-in-cubiccubic-bezier(0.55, 0.055, 0.675, 0.19)Your own CSS: the library uses it nowhere
.my-panel {
  transition: transform 150ms var(--ease-out);
}
<div className="transition-transform duration-150 ease-out" />

Looping Animations

Three compositions, each a @keyframes and its timing. The skeleton and caret-blink keyframes are declared in the theme beside them; spin is Tailwind's own.

TokenValueUtilityUsed by
--animate-spin-fastspin 0.75s linear infiniteanimate-spin-fastSpinner
--animate-skeletonskeleton 2s linear infiniteanimate-skeletonSkeleton
--animate-caret-blinkcaret-blink 1.2s ease-out infiniteanimate-caret-blinkInputOTP

Animating a State

A component writes its state onto the DOM as data-* attributes, and CSS selects on them. Thirteen component stylesheets animate entry and exit this way, overlays among them.

/* The attribute carries a value: match `="true"`, not the bare attribute. */
.my-popover[data-entering="true"] {
  opacity: 1;
  transform: scale(1);
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}

.my-popover[data-exiting="true"] {
  opacity: 0;
}

data-placement carries the side an overlay opened on, which is what lets one rule slide a popover in from the direction it came from. Each component page lists the attributes it sets.

The library's own overlays write these phases with the tw-animate-css utilities rather than by hand — animate-in, animate-out, fade-in-0, zoom-in-90, slide-in-from-bottom-1 — and they are available to you on the same attributes.

Reduced Motion

Every animated stylesheet in the library stands down when the reader asks for less motion, through the motion-reduce variant. Write the same into any animation of your own.

<div className="animate-skeleton motion-reduce:animate-none" />
.my-panel {
  @media (prefers-reduced-motion: reduce) {
    transition: none;
  }
}

One component does not need it: ScrollShadow interpolates its fades along the scroll position rather than along time, so there is no motion of its own to stop.

Using a Motion Library

There is no JavaScript motion library here, and a component that renders a plain DOM element does not need one to be replaced: it takes a render prop, so an element from a motion library can take its place. Which components accept it, and the React Aria restriction that decides it, are in Composition.

On this page