# Motion

Use purposeful, interruptible motion that explains state and respects reduced-motion preferences.

Motion should explain what changed, where an element came from, or how two states relate. It should never delay a task, hide essential feedback, or become the only way a state is communicated.

Zenos keeps routine motion short and quiet. Small anchored surfaces respond immediately, ordinary controls and disclosures use a measured base rhythm, and larger spatial transitions receive slightly more time.

## Duration

Zenos components currently use three practical duration bands:

| Rhythm | Duration | CSS variable             | Utility                | Typical use                                                               |
| ------ | -------: | ------------------------ | ---------------------- | ------------------------------------------------------------------------- |
| Fast   |  `150ms` | `--motion-duration-fast` | `duration-motion-fast` | Popovers, menus, tooltips, indicators, and immediate feedback             |
| Base   |  `200ms` | `--motion-duration-base` | `duration-motion-base` | Dialogs, sheets, accordions, switches, carets, and ordinary state changes |
| Slow   |  `300ms` | `--motion-duration-slow` | `duration-motion-slow` | Lightboxes, large media, and transitions with greater visual distance     |

Choose the shortest duration that keeps the relationship understandable. A small opacity change should not wait for a large panel transition, while a full-screen media change may need more time than a checkbox indicator.

The same values are exported for JavaScript-driven animation:

```tsx
import { motionDuration } from "@zentara-co/zenos-ui";

element.animate(keyframes, { duration: motionDuration.base });
```

## Easing

The curves below share one duration in the preview so the change in velocity is visible. Reset and replay the tracks rather than judging a curve from its name alone.

```tsx
import { Button, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

const motionEasingRows = [
  { label: "Out", utility: "ease-motion-out", use: "UI enter and exit" },
  { label: "In out", utility: "ease-motion-in-out", use: "On-screen movement" },
  { label: "Drawer", utility: "ease-motion-drawer", use: "Sheets and large panels" },
  { label: "Sine", utility: "ease-motion-sine", use: "Oscillation" },
  { label: "Spring", utility: "ease-motion-spring", use: "Rewarding confirmation" },
] as const;

function MotionEasingExample() {
  const [played, setPlayed] = useState(false);

  return (
    <Stack gap="4" className="w-full max-w-2xl">
      <Button size="sm" variant="primary" className="self-start" onClick={() => setPlayed(!played)}>
        {played ? "Reset" : "Play"}
      </Button>
      <Stack gap="3">
        {motionEasingRows.map((row) => (
          <div
            key={row.utility}
            className="grid gap-2 sm:grid-cols-[8rem_1fr_10rem] sm:items-center"
          >
            <code className="text-xs text-text-brand-default">{row.utility}</code>
            <div className="relative h-2 rounded-full bg-background-neutral-subtle-default">
              <span
                aria-hidden="true"
                className={`${row.utility} absolute top-1/2 size-5 -translate-y-1/2 rounded-full bg-background-brand-bold-default transition-[left] duration-motion-slow ${played ? "left-[calc(100%-1.25rem)]" : "left-0"}`}
              />
            </div>
            <Text size="s" color="subtle">
              {row.use}
            </Text>
          </div>
        ))}
      </Stack>
    </Stack>
  );
}
```

| Curve  | CSS variable           | Utility              | Use                                               |
| ------ | ---------------------- | -------------------- | ------------------------------------------------- |
| Out    | `--motion-ease-out`    | `ease-motion-out`    | Entering, exiting, expanding, and settling        |
| In out | `--motion-ease-in-out` | `ease-motion-in-out` | Moving between two equally important positions    |
| Drawer | `--motion-ease-drawer` | `ease-motion-drawer` | Large sheets and panels that travel farther       |
| Sine   | `--motion-ease-sine`   | `ease-motion-sine`   | Multi-stop oscillation such as a restrained shake |
| Spring | `--motion-ease-spring` | `ease-motion-spring` | Small, rewarding confirmation moments             |

Use the out curve for elements entering, exiting, expanding, or moving toward a resting position. It responds quickly at the beginning and settles without making the interface feel delayed. Use the symmetric in-out curve only when both ends of the movement carry equal weight.

Drawer gives large surfaces a confident start without extending the overall duration. Sine leaves and arrives gently, which prevents a multi-stop shake from pausing harshly at every extreme. Spring deliberately overshoots; reserve it for a checkmark, confirmation, or a control popping into place—not menus, dialogs, validation errors, or routine navigation.

For JavaScript animation, use the values from the same public contract:

```tsx
import { motionDuration, motionEasing } from "@zentara-co/zenos-ui";

element.animate(keyframes, {
  duration: motionDuration.base,
  easing: motionEasing.out,
});
```

The curve, duration, and distance form one decision. A longer travel distance can justify the slow rhythm, but increasing duration does not rescue motion that lacks a clear purpose.

## Prefer interruptible transitions

Use CSS transitions for motion driven by hover, focus, pressed, selected, expanded, or open state. A transition can reverse from its current position when the state changes halfway through.

Zenos Button uses the fast duration and out easing for its pressed scale. Use `disableMotion` for an individual button when movement would duplicate feedback supplied by its surrounding interaction:

```tsx
<Button disableMotion>Save changes</Button>
```

The opt-out removes the transition and scale while retaining the immediate pressed color, focus treatment, and native activation behavior.

```tsx
<CaretRightIcon
  aria-hidden
  className="transition-transform duration-motion-base ease-motion-out group-data-[panel-open]:rotate-90 motion-reduce:transition-none"
/>
```

