Hover Directory
Typographic index with smooth arrow reveal.
1. Install Dependencies
$npm install framer-motion lucide-react
2. Copy Component Code
components/ui/HoverDirectory.tsx
1"use client";2
3import React, { useState } from "react";4import { motion, useReducedMotion } from "framer-motion";5import { ArrowUpRight } from "lucide-react";6
7export interface DirectoryEntry {8 title: string;9 count: string;10 href: string;11}12
13interface HoverDirectoryProps {14 items: DirectoryEntry[];15}16
17export function HoverDirectory({ items }: HoverDirectoryProps) {18 const [hoveredIdx, setHoveredIdx] = useState<number | null>(0);19 const prefersReducedMotion = useReducedMotion();20
21 return (22 <div className="w-full max-w-md divide-y divide-black/[0.08] border-y border-black/[0.08] dark:divide-white/[0.08] dark:border-white/[0.08]">23 {items.map((item, idx) => {24 const active = hoveredIdx === idx;25 return (26 <a27 key={item.title}28 href={item.href}29 onMouseEnter={() => setHoveredIdx(idx)}30 className="flex items-center justify-between py-3.5 transition-colors"31 >32 <span33 className={`text-sm font-medium transition-colors ${34 active35 ? "text-black dark:text-white"36 : "text-neutral-500 dark:text-neutral-400"37 }`}38 >39 {item.title}40 </span>41
42 <span className="flex items-center gap-2 font-mono text-xs tabular-nums">43 <span44 className={45 active46 ? "text-emerald-600 dark:text-emerald-400"47 : "text-neutral-400"48 }49 >50 {item.count}51 </span>52 <motion.span53 animate={{54 x: prefersReducedMotion ? 0 : active ? 0 : -4,55 opacity: active ? 1 : 0.25,56 }}57 transition={58 prefersReducedMotion ? { duration: 0 } : { duration: 0.2 }59 }60 >61 <ArrowUpRight62 className="h-3.5 w-3.5 text-emerald-500"63 aria-hidden="true"64 />65 </motion.span>66 </span>67 </a>68 );69 })}70 </div>71 );72}Usage Example
import { HoverDirectory } from "@/components/ui/HoverDirectory";
export default function IndexPage() { return ( <HoverDirectory items={[ { title: "Hero Sections", count: "03", href: "#hero" }, { title: "Bento Grids", count: "04", href: "#bento" }, ]} /> );}3. Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| items | DirectoryEntry[] | required | List of directory entries containing title, count, and href. |