# Motion

Easing curves, durations, and reduced-motion rules for state changes.

## Overview

Motion in Tempo shows where something came from, confirms a press, and marks what is new. It is short, eases out, and never delays input, both in components and in anything you style yourself.

## Easing

Three ease-out curves cover interface motion, so each response starts at full speed. Use them by name instead of the browser default or a custom curve.

* `ease.snappy`: `cubic-bezier(0.23, 1, 0.32, 1)`
* `ease.spring`: `cubic-bezier(0.32, 0.72, 0, 1)`
* `ease.overshoot`: `cubic-bezier(0.34, 1.36, 0.64, 1)`

* **Snappy (ease.snappy):** Short changes, such as hover, focus, presses, popovers, and menus.
* **Overshoot (ease.overshoot):** Only physical feedback, such as switch thumbs and check marks. A dialog or menu would wobble.
* **Spring (ease.spring):** Larger travel, such as dialogs, drawers, toasts, and tabs.
* **Constant Rate (linear):** Continuous indicators only, such as [Spinner](/docs/components/spinner), which would pulse with easing.

## Durations

Small state changes finish fastest, overlays that travel farther run longer, and every overlay leaves faster than it enters.

### Micro Interactions

* **Press (100ms in, 160ms out):** Buttons scale down slightly and return on release.
* **Item Highlight (120ms):** Menu, select, and combobox items highlight.
* **Hover, Focus, and Color (160ms):** Buttons, tabs, and checkboxes change color.
* **Check Indicators (200ms):** Checkbox and radio indicators overshoot slightly.
* **Switch Thumb (240ms):** The switch thumb slides with a slight overshoot.
* **Selection Indicator (240ms):** The tabs indicator slides to the selected tab.

### Overlays and Content

* **Tooltip (160ms in, 100ms out):** Tooltips fade in, and leave faster than they enter.
* **Popover and Menu (200ms in, 140ms out):** Popovers and menus grow from their trigger.
* **Select and Combobox List (240ms in, 150ms out):** Lists open on the spring curve and close on snappy.
* **Expanding Content (240ms in, 180ms out):** Accordion panels expand and collapse.
* **Dialog (280ms in, 180ms out):** Dialogs enter over a fading backdrop.
* **Drawer and Toast (320ms in, 200 to 240ms out):** Drawers and toasts travel farthest and run longest.

## Guidelines

### Animate Every State Change

Give every state change a transition, from hover and focus to checked, disabled, and invalid states. Animate overlays, toasts, expanding content, and changing values in and out.

* **Press:** Scale the control to `scale.press` (0.98).
* **Popover and Menu:** Fade and grow from `scale.enter` (0.96).
* **Dialog and Drawer:** Fade the backdrop and slide or scale the panel.
* **Value Change:** Fade or slide the new value in.

### Use Transitions for State, Keyframes for Feedback

A transition reverses from its current point when the state flips back, so a quick hover in and out never jumps. Keep keyframes for feedback that plays once.

* **State Changes (transition):** Hover, press, checked, and open states, such as the switch thumb.
* **One-Shot Feedback (keyframes):** The 360ms nudge of an invalid [TextInput](/docs/components/text-input) or [OtpField](/docs/components/otp-field), and the 240ms pop of a [CopyButton](/docs/components/copy-button) check.

### Animate Transform and Opacity

Animate transforms, opacity, colors, shadows, and outlines, which change without a new layout. Animate size only when no transform produces the effect, as the components below do.

**Do:** Scale a pressed control to `scale: 'press'` with `ease.snappy`.

**Don't:** Animate `width`, `height`, or `margin` when a transform produces the same effect.

* **Accordion (height):** Panels grow to a measured height, not a transform.
* **SidebarMenu (height):** Nested items grow as a group expands.
* **Progress (width):** The indicator grows and keeps its rounded ends.
* **Tabs (size):** The indicator stretches to match each tab.
* **Switch (width):** The pressed thumb stretches to keep its round ends.
* **Toast (height):** Toasts shrink as their stack collapses.

### Never Delay Input

Controls respond on the first frame of a press. Don't hold an action until an animation finishes, and don't block the next interaction during an exit animation.

**Do:** Use short transitions that respond on the first frame, such as the library's press feedback.

```tsx
<MotionDemo kind="press" />
```

**Don't:** Make the reader wait for an animation to finish before they can act.

```tsx
<MotionDemo kind="slow" />
```

## Authoring Motion

Set each curve and duration by its token, and pair each transition with a reduced-motion override that removes movement and keeps color changes.

```tsx
import { style } from '@tempoxyz/ds'

namespace styles {
  export const row = style({
    transitionDuration: '160',
    transitionProperty: 'background-color, scale',
    transitionTimingFunction: 'snappy',
    selectors: {
      '&:active': { scale: 'press' },
      '&:hover': { backgroundColor: 'container.regular' },
    },
    '@media (prefers-reduced-motion: reduce)': {
      transitionProperty: 'background-color',
      selectors: { '&:active': { scale: 'none !custom' } },
    },
  })
}
```

* **Durations (transitionDuration):** Name a duration in ms, such as `'160'`.
* **Curves (transitionTimingFunction):** Name a curve, such as `'snappy'`.
* **Keyframes (vars.ease):** A keyframe shorthand reads its curve from `vars`.

## Reduced Motion

When the system asks for reduced motion, components remove movement and scaling, and keep instant changes or brief opacity fades. Apply the same rule in your own styles, and honor Reduce Motion on iOS and Android.

### What Components Change

* **Pressable Controls:** Buttons, surfaces, and other pressable controls stop scaling and keep their color transitions.
* **Overlays:** Popovers, menus, dialogs, and toasts fade in place, including the narrow-screen dialog sheet.
* **Moving Indicators:** The tabs indicator and the switch thumb jump straight to their final position.
* **Loading Indicators:** Spinners stop rotating, skeletons stop their sweep, and loading dots stop pulsing.
* **Feedback:** [CopyButton](/docs/components/copy-button) skips its pop, and invalid fields skip their nudge.

## Accessibility

[Accessibility](/docs/foundations/accessibility#motion) sets the limits for flashing and for content that moves on its own.

* **Never Motion Alone (Field.Error):** Never convey information through motion alone. Pair a nudge on an invalid field with an error message.

## Related

[Loading](/docs/patterns/loading)

Covers spinners, skeletons, and progress.

[Feedback and Status](/docs/patterns/feedback-and-status)

Covers toasts and confirmations.

[Accessibility](/docs/foundations/accessibility)

Covers reduced motion and other preferences.