Reserve keyframes for sequences that must run independently, such as a loader, a one-time overlay entrance, or a staged effect with more than two states. Do not use a looping animation merely to make static content appear active.

## Name the properties

Transition only the properties that communicate the state change:

```tsx
// Color feedback
<button className="transition-colors duration-motion-fast" />

// Spatial feedback
<div className="transition-[opacity,transform] duration-motion-base ease-motion-out" />
```

Avoid `transition-all`. It can animate an unrelated property introduced later and makes layout or paint work harder to diagnose. Prefer composited `opacity` and `transform` for spatial motion. Animate `height` only when revealing measured content, as Accordion and Collapsible do.

Tailwind CSS v4 represents `translate`, `scale`, and `rotate` as individual properties. Use `transition-transform` when those transform-related properties move together, or name the individual property in a custom transition list.

## Enter and exit with different emphasis

Entrance motion may establish origin with a small fade, scale, or directional offset. Exit motion should be equal or quieter: shorter travel, less scale, and no dramatic collapse.

Anchored Zenos surfaces derive direction from their placement. A popover below its trigger enters from above; one positioned to the right enters from the left. Dialogs and alerts use a restrained fade and scale because their origin is the current viewport rather than an edge.

Keep travel small. Motion should preserve the user's spatial model, not force their attention to follow an object across the screen.

## Stagger related content

When a small group mounts together, revealing every item as one block can hide its reading order. `Stagger` assigns a token-based delay to each direct element child, plays once on mount, and removes the entire effect under reduced motion.

```tsx
import { Button, Card, Stagger, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

const staggerItems = ["Overview", "Analytics", "Reports", "Members", "Billing", "Settings"];

function StaggerExample() {
  const [replay, setReplay] = useState(0);

  return (
    <Stack gap="4" className="w-full max-w-2xl">
      <Button
        size="sm"
        variant="primary"
        className="self-start"
        onClick={() => setReplay((current) => current + 1)}
      >
        Replay
      </Button>
      <Stagger key={replay} step={70} className="grid grid-cols-2 gap-3 sm:grid-cols-3">
        {staggerItems.map((item) => (
          <Card key={item} className="p-4">
            <Text weight="medium">{item}</Text>
          </Card>
        ))}
      </Stagger>
    </Stack>
  );
}
```

```tsx
import { Card, Stagger } from "@zentara-co/zenos-ui";

<Stagger className="grid grid-cols-3 gap-3">
  {items.map((item) => (
    <Card key={item.id}>{item.name}</Card>
  ))}
</Stagger>;
```

The default `step` is `70ms`, also exported as `motionStaggerStep` and available as `--motion-stagger-step`. Use `inView` for below-the-fold content and `blur` for an optional 4px focus pull. Direct children must forward `style` and `data-*` attributes. Keep cascades short; a large data set should not make its final rows wait to become readable.

## Turn one indicator instead of swapping two

When one mark represents two directions, preserve the mark and rotate it:

```tsx
<CaretDownIcon
  aria-hidden
  className="transition-transform duration-motion-base ease-motion-out group-data-[popup-open]:rotate-180 motion-reduce:transition-none"
/>
```

Replacing a down caret with a separate up caret removes the visible relationship between the states. Swapping icons is appropriate only when the symbols communicate genuinely different actions or meanings.

## Avoid unsolicited entrance motion

Content visible on the first page render should usually be present without an entrance animation. The user did not initiate a state change, and animating the entire page delays scanning.

Use entrance motion for an element that is newly mounted because of an action, for an overlay whose origin matters, or for a focused sequence where the transition explains hierarchy. Do not replay it on every render or route update.

Base UI exposes starting and ending state attributes for overlays and panels. Zenos uses those attributes so the motion follows the component lifecycle instead of relying on arbitrary timeouts.

## Respect reduced motion

Every non-essential transition and keyframe must have a reduced-motion treatment. In utility classes, use `motion-reduce:transition-none`, `motion-reduce:animate-none`, or gate an effect behind `motion-safe:`.

Reduced motion does not mean reduced information. Apply the final state immediately, retain visible focus and status feedback, and replace spatial movement with a static change or a simple state update.

```css
@media (prefers-reduced-motion: reduce) {
  .product-transition {
    animation: none;
    transition: none;
  }
}
```

Ambient and looping motion deserves particular care. A loader can retain a static progress shape or accessible status text when its animation stops. Never require movement to prove that work is happening.

## Performance

Prefer changes the browser can composite, especially `opacity` and transform-related properties. Avoid animating layout properties such as width, padding, or position unless the relationship cannot be expressed another way.

Do not add `will-change` preemptively. It can keep extra compositor layers alive and consume memory. Apply it only after measuring a real first-frame problem, limit it to the animated property, and remove it when the transition ends.

## Review checklist

Before shipping motion, verify:

- [ ] The movement explains a state, origin, hierarchy, or relationship.
- [ ] The duration matches the distance and complexity.
- [ ] Interactive state changes use interruptible transitions.
- [ ] Only intended properties animate.
- [ ] Exit motion is no stronger than entrance motion.
- [ ] Initial page content does not animate without purpose.
- [ ] Keyboard and pointer interactions can retarget the transition cleanly.
- [ ] Reduced motion preserves the same final state and information.
- [ ] Focus, announcements, and input remain available throughout the transition.
- [ ] Performance is tested on the actual surface, not inferred from the property name.

Motion is part of interaction design, not decoration added after implementation. Review it alongside keyboard behavior, focus management, responsive layout, and content—not as a separate polish pass.

Source: https://zenos-ui.pages.dev/foundations/motion/