Morph modal
A reusable modal component that smoothly "morphs" from the dimensions and position of its trigger element
Current Theme:
API usage
components/morph-modal.demo.tsx
"use client";
import { PlayIcon } from "lucide-react";
import {
MorphModal,
MorphModalTrigger,
MorphModalContent,
MorphModalOverlay,
} from "@/components/morph-modal";
export function MorphModalDemo() {
return (
<MorphModal transition={{ ease: "easeInOut" }}>
<MorphModalTrigger className="bg-secondary text-secondary-foreground border-border/50 rounded-full border px-3.5 py-2">
<div className="flex items-center gap-1.5">
Watch demo
<PlayIcon className="fill-foreground stroke-foreground bg-background box-content size-3.5 rounded-full p-1" />
</div>
</MorphModalTrigger>
<MorphModalOverlay className="z-50">
<MorphModalContent className="bg-muted border-border/50 m-2 rounded-xl border p-1">
<iframe
className="aspect-[560/315] max-w-full rounded-lg"
width="768px"
height="auto"
src="https://www.youtube.com/embed/aWBiZc5XKJM?si=muuRWjXzomYeoQ2K"
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerPolicy="strict-origin-when-cross-origin"
allowFullScreen
/>
</MorphModalContent>
</MorphModalOverlay>
</MorphModal>
);
}
Installation
CLI (recommended)
1
Run the command below to add the component to your project.
It will also generate the required base stylesheet if one doesn't already exist and guide you through setting up the import alias
@/components/... if it isn't already configured.pnpm dlx shadcn@latest add https://100xui.com/components/morph-modal.jsonManual
1
pnpm add clsx motion tailwind-merge2
100xui
components/morph-link.tsx
3
API reference
<MorphModal/>
| Props | Type | Description | Default value |
|---|---|---|---|
children | | React nodes that will be rendered inside the MorphModal as children. This typically includes the MorphModalTrigger and the MorphModalOverlay. | |
| transition? | | Object that defines the animation properties for the morphing transition except | |
<MorphModalTrigger/>
| Props | Type | Description | Default value |
|---|---|---|---|
children | | The single child element to be rendered inside the trigger, such as text, an icon, or a single nested component. | |
| ...rest | | Any standard React button props, like onClick handlers or disabled states, which will be applied directly to the button | |
<MorphModalOverlay/>
| Props | Type | Description | Default value |
|---|---|---|---|
children | | The content to be rendered inside the overlay. This should typically be the MorphModalContent component. | |
| ...rest | | Any standard React div props, like id, style or className, which will be applied directly to the component's root element. | |
<MorphModalContent/>
| Props | Type | Description | Default value |
|---|---|---|---|
children | | The single child element to be displayed inside the modal (e.g., text, videos, forms, or custom components). | |
| ...rest | | Any standard React div props, like id, style or className, which will be applied directly to the component's root element. | |