Components / Cards
Expandable Cards
Cards that smoothly morph into a full dialog when clicked, using shared layout animation.
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/expandable-cards.tsx. - 3
Use it
example.tsximport { ExpandableCards } from "@/components/ui/expandable-cards"; const trips = [ { id: "alps", title: "Swiss Alps", subtitle: "Hiking · 7 days", cover: "linear-gradient(135deg, #38bdf8, #6366f1)", content: "Glacier lakes, high passes and cosy mountain huts. Best from June to September.", }, { id: "kyoto", title: "Kyoto", subtitle: "Culture · 5 days", cover: "linear-gradient(135deg, #fb7185, #f59e0b)", content: "Temples, tea houses and lantern-lit streets. Go in spring for the cherry blossoms.", }, { id: "sahara", title: "Sahara", subtitle: "Adventure · 4 days", cover: "linear-gradient(135deg, #fbbf24, #ea580c)", content: "Camel treks over golden dunes and nights under more stars than you can count.", }, { id: "iceland", title: "Iceland", subtitle: "Road trip · 10 days", cover: "linear-gradient(135deg, #2dd4bf, #0f766e)", content: "Waterfalls, black-sand beaches and, if you're lucky, the northern lights.", }, ]; export default function ExpandableCardsDemo() { return <ExpandableCards items={trips} className="max-w-md" />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items | { id; title; subtitle?; cover; content }[] | — | Cards to show. cover is any CSS background. |
| className | string | — | Classes for the grid. |