Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

6.1 KB
Raw Blame
---
title: Button
description: A button whose visual state is a pure function of the timeline
component: button
vibe: clean
length: 120
useWhen:
  - "Showing the full interactive lifecycle of a CTA — hover → press → loading → success — on the timeline."
  - "A composition needs a trigger visual for a modal-layer primitive (`dialog`, `alert-dialog`, `drawer`)."
  - "Demonstrating a loading/submit state with a spinner inline inside the button."
avoidWhen:
  - "You need a selectable row inside a menu — use `dropdown-menu-item` or `command-menu-item` instead."
  - "The button must open a searchable dropdown — use `combobox` (which uses an input trigger) instead."
  - "You only need a static label with no interactive state — render plain text in the composition."
askedAs:
  - "button"
  - "button click animation"
  - "I want a CTA button that shows hover, press and loading states"
  - "show a button being pressed and processing"
  - "UI beat highlighting the main call to action"
  - "submit button demo with loading spinner and done state"
---

<UiComponentPreview name="button" />

A state atom whose appearance (idle, hover, press, loading, success) is a pure function of the `state` prop. Pass a state directly or drive it from the Remotion timeline via `useCurrentState`. The component reads no frame — only the state value you give it.

<InstallBlock name="button" />

<Note>
Installing `button` automatically installs `spinner` and the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies`. You do not need to install either separately.
</Note>

## States

`ButtonState` is:

```ts
type ButtonState =
  | "idle"     // resting
  | "hover"    // lifted + background shift
  | "press"    // scale down + darken
  | "loading"  // renders <Spinner />
  | "success"  // renders a static checkmark, background fills primary
```

`loading` composes `<Spinner />` in place of the label. `success` renders a static checkmark SVG. Both `loading` and `success` hide the label text.

## Snap usage (simple path)

Pass `state` directly — the component snaps instantly to that visual. Useful for static previews or when you drive state from your own logic:

```tsx
import { Button } from "@/components/remocn/button";

export const Scene = () => <Button state="loading" />;
```

To drive state from the timeline, use `useCurrentState`:

```tsx
import { useCurrentState } from "@/lib/remocn-ui";
import { Button } from "@/components/remocn/button";

export const Scene = () => {
  const state = useCurrentState(
    [
      { at: 8,  state: "hover" },
      { at: 20, state: "press" },
      { at: 35, state: "loading" },
      { at: 70, state: "success" },
    ],
    "idle",
  );

  return <Button label="Continue" state={state} />;
};
```

Each `at` is a **Sequence-local authored frame**. State persists between steps: `hover` at frame 8 keeps the button lifted until `press` fires at frame 20. See [Concepts](/docs/ui/concepts) for the full `useCurrentState` API.

## Smooth transitions (opt-in)

State changes via `state` snap with no cross-fade. For animated transitions, use `useButtonTransition` from the copied `use-button-transition.ts` file. It reads the frame, interpolates between state presets, and returns a resolved `ButtonStyle` — pass it to the `style` prop:

```tsx
import { Button } from "@/components/remocn/button";
import { useButtonTransition } from "@/components/remocn/use-button-transition";

export const Scene = () => {
  const style = useButtonTransition([
    { at: 12, state: "hover" },
    { at: 30, state: "press" },
    { at: 48, state: "loading", duration: 6 },
    { at: 96, state: "success", duration: 16 },
  ]);
  return <Button label="Continue" style={style} />;
};
```

The `duration` field on each step overrides the file's `DEFAULT_DURATION` for that specific transition. To globally tune timing and easing, edit `use-button-transition.ts` directly in your project — that file is yours (shadcn "own your code" philosophy).

`style` takes precedence over `state` when both are provided.


<PropsTable title="Props"
  rows={[
    {
      name: "state",
      type: "\"idle\" | \"hover\" | \"press\" | \"loading\" | \"success\"",
      default: "\"idle\"",
      description: "Current visual state (snap path). State changes snap — no automatic cross-fade.",
    },
    {
      name: "style",
      type: "ButtonStyle",
      description: "Resolved animated visual (smooth path). Pass an interpolated ButtonStyle from useButtonTransition. Takes precedence over state when provided.",
    },
    {
      name: "label",
      type: "string",
      default: "\"Continue\"",
      description: "Button label text. Hidden during loading and success states.",
    },
    {
      name: "variant",
      type: "\"default\" | \"secondary\" | \"destructive\" | \"outline\" | \"ghost\"",
      default: "\"default\"",
      description: "Visual variant. Matches shadcn button variant names.",
    },
    {
      name: "size",
      type: "\"sm\" | \"default\" | \"lg\"",
      default: "\"default\"",
      description: "Button height and padding. sm=32px, default=40px, lg=48px.",
    },
    {
      name: "theme",
      type: "Partial<RemocnTheme>",
      description: "Per-component theme override. Merges with the active RemocnUIProvider theme and the mode defaults. Must be concrete oklch/hex/rgb values — not CSS custom properties.",
    },
    {
      name: "mode",
      type: "\"light\" | \"dark\"",
      default: "\"light\"",
      description: "Sets the base palette. Overrides the mode on RemocnUIProvider when both are present.",
    },
    {
      name: "primary",
      type: "string",
      description: "Convenience override for the primary theme token. Merged into theme — saves a theme object for single-token changes.",
    },
    {
      name: "speed",
      type: "number",
      default: "1",
      description: "Forwarded to the loading Spinner. Scales the spinner playhead — speed=2 spins twice as fast without changing authored step times.",
    },
    {
      name: "className",
      type: "string",
      description: "Optional className passed to the inner <button> element.",
    },
  ]}
/>