INFINITYUI
HomeComponentsDocsTemplates
Star

Getting Started

  • Introduction
  • Installation
  • CLI
  • Audit

Navigation

  • Spotlight Navbar
  • Glass DockNEW
  • Animated Tab Bar
  • Circle Menu
  • Magnet Tabs
  • Animated Sidebar
  • Apple Spotlight
  • Page TOC RailNEW

Text

  • Flip Text
  • Glitch Text
  • Liquid Text
  • Flip Fade Text
  • Mask Cursor Effect

Cards

  • Glow Border Card
  • Testimonials Card
  • Interactive Book
  • Trading CardsNEW
  • Hover Image
  • Chain of ThoughtNEW
  • Masonry Grid
  • Image Pile
  • Staggered Grid

Inputs

  • AI InputNEW
  • OTP Input
  • Leave Rating

Buttons

  • Social Flip Button
  • Creepy Button

Loaders

  • Jelly Loader
  • Rolling Ball Scroll
  • Glowing Scroll

Backgrounds

  • Light Lines
  • Perspective Grid
  • Liquid Ocean
  • Eagle Vision
  • Flow Scroll
  • Horizontal Scroll

Overlays

  • PersonaNEW
  • Infinite Moving Cards
  • Masked Avatars
  • Stacked Logos
  • Icon Wheel
  • Pixelated CarouselNEW
  • Pixelated Image Trail
  • Flip Scroll
  • Interactive Folder
  • Animated Folder IconNEW
  • Stack Scroll
  • Rubik Cube
Navigation

Spotlight Navbar

#navbar#spotlight#hover
Hover to see the tracking spotlight effect.
implementedInfinityUI component

This component is fully implemented in InfinityUI and wired into the docs and registry flow.

Installation

Use the registry command to add the component source, and install any package dependencies if needed.

Infinity Registry

Install the component source into your project with the shadcn CLI.

npx shadcn@latest add https://infinityui-pearl.vercel.app/r/spotlight-navbar
Package Dependencies

Install the npm packages used by this component source.

npm install framer-motion

Component Code

Copy and paste this code into your component file.

tsx
"use client";

import { useRef, useState, useEffect } from "react";
import { motion } from "framer-motion";

interface SpotlightNavbarProps {
    items: {
        name: string;
        href: string;
    }[];
}

export function SpotlightNavbar({ items }: SpotlightNavbarProps) {
    const navRef = useRef<HTMLElement>(null);
    const [position, setPosition] = useState<{ x: number; y: number } | null>(null);
    const [opacity, setOpacity] = useState(0);

    const handleMouseMove = (e: React.MouseEvent<HTMLElement>) => {
        if (!navRef.current) return;
        const rect = navRef.current.getBoundingClientRect();
        setPosition({
            x: e.clientX - rect.left,
            y: e.clientY - rect.top,
        });
    };

    return (
        <nav
            ref={navRef}
            onMouseMove={handleMouseMove}
            onMouseEnter={() => setOpacity(1)}
            onMouseLeave={() => setOpacity(0)}
            className="relative px-4 py-2 flex items-center gap-2 rounded-full border border-white/10 bg-zinc-950/50 backdrop-blur-xl overflow-hidden pointer-events-auto shadow-2xl shadow-black/50"
        >
            {/* The Spotlight Glow */}
            <motion.div
                animate={{
                    opacity,
                    left: position?.x ? position.x - 100 : "50%",
                    top: position?.y ? position.y - 100 : "50%",
                }}
                transition={{ type: "tween", ease: "backOut", duration: 0.2 }}
                className="pointer-events-none absolute w-[200px] h-[200px] bg-indigo-500/20 rounded-full blur-3xl z-0"
            />

            {items.map((item) => (
                <button
                    key={item.name}
                    type="button"
                    className="relative z-10 px-4 py-1.5 text-sm font-medium text-zinc-400 hover:text-white transition-colors duration-300 rounded-full group outline-none"
                >
                    <span className="relative z-10">{item.name}</span>
                    <span className="absolute inset-x-0 -bottom-px h-px bg-gradient-to-r from-transparent via-indigo-500/0 to-transparent group-hover:via-indigo-500/50 transition-all duration-300" />
                </button>
            ))}
        </nav>
    );
}