Focus Cards
Hover over a card to focus on it, softly blurring the rest of the cards.
Focus Cards
A grid of image cards where hovering over one card brings it into sharp focus while the rest softly blur and scale down.
Installation
npm install next reactpnpm install next reactyarn add next reactbun add next reactnpx install next reactUsage
FocusCards renders an array of cards. Each Card object contains a title and an src (image URL).
"use client";
import { FocusCards } from "@/components/mvpblocks/cards/focus-cards/focus-cards";
const cards = [
{
title: "Forest Adventure",
src: "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?q=80&auto=format&fit=crop&w=600",
},
{
title: "Valley of life",
src: "https://images.unsplash.com/photo-1500534314209-a25ddb2bd429?q=80&auto=format&fit=crop&w=600",
},
{
title: "Sala behta hi jayega",
src: "https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?q=80&auto=format&fit=crop&w=600",
},
{
title: "Camping is for pros",
src: "https://images.unsplash.com/photo-1504280390367-361c6d9f38f4?q=80&auto=format&fit=crop&w=600",
},
{
title: "The road not taken",
src: "https://images.unsplash.com/photo-1476514525535-07fb3b4ae5f1?q=80&auto=format&fit=crop&w=600",
},
{
title: "The First Rule",
src: "https://images.unsplash.com/photo-1511497584788-876760111969?q=80&auto=format&fit=crop&w=600",
},
];
export default function MyComponent() {
return <FocusCards cards={cards} />;
}Props
| Component | Prop | Type | Description |
|---|---|---|---|
Card | card | FocusCard | The card object containing title and src properties |
Card | index | number | The index of the card in the array |
Card | hovered | number | null | The index of the currently hovered card, or null if none is hovered |
Card | setHovered | React.Dispatch<React.SetStateAction<number | null>> | Function to update the hovered state |
FocusCards | cards | FocusCard[] | An array of card objects to render |
FocusCard
| Prop | Type | Description |
|---|---|---|
title | string | The title shown on hover at the bottom of the card |
src | string | The image URL used as the card background |
Features
- Focus on Hover: The hovered card stays sharp while siblings receive
blur-smand a subtlescale-[0.98] - Smooth Transitions: All state changes animate with a 300ms ease-out transition
- Revealed Title: The title fades in with a gradient when its card is hovered
- Responsive: Single column on mobile, three columns on medium screens and up
- Themed: Card surfaces use
bg-secondaryand titles use the foreground/muted gradient
Note
The Card component is wrapped in React.memo so untouched cards skip re-renders when the hovered index changes.
Last updated on
