Morph Popover

A panel that unfolds from the corner nearest its trigger on a spring.

Preview

"use client";

import { ChevronDown, Copy, Pencil, Share2, Trash2 } from "lucide-react";
import { useState } from "react";
import {
  MorphPopover,
  MorphPopoverContent,
  MorphPopoverTrigger,
} from "@/components/motion/popover-morph";

const ACTIONS = [
  { icon: Pencil, label: "Edit" },
  { icon: Copy, label: "Duplicate" },
  { icon: Share2, label: "Share" },
  { icon: Trash2, label: "Delete" },
];

export function MorphPopoverPreview() {
  const [open, setOpen] = useState(false);

  return (
    <MorphPopover open={open} onOpenChange={setOpen}>
      <MorphPopoverTrigger>
        <button
          type="button"
          className="inline-flex h-10 items-center gap-2 rounded-full border border-border bg-background px-4 text-sm font-medium text-foreground outline-none transition-colors hover:border-border-strong focus-visible:ring-2 focus-visible:ring-ring"
        >
          Options
          <ChevronDown className="h-4 w-4 text-muted-foreground" />
        </button>
      </MorphPopoverTrigger>

      <MorphPopoverContent align="start" className="w-48 p-2">
        {ACTIONS.map(({ icon: Icon, label }) => (
          <button
            key={label}
            type="button"
            onClick={() => setOpen(false)}
            className="flex w-full items-center gap-2.5 rounded-full px-3 py-1.5 text-left text-sm text-foreground outline-none transition-colors hover:bg-muted focus-visible:bg-muted"
          >
            <Icon className="h-4 w-4 text-muted-foreground" />
            {label}
          </button>
        ))}
      </MorphPopoverContent>
    </MorphPopover>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/popover-morph

API Reference

MorphPopover

open?
boolean

Controlled open state.

Default—
defaultOpen?
boolean

Uncontrolled initial open state.

Defaultfalse
onOpenChange?
((open: boolean) => void)

Called with the new open state when the panel opens or closes.

Default—
className?
string

Classes merged onto the wrapper around the trigger.

Default—

MorphPopoverContent

side?
"top" | "bottom"

Preferred side of the trigger. Flips when there is no room. Default: "bottom"

Default—
align?
"end" | "start"

Lines the panel up with the trigger's start or end edge. Default: "end"

Default—
sideOffset?
number

Gap between trigger and panel, in px. Default 8.

Default—
radius?
number

Panel corner radius, in px. Default 16 (rounded-2xl), like every floating panel.

Default—
shadow?
boolean

Draw the surface shadow. Default true.

Default—
onOpenAutoFocus?
((content: HTMLDivElement) => void)

Runs after the portalled surface is positioned and visible. Passing it hands focus to the caller: the panel then moves no focus on its own.

Default—
initialFocus?
RefObject<HTMLElement | null>

Element to focus when the trigger opens the panel by keyboard. Defaults to the first focusable element in the panel, or the panel itself. A pointer open does not move focus. Ignored with `onOpenAutoFocus`.

Default—
className?
string

Classes merged onto the panel surface.

Default—

More in Popover

Updated