Morphic Card Modal
1 バリエーション
A card that morphs into a full dialog and back, keeping its rounded corners, with focus trapping, scroll lock, and keyboard opening.
Courtyard house
Lisbon · $210 a night
Terrace home
Mallorca · $340 a night
Garden house
Melbourne · $280 a night
TSXcomponents/previews/premium/morphic-card-modal-preview.tsx
"use client";
import { MapPin, Users, X } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/motion/button";
import { Tooltip } from "@/components/motion/tooltip";
import {
MorphicCard,
MorphicCardModal,
MorphicCardModalDescription,
MorphicCardModalTitle,
} from "@/components/premium/morphic-card-modal";
const photo = (id: string) =>
`https://images.unsplash.com/photo-${id}?auto=format&fit=crop&fm=webp&q=80&w=800`;
const STAYS = [
{
id: "courtyard",
name: "Courtyard house",
place: "Lisbon",
price: 210,
guests: 4,
image: photo("1600566753190-17f0baa2a6c3"),
alt: "Warm modern courtyard framed by timber",
about:
"A timber courtyard home with a shaded patio, two bedrooms, and a quiet street ten minutes from the river.",
},
{
id: "terrace",
name: "Terrace home",
place: "Mallorca",
price: 340,
guests: 6,
image: photo("1600585154340-be6161a56a0c"),
alt: "Modern home opening onto a green terrace",
about:
"Glass walls open onto a planted terrace and pool, with three bedrooms and a kitchen built for long dinners.",
},
{
id: "garden",
name: "Garden house",
place: "Melbourne",
price: 280,
guests: 4,
image: photo("1600047509807-ba8f99d2cdde"),
alt: "Brick and glass house behind a front lawn",
about:
"A brick and glass house on a quiet street, with a lawn out front, a sunny reading room, and bikes to borrow.",
},
];
export function MorphicCardModalPreview() {
const [openId, setOpenId] = useState<string | null>(null);
const stay = STAYS.find((item) => item.id === openId) ?? null;
return (
<div className="grid w-full max-w-2xl grid-cols-1 gap-3 px-4 sm:grid-cols-3">
{STAYS.map((item) => (
<MorphicCard
key={item.id}
id={item.id}
label={`${item.name}, ${item.place}`}
onClick={() => setOpenId(item.id)}
className="border border-border bg-background transition-colors hover:border-foreground/20"
>
{/* biome-ignore lint/performance/noImgElement: remote Unsplash photo in a preview. */}
<img
src={item.image}
alt=""
className="aspect-4/3 w-full object-cover"
/>
<div className="space-y-0.5 p-3">
<p className="font-medium text-sm">{item.name}</p>
<p className="text-muted-foreground text-xs">
{item.place} · ${item.price} a night
</p>
</div>
</MorphicCard>
))}
<MorphicCardModal
id={stay?.id ?? ""}
open={Boolean(stay)}
onClose={() => setOpenId(null)}
className="max-w-md border border-border bg-background"
>
{stay ? (
<>
<div className="relative">
{/* biome-ignore lint/performance/noImgElement: remote Unsplash photo in a preview. */}
<img
src={stay.image}
alt={stay.alt}
className="aspect-16/10 w-full object-cover"
/>
<Tooltip
content="Close"
side="bottom"
wrapperClassName="absolute top-3 right-3"
>
<Button
size="icon"
variant="secondary"
aria-label="Close"
onClick={() => setOpenId(null)}
className="size-8 border-0 bg-background/80 backdrop-blur"
>
<X aria-hidden="true" className="size-4" />
</Button>
</Tooltip>
</div>
<div className="space-y-4 p-5">
<div>
<MorphicCardModalTitle className="font-medium text-xl">
{stay.name}
</MorphicCardModalTitle>
<p className="mt-1 flex items-center gap-3 text-muted-foreground text-xs">
<span className="inline-flex items-center gap-1">
<MapPin aria-hidden="true" className="size-3.5" />
{stay.place}
</span>
<span className="inline-flex items-center gap-1">
<Users aria-hidden="true" className="size-3.5" />
Up to {stay.guests} guests
</span>
</p>
</div>
<MorphicCardModalDescription className="text-muted-foreground text-sm">
{stay.about}
</MorphicCardModalDescription>
<div className="flex items-center justify-between gap-3 border-border border-t pt-4">
<p className="text-sm">
<span className="font-medium">${stay.price}</span>
<span className="text-muted-foreground"> a night</span>
</p>
<Button size="sm" className="h-9 px-4 text-sm">
Check dates
</Button>
</div>
</div>
</>
) : null}
</MorphicCardModal>
</div>
);
}
インストール
shadcn CLI でこのコンポーネントを追加します。
$ bunx --bun shadcn add @beui-pro/morphic-card-modal