A responsive, zero-dependency expanding editorial gallery with smooth flex proportions, keyboard navigation via roving tabindex, and clean typography.
$ npx shadcn@latest add https://akshitr.com/r/expandable-cards.json
import ExpandableCards from "@/components/expandable-cards";
export default function Example() {
return (
<ExpandableCards
defaultIndex={2}
expandedFlex={5.2}
collapsedFlex={1}
height="h-[480px]"
/>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
items | ExpandableCardItem[] | DEFAULT_ITEMS | List of items with src, alt, title, and optional tags. |
defaultIndex | number | 2 | Index of the card expanded by default on first mount. |
expandedFlex | number | 5.2 | CSS flex proportion assigned to the active expanded card. |
collapsedFlex | number | 1 | CSS flex proportion assigned to the collapsed sliver cards. |
height | string | "h-[480px]" | Tailwind height utility class for the gallery track. |
onSelect | (index: number, item: ExpandableCardItem) => void | - | Callback fired when a card is clicked or keyboard-navigated. |