# Morph Panel

> A React button that morphs into the panel it opens on a spring, blurring the label out and the form in. Ships with a feedback form and closes on Escape.

- Kind: Component (Motion)
- Docs: https://ui.minidev.pro/docs/morph-panel
- Source (registry JSON with the full file): https://ui.minidev.pro/r/morph-panel.json
- License: MIT. One file, yours to edit after install.

## When to use

One surface grows from a pill into a panel, its corners easing from 10 to 16px, while the label blurs out and the content blurs in. No popover, no jump. Escape and an outside click close it and focus returns to the trigger; with reduced motion it swaps instantly. Default content is a feedback form with a sent state; pass a render function as `children` for your own panel. For a plain anchored panel use Popover; for a modal use Dialog.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/morph-panel
```

Writes `components/ui/morph-panel.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/morph-panel.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { MorphPanel } from "@/components/ui/morph-panel"
```

From the npm package:

```tsx
import { MorphPanel } from "minidev-ui-kit/ui/morph-panel"
```

## Usage

```tsx
import { MorphPanel } from "@/components/ui/morph-panel"

export function Example() {
  return (
    <MorphPanel />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `label` | `React.ReactNode` | `"Feedback"` | no | Trigger text; also the panel's accessible name when it is a string. |
| `icon` | `React.ReactNode` | `<MessageSquareIcon />` | no | Icon before the label. |
| `width` | `number` | `340` | no | Panel width in px. |
| `anchor` | `Anchor` | `"top-left"` | no | Which corner of the trigger the panel grows from. |
| `open` | `boolean` | - | no | Controlled open state. |
| `defaultOpen` | `boolean` | `false` | no | Initial open state when uncontrolled. |
| `onOpenChange` | `(open: boolean) => void` | - | no | Fires when the panel opens or closes. |
| `children` | `(api: { close: () => void }) => React.ReactNode` | - | no | Custom panel as a render function. Receives close(), which also returns focus to the trigger. |
| `onSubmit` | `(text: string) => void \| Promise<void>` | - | no | Called with the text by the default feedback form. Return a promise to show "Sending…"; reject to let the user retry. |
| `className` | `string` | - | no |  |

## Examples

### Feedback with an async submit

Return a promise from onSubmit (here a 900ms stand-in for your API call) to show "Sending…"; a rejected promise puts the form back so the user can retry.

```tsx
<MorphPanel label="Feedback" onSubmit={() => new Promise<void>((resolve) => setTimeout(resolve, 900))} />
```

### Your own panel

Pass a render function; close() shuts the panel and returns focus to the trigger.

```tsx
<MorphPanel label="New note" icon={<StickyNoteIcon />} width={300}>
  {({ close }) => (
    <form
      className="space-y-3 p-4"
      onSubmit={(e) => {
        e.preventDefault()
        close()
      }}
    >
      <Input autoFocus aria-label="Note" placeholder="Call Northwind about the renewal" />
      <div className="flex justify-end gap-2">
        <Button type="button" variant="ghost" size="sm" onClick={close}>
          Cancel
        </Button>
        <Button type="submit" size="sm">
          Save note
        </Button>
      </div>
    </form>
  )}
</MorphPanel>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Enter` or `Space` | On the trigger, opens the panel. |
| `Escape` | Closes the panel and returns focus to the trigger. |
| `Meta+Enter` or `Ctrl+Enter` | In the feedback textarea, sends the note. |
| `Tab` | Moves through the fields and buttons in the panel. Focus is not trapped. |

## Accessibility

- The open panel has `role="dialog"` and an `aria-label` from `label` when it is a string, or "Panel" otherwise. It is not modal and has no `aria-modal`.
- Escape returns focus to the trigger. An outside click closes it and leaves focus where the user clicked.
- The textarea has `aria-label="Feedback"` and `maxLength={500}`. The "Sent" message renders inside an `aria-live="polite"` element that mounts together with its text, so some screen readers may not announce it.
- Under reduced motion the pill and panel swap instantly.

## FAQ

### How do I put my own form inside MorphPanel?

Pass a render function as `children`: `<MorphPanel label="New note" width={300}>{({ close }) => <NoteForm onDone={close} />}</MorphPanel>`. Calling `close()` shuts the panel and returns focus to the trigger. Focus your first field yourself; only the built-in feedback form focuses its textarea on open.

### How do I send the built-in feedback form to my API?

Pass `onSubmit`, which receives the text. Return a promise to show "Sending…"; if it rejects, the form goes back to idle so the user can retry, but no error message is shown. The panel closes itself 1.5s after the "Sent" state.

### Can I open MorphPanel from outside, or control it?

Yes. Pass `open` and `onOpenChange` to control it, or `defaultOpen` for the first render. `anchor` picks the trigger corner the panel grows from, for example `"bottom-right"` for a button in the bottom-right of the screen.

### How is it different from Popover or Dialog?

The trigger itself grows into the panel, and nothing else on the page is blocked. There is no focus trap and no backdrop. Use [`Popover`](https://ui.minidev.pro/docs/popover) for a panel anchored beside its trigger, and [`Dialog`](https://ui.minidev.pro/docs/dialog) when the rest of the page must wait.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`

## Related

- [Popover](https://ui.minidev.pro/docs/popover/md): A floating React panel anchored to a trigger, built on Base UI with side and align options, collision aware positioning, title and description parts.
- [Dialog](https://ui.minidev.pro/docs/dialog/md): Shadcn compatible modal dialog on Base UI with a blurred backdrop, enter and exit animation, close button, header, title, description and a footer bar.
- [Light Provider](https://ui.minidev.pro/docs/light-provider/md): A page wide light source that follows the pointer and drifts when idle, driving shadows via CSS variables, plus a hairline, glass, metal and paper switcher.
- [Marquee](https://ui.minidev.pro/docs/marquee/md): An infinitely scrolling Tailwind strip that loops its children horizontally, duplicated for a gapless cycle, and stops when users prefer reduced motion.
- [Number Roll](https://ui.minidev.pro/docs/number-roll/md): An odometer style animated number where each digit rolls on a spring and only changed digits move. Supports Intl formatting, trend tint and reduced motion.
- [Split Flap](https://ui.minidev.pro/docs/split-flap/md): Split-flap display that flips each character through the alphabet like a departure board, with a column ripple, tones, sizes and reduced motion support.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
