# Transition Panel

> Swap between panels with a directional slide while the container springs to each panel's height.

Source: https://www.honestui.com/docs/animated/transition-panel

```tsx
"use client";

import { useState } from "react";

import { TransitionPanel } from "@/registry/default/animated/transition-panel";
import { cn } from "@/lib/utils";

const steps = [
  {
    label: "Account",
    title: "Create your workspace",
    body: "Pick a name your team will recognize. You can change it later in settings.",
  },
  {
    label: "Invite",
    title: "Invite your team",
    body: "Add teammates by email. They get access as soon as they accept, and you can set their role from the members page at any time.",
  },
  {
    label: "Connect",
    title: "Connect a repository",
    body: "Link a Git provider so deploys run on every push to main.",
  },
];

export function TransitionPanelDemo() {
  const [active, setActive] = useState(0);

  return (
    <div className="flex w-full max-w-sm flex-col gap-4">
      <div role="group" aria-label="Setup step" className="flex gap-1 rounded-lg bg-muted p-1">
        {steps.map((step, index) => (
          <button
            key={step.label}
            type="button"
            aria-pressed={active === index}
            onClick={() => setActive(index)}
            className={cn(
              "h-8 flex-1 cursor-pointer rounded-md text-sm font-medium text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
              active === index && "bg-background text-foreground shadow-sm ring-1 ring-border/60 dark:bg-foreground/10 dark:ring-0",
            )}
          >
            {step.label}
          </button>
        ))}
      </div>
      <TransitionPanel activeIndex={active} className="rounded-xl border border-border bg-card">
        {steps.map((step) => (
          <div key={step.label} className="flex flex-col gap-1.5 p-5">
            <h3 className="text-sm font-medium text-foreground">{step.title}</h3>
            <p className="text-sm leading-relaxed text-muted-foreground">{step.body}</p>
          </div>
        ))}
      </TransitionPanel>
    </div>
  );
}

```

## Overview [#overview]

Transition Panel shows one of several panels at a time. When the active index changes, the outgoing panel slides and blurs away in the direction of travel, the incoming one slides in from the other side, and the container springs to the new panel's height so content below moves smoothly. Use it for steppers, segmented views, and settings sections whose panels differ in length.

## Installation [#installation]

<CliBlock commands="[&#x22;transition-panel&#x22;]" />

## Usage [#usage]

```tsx
import { TransitionPanel } from "@/components/animated/transition-panel"

const [active, setActive] = useState(0)

<TransitionPanel activeIndex={active}>
  <div>Account</div>
  <div>Invite</div>
  <div>Connect</div>
</TransitionPanel>
```

Pass your own `variants` with `enter`, `center`, and `exit` keys to change the motion. Each variant can be a function of the direction, which is `1` when moving to a later panel and `-1` when moving back.

## Accessibility [#accessibility]

Transition Panel only animates; it does not add roles. When the panels belong to a tab-like control, give the control `role="tablist"` semantics or use [Animated Tabs](/docs/animated/animated-tabs). With reduced motion enabled, panels cross-fade and the height changes immediately.

## API Reference [#api-reference]


  ### `activeIndex`

type: `number`

Index of the visible panel.

  ### `children`

type: `ReactNode`

One child per panel.

  ### `variants`

type: `Variants`

Variants with 

    `enter`

    , 

    `center`

    , and 

    `exit`

     keys. Defaults to a directional slide with a blur.

  ### `transition`

type: `Transition`

Transition for panel enter and exit.

  ### `animateHeight`

type: `boolean` · default: `true`

Springs the container between panel heights.

  ### `className`

type: `string`

Classes for the container.

  ### `panelClassName`

type: `string`

Classes for the wrapper around each panel.
