Morphing Dialog for React
A morphing dialog for React where a card grows into a modal: its image, title and surface fly into place with Motion's shared layout animation.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/morphing-dialog.jsonMorphingDialogMorphingDialogCloseMorphingDialogMediaMorphingDialogTitleMorphingDialogActions- +8 more
- +5 more
Gallery
Open a card, then close it with Escape, the × button or a click outside: everything flies back. Keep the media's aspect ratio the same in card and dialog.
import { Button } from "@/components/sheenui/button/button";
import { MorphingDialog, MorphingDialogActions, MorphingDialogContent, MorphingDialogDescription, MorphingDialogMedia, MorphingDialogSubtitle, MorphingDialogTitle, MorphingDialogTrigger } from "@/components/sheenui/morphing-dialog/morphing-dialog";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Button, MorphingDialog, MorphingDialogActions, MorphingDialogContent, MorphingDialogDescription, MorphingDialogMedia, MorphingDialogSubtitle, MorphingDialogTitle, MorphingDialogTrigger, useToast } from "@sheenui/theme";
// This example also uses button, toast: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json
const place = {
name: "Lisbon",
region: "Portugal",
gradient: "from-amber-300 to-rose-500",
body: "Seven hills, trams and pastel de nata.",
facts: [
["Best month", "May"],
["Flight from Delhi", "12 h"],
],
};
export function Example() {
const toast = useToast();
// One card per place, in a <ul className="grid gap-4 sm:grid-cols-3">.
return (
<MorphingDialog>
<MorphingDialogTrigger className="w-full p-2 pb-4">
<MorphingDialogMedia className="aspect-[4/3]">
<div aria-hidden className={`size-full bg-gradient-to-br ${place.gradient}`} />
</MorphingDialogMedia>
<MorphingDialogTitle className="px-2 pt-2">{place.name}</MorphingDialogTitle>
<MorphingDialogSubtitle className="px-2">{place.region}</MorphingDialogSubtitle>
</MorphingDialogTrigger>
<MorphingDialogContent className="p-3 pb-6">
<MorphingDialogMedia className="aspect-[4/3]">
<div aria-hidden className={`size-full bg-gradient-to-br ${place.gradient}`} />
</MorphingDialogMedia>
<div className="px-3 pt-4">
<MorphingDialogTitle>{place.name}</MorphingDialogTitle>
<MorphingDialogSubtitle>{place.region}</MorphingDialogSubtitle>
</div>
<MorphingDialogDescription className="flex flex-col gap-4 px-3 pt-3">
<p>{place.body}</p>
<dl className="grid grid-cols-2 gap-3">
{place.facts.map(([term, value]) => (
<div key={term} className="rounded-sheen-md bg-sheen-hover px-3 py-2">
<dt className="text-xs text-sheen-fg-muted">{term}</dt>
<dd className="font-medium text-sheen-fg">{value}</dd>
</div>
))}
</dl>
</MorphingDialogDescription>
{/* Controls go here, not in the description: each one fades itself in. */}
<MorphingDialogActions className="px-3 pt-4">
<Button onClick={() => toast.success(`${place.name} saved to your trips`)}>Plan a trip</Button>
</MorphingDialogActions>
</MorphingDialogContent>
</MorphingDialog>
);
}Files to copy
5 folders · 7 files · 4 packages
- From
theme/src/ components/morphing-dialog/hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}motion/{presets.ts, tokens.ts}lib/{cn.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/morphing-dialog.jsonRegistry item: morphing-dialog. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/avatar/components/button/components/spinner/components/toast/hooks/{use-direction.ts, use-latest.ts, use-magnetic.ts}motion/gate.tslib/{form.ts, initials.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/avatar.json https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Compact card
No picture: just the surface and the text morph. The dialog takes any content, and its glass level and radius are props. Buttons go in MorphingDialogActions, where each one (glass included) fades itself in.
import { Avatar } from "@/components/sheenui/avatar/avatar";
import { Button } from "@/components/sheenui/button/button";
import { MorphingDialog, MorphingDialogActions, MorphingDialogContent, MorphingDialogDescription, MorphingDialogSubtitle, MorphingDialogTitle, MorphingDialogTrigger } from "@/components/sheenui/morphing-dialog/morphing-dialog";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Avatar, Button, MorphingDialog, MorphingDialogActions, MorphingDialogContent, MorphingDialogDescription, MorphingDialogSubtitle, MorphingDialogTitle, MorphingDialogTrigger, useToast } from "@sheenui/theme";
// This example also uses avatar, button, toast: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/avatar.json https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json
export function Example() {
const toast = useToast();
return (
<MorphingDialog>
<MorphingDialogTrigger className="flex-row items-center gap-3 p-3 pe-5">
<Avatar name="Grace Hopper" />
<span className="flex flex-col">
<MorphingDialogTitle>Grace Hopper</MorphingDialogTitle>
<MorphingDialogSubtitle>Rear admiral · Compilers</MorphingDialogSubtitle>
</span>
</MorphingDialogTrigger>
<MorphingDialogContent className="max-w-md gap-1 p-6 pe-14">
<MorphingDialogTitle>Grace Hopper</MorphingDialogTitle>
<MorphingDialogSubtitle>Rear admiral · Compilers</MorphingDialogSubtitle>
<MorphingDialogDescription className="mt-3">
Wrote the first compiler and helped design COBOL, so programs could be written in words
instead of machine code. She kept a moth taped in her logbook: the first actual bug.
</MorphingDialogDescription>
<MorphingDialogActions className="mt-4">
<Button size="sm" onClick={() => toast.success("Following Grace Hopper")}>Follow</Button>
<Button size="sm" variant="glass" onClick={() => toast.info("Message drafted")}>Message</Button>
</MorphingDialogActions>
</MorphingDialogContent>
</MorphingDialog>
);
}MorphingDialog props
MorphingDialogTrigger props
MorphingDialogContent props
MorphingDialogLabels keys and English defaults (1)
Parts
MorphingDialogActions props
MorphingDialogClose props
MorphingDialogDescription props
MorphingDialogMedia props
MorphingDialogSubtitle props
MorphingDialogTitle props
Keyboard
Accessibility
- The card is a native button with aria-haspopup="dialog"; the dialog is role="dialog", labeled by MorphingDialogTitle and described by MorphingDialogDescription. Always render a title.
- Controls go in MorphingDialogActions, which fades each one in after the flight.
- Under reduced motion the flight is removed and the dialog only fades; describe informative media with alt.
All exports on this page
MorphingDialog— Morphing dialog: a card that grows into a dialog.MorphingDialogActions— The dialog's buttons and other controls (a row by default).MorphingDialogClose— The × button (added automatically by MorphingDialogContent unless showClose={false}).MorphingDialogContent— The dialog.MorphingDialogDescription— Text that only exists in the dialog.MorphingDialogMedia— The picture (an <img>, a video poster, artwork) that flies from the card into the dialog.MorphingDialogSubtitle— A line under the title (place, author, price) that also moves from the card into the dialog.MorphingDialogTitle— The title.MorphingDialogTrigger— The card.defaultMorphingDialogLabels— The English MorphingDialogLabels used when labels is omitted; a partial labels prop is merged over it.
When to use the morphing dialog effect
- Use it as a card to modal animation for gallery and product cards that open into detail, where the picture, title and subtitle fly from the card into the dialog instead of a modal appearing from nowhere.
- Use it for a portfolio grid, a travel destination list or a recipe index, composing MorphingDialogTrigger with MorphingDialogContent and the shared Media, Title, Subtitle, Description and Actions pieces.
- Keep the media's aspect ratio the same in the card and in the dialog, otherwise the shared image stretches during the flight and the morph looks unclean.
- Skip it when the dialog is a form or a confirmation with no card to grow from; use Dialog for those, since a morph only makes sense when the trigger visibly becomes the content.
- Pair it with Button inside MorphingDialogActions so each control fades itself, Badge for a category label on the card, and GlassCard grids to lay the triggers out.
Frequently asked questions
Related pages
Guides that cover it
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .