nook
Browse the docs

Components

Motion

Native

Shared motion preference, animation timing and a visible playback control.

See the prompt

Effects are paused.

  • A marker sliding across a track
  • A live indicator that pulses
  • A square-dot loader that turns

If your system asks for reduced motion, everything starts paused and the button is disabled.

Installation

npx nook-ui@latest add motion

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Motion" component to this project, exactly as Nook ships it.

Shared motion preference, animation timing and a visible playback control.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add motion`. It writes `components/ui/motion.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/motion.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";

import * as React from "react";
import { MotionControl, useReducedMotion } from "@/components/ui/motion";

/** Three effects that run forever. The button pauses all of them at once. */
export default function MotionDefault() {
  const [paused, setPaused] = React.useState(false);
  const reduced = useReducedMotion();
  const state = paused || reduced ? "paused" : "running";
  return (
    <div className="grid w-full max-w-md gap-4">
      <style>{`
        @keyframes nook-demo-slide { from { transform: translateX(0) } to { transform: translateX(calc(100% - 1.5rem)) } }
        @keyframes nook-demo-pulse { 0%, 100% { opacity: 1; transform: scale(1) } 50% { opacity: .35; transform: scale(.7) } }
        @keyframes nook-demo-spin { to { transform: rotate(360deg) } }
      `}</style>
      <div className="flex flex-wrap items-center justify-between gap-3">
        <p role="status" className="text-sm text-muted-foreground">Effects are {state}.</p>
        <MotionControl paused={paused} onPausedChange={setPaused} label="effects" />
      </div>
      <ul className="grid gap-3 text-sm">
        <li className="grid gap-1.5">
          <span>A marker sliding across a track</span>
          <span aria-hidden="true" className="block h-6 overflow-hidden bg-muted">
            <span style={{ animation: "nook-demo-slide 1.8s ease-in-out infinite alternate", animationPlayState: state }} className="block size-6 bg-brand" />
          </span>
        </li>
        <li className="flex items-center gap-3">
          <span aria-hidden="true" style={{ animation: "nook-demo-pulse 1.2s ease-in-out infinite", animationPlayState: state }} className="size-3 bg-brand" />
          A live indicator that pulses
        </li>
        <li className="flex items-center gap-3">
          <span aria-hidden="true" style={{ animation: "nook-demo-spin 1.4s linear infinite", animationPlayState: state }} className="grid size-6 grid-cols-2 gap-0.5">
            <span className="bg-foreground" /><span className="bg-foreground/30" /><span className="bg-foreground/30" /><span className="bg-brand" />
          </span>
          A square-dot loader that turns
        </li>
      </ul>
      <p className="text-xs text-muted-foreground">If your system asks for reduced motion, everything starts paused and the button is disabled.</p>
    </div>
  );
}
```

API
- `MotionControl`: Shared motion preference, animation timing and a visible playback control.
  - `paused` (`boolean`): Whether playback is paused.
  - `onPausedChange` (`(paused: boolean) => void`): Respond to the playback button.
  - `label` (`string`): Name of the effect in the button label.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The native playback button is disabled when reduced motion is preferred. Preference changes are observed after hydration.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";

import * as React from "react";
import { MotionControl, useReducedMotion } from "@/components/ui/motion";

/** Three effects that run forever. The button pauses all of them at once. */
export default function MotionDefault() {
  const [paused, setPaused] = React.useState(false);
  const reduced = useReducedMotion();
  const state = paused || reduced ? "paused" : "running";
  return (
    <div className="grid w-full max-w-md gap-4">
      <style>{`
        @keyframes nook-demo-slide { from { transform: translateX(0) } to { transform: translateX(calc(100% - 1.5rem)) } }
        @keyframes nook-demo-pulse { 0%, 100% { opacity: 1; transform: scale(1) } 50% { opacity: .35; transform: scale(.7) } }
        @keyframes nook-demo-spin { to { transform: rotate(360deg) } }
      `}</style>
      <div className="flex flex-wrap items-center justify-between gap-3">
        <p role="status" className="text-sm text-muted-foreground">Effects are {state}.</p>
        <MotionControl paused={paused} onPausedChange={setPaused} label="effects" />
      </div>
      <ul className="grid gap-3 text-sm">
        <li className="grid gap-1.5">
          <span>A marker sliding across a track</span>
          <span aria-hidden="true" className="block h-6 overflow-hidden bg-muted">
            <span style={{ animation: "nook-demo-slide 1.8s ease-in-out infinite alternate", animationPlayState: state }} className="block size-6 bg-brand" />
          </span>
        </li>
        <li className="flex items-center gap-3">
          <span aria-hidden="true" style={{ animation: "nook-demo-pulse 1.2s ease-in-out infinite", animationPlayState: state }} className="size-3 bg-brand" />
          A live indicator that pulses
        </li>
        <li className="flex items-center gap-3">
          <span aria-hidden="true" style={{ animation: "nook-demo-spin 1.4s linear infinite", animationPlayState: state }} className="grid size-6 grid-cols-2 gap-0.5">
            <span className="bg-foreground" /><span className="bg-foreground/30" /><span className="bg-foreground/30" /><span className="bg-brand" />
          </span>
          A square-dot loader that turns
        </li>
      </ul>
      <p className="text-xs text-muted-foreground">If your system asks for reduced motion, everything starts paused and the button is disabled.</p>
    </div>
  );
}

Examples

A one-off effect

Invoice sent

Northwind Coffee will get it in a minute.

Fades up 12 px over the theme's motion time. Not played with reduced motion.

Props

MotionControl

Shared motion preference, animation timing and a visible playback control.

PropTypeDefaultDescription
pausedboolean–Whether playback is paused.
onPausedChange(paused: boolean) => void–Respond to the playback button.
labelstring–Name of the effect in the button label.

Accessibility

The native playback button is disabled when reduced motion is preferred. Preference changes are observed after hydration.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.