Spotlight Grid
The Spotlight Grid is a component that displays a grid of items with a spotlight effect. It's perfect for showcasing your projects or skills.
Preview
CSS
Framer
Next.js
Node.js
React
Tailwind
Three.js
Typescript
Follow below steps 👇🏻
Install dependencies
1npm i framer-motion
Component
Create a file spotlight-grid.tsx in your components folder and paste this code
1'use client';23import { motion } from 'framer-motion';4import Image from 'next/image';5import React, { useState } from 'react';67interface SpotlightItemType {8name: string;9logo: string;10}1112interface SpotlightGridProps {13items: SpotlightItemType[];14}1516const SpotlightGrid = ({ items }: SpotlightGridProps) => {17// * Randomly select an item to highlight when component mounts18const randomIndex = Math.floor(Math.random() * items.length);19const [hoveredItem, setHoveredItem] = useState<string>(items[randomIndex].name);2021return (22<div className="w-full flex flex-col items-start justify-start gap-4">23<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 w-full sm:gap-0 gap-2 text-white/85">24{items25.sort((a, b) => a.name.localeCompare(b.name))26.map((item) => {27return (28<div29key={item.name}30className="relative flex items-center justify-start group cursor-default"31>32<div33onMouseEnter={() => setHoveredItem(item.name)}34className="flex p-1 sm:p-2 items-center justify-center gap-1 z-10 relative"35>36<div className="relative h-[12px] w-[12px] md:h-[16px] md:w-[16px]">37<Image src={item.logo || ''} alt={item.name} fill className="object-contain" />38</div>39<p className="truncate">{item.name}</p>40{hoveredItem === item.name && (41<motion.div42layout43layoutId="item-highlight"44style={{45boxShadow: '0px 0px 100px 10px #ffffff4c'46}}47className="absolute h-full z-0 rounded-md w-[calc(100%+30px)] pointer-events-none"48></motion.div>49)}50</div>51</div>52);53})}54</div>55</div>56);57};5859export default SpotlightGrid;
Usage
1<SpotlightGrid2items={[3{4name: 'React',5logo: '/react.svg'6},7{8name: 'Next.js',9logo: '/nextjs.svg'10},11{12name: 'Tailwind',13logo: '/tailwindcss.svg'14},15{16name: 'Typescript',17logo: '/typescript.svg'18},19{20name: 'Framer',21logo: '/framermotion.png'22},23{24name: 'Node.js',25logo: '/nodejs.svg'26},27{28name: 'CSS',29logo: '/css.svg'30},31{32name: 'Three.js',33logo: '/threejs.svg'34}35]}36/>
⭐️ Got a question or feedback?
Feel free to reach out!