Components94 / 118
Dash Header
A light dashboard top bar. Switching section fills the tab with accent ink while the old one drains; the search widens on focus (press /), the gear turns, the bell swings with a lagging clapper as notifications land, and the account menu drops open on a spring.
HeaderHeaderDashboardDashboardSearchSearchTabsTabsNotificationsNotificationsMenuMenuGSAPGSAP
Tweak
LIVELIVELook
Accent
Name beside avatar
Usage
Follows your tweaks.
usage.tsx
import { useState } from "react";
import { DashHeader } from "@/components/inreact/dash-header";
export function AppShell() {
const [section, setSection] = useState("Dashboard");
return (
<DashHeader
tabs={["Dashboard", "Analytics", "Sales", "Products"]}
value={section}
onValueChange={setSection}
user={{ name: "Alex Moreno", role: "Product Designer", avatar: "/me.jpg" }}
notifications={3}
/>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/dash-header.jsonOr copy the source
Install the dependencies, then save this as components/inreact/dash-header.tsx.
terminal
npm install gsapcomponents/inreact/dash-header.tsx
"use client";
import { gsap } from "gsap";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
/**
* Dash Header: a light app top bar with search, section tabs, settings,
* notifications and an account menu.
*
* Switching section fills the new tab's label with the accent like ink
* rising in a glass while the old one drains, and the label squashes a touch
* as it fills. The search field widens on focus (press "/" from anywhere) and
* its lens tips as you type. The gear turns on hover; when a notification
* lands the bell swings with its clapper lagging behind and the badge pops.
* The account menu drops open with a springy settle.
*
* <DashHeader tabs={["Dashboard", "Analytics", "Sales", "Products"]} user={{ name: "Alex Moreno", role: "Product Designer", avatar: "/me.jpg" }} />
*/
export interface DashHeaderUser {
name: string;
role?: string;
avatar?: string;
}
export interface DashHeaderProps {
tabs?: string[];
value?: string;
defaultValue?: string;
onValueChange?: (v: string) => void;
user?: DashHeaderUser;
/** Unread notifications; raising it rings the bell. */
notifications?: number;
onSearch?: (q: string) => void;
/** Menu items under the avatar. */
menu?: { label: string; onSelect?: () => void }[];
/** Accent colour (logo tile, active tab, badge). */
accent?: string;
/** Replaces the logo tile's mark. */
logo?: ReactNode;
/** Show the user's name and role beside the avatar. */
showName?: boolean;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const INK = "#1d2430";
const MUTED = "#8b94a3";
function Icon({ d, size = 18, children }: { d?: string; size?: number; children?: ReactNode }) {
return (
<svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
{d ? <path d={d} /> : children}
</svg>
);
}
export function DashHeader({
tabs = ["Dashboard", "Analytics", "Sales", "Products"],
value,
defaultValue,
onValueChange,
user = { name: "Alex Moreno", role: "Product Designer" },
notifications = 0,
onSearch,
menu = [{ label: "Profile" }, { label: "Settings" }, { label: "Sign out" }],
accent = "#2f6b45",
logo,
showName = false,
className,
}: DashHeaderProps) {
const [inner, setInner] = useState(defaultValue ?? tabs[0]);
const cur = value ?? inner;
const idx = Math.max(0, tabs.indexOf(cur));
const inkRefs = useRef<(HTMLSpanElement | null)[]>([]);
const labRefs = useRef<(HTMLSpanElement | null)[]>([]);
const prev = useRef(idx);
const choose = useCallback(
(i: number) => {
const v = tabs[i];
if (v === undefined) return;
if (value === undefined) setInner(v);
onValueChange?.(v);
},
[tabs, value, onValueChange],
);
// the accent ink rises in the new tab and drains from the old one
useLayoutEffect(() => {
const was = prev.current;
prev.current = idx;
inkRefs.current.forEach((el, i) => {
if (!el) return;
if (i !== idx && i !== was) gsap.set(el, { clipPath: "inset(100% 0% 0% 0%)" });
});
const inn = inkRefs.current[idx], out = inkRefs.current[was], lab = labRefs.current[idx];
if (was === idx || reduced()) {
if (inn) gsap.set(inn, { clipPath: "inset(0% 0% 0% 0%)" });
if (out && was !== idx) gsap.set(out, { clipPath: "inset(100% 0% 0% 0%)" });
return;
}
if (out) gsap.to(out, { clipPath: "inset(100% 0% 0% 0%)", duration: 0.38, ease: "power2.in", overwrite: true });
if (inn) gsap.fromTo(inn, { clipPath: "inset(100% 0% 0% 0%)" }, { clipPath: "inset(0% 0% 0% 0%)", duration: 0.55, ease: "power3.out", delay: 0.06, overwrite: true });
if (lab) {
gsap.killTweensOf(lab);
gsap.timeline().to(lab, { scaleY: 1.14, scaleX: 0.95, y: -1.5, duration: 0.12, ease: "power2.out" }).to(lab, { scaleY: 1, scaleX: 1, y: 0, duration: 0.7, ease: "elastic.out(1, 0.4)" });
}
}, [idx]);
const onTabKey = (e: ReactKeyboardEvent<HTMLDivElement>) => {
const map: Record<string, number> = { ArrowRight: (idx + 1) % tabs.length, ArrowLeft: (idx - 1 + tabs.length) % tabs.length, Home: 0, End: tabs.length - 1 };
const n = map[e.key];
if (n === undefined) return;
e.preventDefault();
choose(n);
(e.currentTarget.children[n] as HTMLElement | undefined)?.focus();
};
// search: widens on focus, "/" focuses it, the lens tips with each keystroke
const searchRef = useRef<HTMLLabelElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const lensRef = useRef<HTMLSpanElement>(null);
const widen = (on: boolean) => {
const s = searchRef.current, l = lensRef.current;
if (!s || !l) return;
const still = reduced();
gsap.to(s, { width: on ? 272 : 204, duration: still ? 0 : on ? 0.6 : 0.45, ease: on ? "back.out(1.6)" : "power3.inOut", overwrite: "auto" });
gsap.to(l, { rotation: on ? -18 : 0, scale: on ? 1.1 : 1, color: on ? INK : MUTED, duration: still ? 0 : 0.5, ease: "back.out(2.4)", overwrite: "auto" });
};
const tick = () => {
const l = lensRef.current;
if (!l || reduced()) return;
gsap.fromTo(l, { scaleX: 1.22, scaleY: 0.86 }, { scaleX: 1.1, scaleY: 1.1, duration: 0.45, ease: "elastic.out(1, 0.35)", overwrite: "auto" });
};
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== "/" || e.metaKey || e.ctrlKey) return;
const t = e.target as HTMLElement | null;
if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
e.preventDefault();
inputRef.current?.focus();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
// gear turns a quarter on each hover (it keeps its angle, like a real dial)
const gearRef = useRef<HTMLSpanElement>(null);
const turn = () => !reduced() && gearRef.current && gsap.to(gearRef.current, { rotation: "+=90", duration: 0.7, ease: "back.out(2.2)" });
// bell: swings from its top with the clapper lagging behind; the badge pops
const bellRef = useRef<SVGGElement>(null);
const clapRef = useRef<SVGPathElement>(null);
const badgeRef = useRef<HTMLSpanElement>(null);
const ring = useCallback(() => {
const b = bellRef.current, c = clapRef.current;
if (!b || !c || reduced()) return;
gsap.killTweensOf([b, c]);
const swing = [17, -14, 10, -7, 4, -2, 0];
const tl = gsap.timeline();
swing.forEach((r, i) => tl.to(b, { rotation: r, svgOrigin: "12 3", duration: i === 0 ? 0.1 : 0.12, ease: "sine.inOut" }));
const lag = gsap.timeline({ delay: 0.06 });
swing.forEach((r, i) => lag.to(c, { x: -r * 0.12, svgOrigin: "12 3", duration: i === 0 ? 0.1 : 0.12, ease: "sine.inOut" }));
}, []);
const lastN = useRef(notifications);
useEffect(() => {
const up = notifications > lastN.current;
lastN.current = notifications;
if (!up) return;
ring();
if (badgeRef.current && !reduced()) gsap.fromTo(badgeRef.current, { scale: 0.2 }, { scale: 1, duration: 0.6, ease: "back.out(3.2)" });
}, [notifications, ring]);
// account menu: drops open with a springy settle, items follow a beat behind
const [open, setOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
const chevRef = useRef<HTMLSpanElement>(null);
const acctRef = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
const m = menuRef.current, c = chevRef.current;
if (!m || !c) return;
const still = reduced();
const items = m.querySelectorAll("[data-mi]");
gsap.to(c, { rotation: open ? 180 : 0, duration: still ? 0 : 0.55, ease: "back.out(2.6)", overwrite: true });
if (open) {
gsap.fromTo(m, { autoAlpha: 0, y: -8, scaleY: 0.86, scaleX: 0.96 }, { autoAlpha: 1, y: 0, scaleY: 1, scaleX: 1, duration: still ? 0 : 0.5, ease: "back.out(1.9)", overwrite: true });
gsap.fromTo(items, { y: -6, opacity: 0 }, { y: 0, opacity: 1, duration: still ? 0 : 0.4, ease: "back.out(2)", stagger: 0.045, delay: still ? 0 : 0.07, overwrite: true });
} else {
gsap.to(m, { autoAlpha: 0, y: -5, scaleY: 0.92, duration: still ? 0 : 0.2, ease: "power2.in", overwrite: true });
}
}, [open]);
useEffect(() => {
if (!open) return;
const away = (e: PointerEvent) => !acctRef.current?.contains(e.target as Node) && setOpen(false);
const esc = (e: KeyboardEvent) => e.key === "Escape" && setOpen(false);
window.addEventListener("pointerdown", away);
window.addEventListener("keydown", esc);
return () => {
window.removeEventListener("pointerdown", away);
window.removeEventListener("keydown", esc);
};
}, [open]);
const press = (el: HTMLElement) => {
if (reduced()) return;
gsap.killTweensOf(el, "scale");
gsap.timeline().to(el, { scale: 0.88, duration: 0.08, ease: "power2.out" }).to(el, { scale: 1, duration: 0.6, ease: "elastic.out(1, 0.4)" });
};
const iconBtn = "grid size-9 shrink-0 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-[#6b7482] outline-none transition-colors duration-200 hover:bg-[#f1f3f6] hover:text-[#1d2430] focus-visible:ring-2 focus-visible:ring-black/15";
return (
<header
className={["relative flex h-14 items-center gap-3 rounded-[14px] bg-white px-2 text-[13px] select-none", className].filter(Boolean).join(" ")}
style={{ color: INK, boxShadow: "0 1px 2px rgba(20,28,40,.05), 0 6px 16px -6px rgba(20,28,40,.10), 0 18px 36px -18px rgba(20,28,40,.14)" }}
>
<a href="/" aria-label="Home" className="grid size-10 shrink-0 place-items-center rounded-[10px] text-white outline-none focus-visible:ring-2 focus-visible:ring-black/20" style={{ background: accent }}>
{logo ?? (
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true">
<rect x="5" y="6.5" width="14" height="4" rx="2" fill="currentColor" />
<rect x="5" y="13.5" width="9" height="4" rx="2" fill="currentColor" />
</svg>
)}
</a>
<label ref={searchRef} className="flex h-10 shrink-0 cursor-text items-center gap-2 rounded-[10px] bg-[#f2f4f7] pr-3 pl-3.5" style={{ width: 204 }}>
<input
ref={inputRef}
type="search"
placeholder="Search…"
aria-label="Search"
onFocus={() => widen(true)}
onBlur={() => widen(false)}
onChange={(e) => (tick(), onSearch?.(e.target.value))}
onKeyDown={(e) => e.key === "Escape" && e.currentTarget.blur()}
className="min-w-0 flex-1 border-0 bg-transparent p-0 text-[13px] text-[#1d2430] outline-none placeholder:text-[#9aa2ae] [&::-webkit-search-cancel-button]:hidden"
/>
<span ref={lensRef} className="grid shrink-0 place-items-center" style={{ color: MUTED }}>
<Icon size={16}>
<circle cx="11" cy="11" r="6.5" />
<path d="M20 20l-4.2-4.2" />
</Icon>
</span>
</label>
<div role="tablist" aria-label="Sections" className="flex items-center" onKeyDown={onTabKey}>
{tabs.map((t, i) => (
<button
key={t}
type="button"
role="tab"
aria-selected={i === idx}
tabIndex={i === idx ? 0 : -1}
onClick={() => choose(i)}
className="group cursor-pointer rounded-[8px] border-0 bg-transparent px-3 py-2 font-medium outline-none focus-visible:ring-2 focus-visible:ring-black/15"
style={{ font: "inherit", fontWeight: 600 }}
>
<span ref={(el) => void (labRefs.current[i] = el)} className="relative block origin-bottom whitespace-nowrap">
<span className="block transition-colors duration-200 group-hover:text-[#4b5462]" style={{ color: MUTED }}>
{t}
</span>
<span ref={(el) => void (inkRefs.current[i] = el)} aria-hidden="true" className="absolute inset-0 block" style={{ color: accent, clipPath: i === idx ? "inset(0% 0% 0% 0%)" : "inset(100% 0% 0% 0%)" }}>
{t}
</span>
</span>
</button>
))}
</div>
<div className="ml-auto flex items-center gap-1">
<button type="button" aria-label="Settings" className={iconBtn} onPointerEnter={turn} onClick={(e) => press(e.currentTarget)}>
<span ref={gearRef} className="grid place-items-center">
<Icon size={18}>
<path d="M12 3.2l1.6 1.9 2.5-.4.9 2.3 2.3.9-.4 2.5 1.9 1.6-1.9 1.6.4 2.5-2.3.9-.9 2.3-2.5-.4L12 20.8l-1.6-1.9-2.5.4-.9-2.3-2.3-.9.4-2.5L3.2 12l1.9-1.6-.4-2.5 2.3-.9.9-2.3 2.5.4z" />
<circle cx="12" cy="12" r="3" />
</Icon>
</span>
</button>
<button type="button" aria-label={notifications ? `Notifications, ${notifications} unread` : "Notifications"} className={`${iconBtn} relative`} onPointerEnter={ring} onClick={(e) => press(e.currentTarget)}>
<Icon size={18}>
<path ref={clapRef} d="M10.2 19.2a1.9 1.9 0 0 0 3.6 0" />
<g ref={bellRef}>
<path d="M12 3a1 1 0 0 1 1 1v.4a5.6 5.6 0 0 1 4.6 5.5v3.4l1.6 2.6H4.8l1.6-2.6V9.9A5.6 5.6 0 0 1 11 4.4V4a1 1 0 0 1 1-1z" />
</g>
</Icon>
<span
ref={badgeRef}
aria-hidden="true"
className="absolute top-0.5 -right-0.5 grid h-4 min-w-4 place-items-center rounded-full px-1 text-[9.5px] leading-none font-semibold text-white ring-2 ring-white"
style={{ background: accent, visibility: notifications ? "visible" : "hidden" }}
>
{notifications > 9 ? "9+" : notifications}
</span>
</button>
<div ref={acctRef} className="relative ml-1">
<button
type="button"
aria-haspopup="menu"
aria-expanded={open}
onClick={(e) => (press(e.currentTarget), setOpen((o) => !o))}
className="flex cursor-pointer items-center gap-2 rounded-full border-0 bg-transparent py-1 pr-2 pl-1 outline-none transition-colors duration-200 hover:bg-[#f1f3f6] focus-visible:ring-2 focus-visible:ring-black/15"
style={{ font: "inherit" }}
>
<span className="grid size-8 shrink-0 place-items-center overflow-hidden rounded-full text-[12px] font-semibold text-white" style={{ background: user.avatar ? "#d9dde3" : accent }}>
{user.avatar ? <img src={user.avatar} alt="" className="size-full object-cover" /> : user.name.slice(0, 1)}
</span>
{showName && (
<span className="flex flex-col items-start leading-tight">
<span className="text-[12.5px] font-semibold whitespace-nowrap" style={{ color: INK }}>
{user.name}
</span>
{user.role && <span className="text-[11px] whitespace-nowrap" style={{ color: MUTED }}>{user.role}</span>}
</span>
)}
<span ref={chevRef} className="grid place-items-center" style={{ color: MUTED }}>
<Icon d="M7 10l5 5 5-5" size={16} />
</span>
</button>
<div
ref={menuRef}
role="menu"
className="invisible absolute top-full right-0 z-20 mt-2 w-52 origin-top-right rounded-[12px] bg-white p-1.5 opacity-0"
style={{ boxShadow: "0 1px 2px rgba(20,28,40,.06), 0 10px 24px -8px rgba(20,28,40,.16), 0 28px 48px -24px rgba(20,28,40,.2)" }}
>
<div data-mi className="px-2.5 pt-1.5 pb-2">
<div className="text-[12.5px] font-semibold" style={{ color: INK }}>
{user.name}
</div>
{user.role && <div className="text-[11px]" style={{ color: MUTED }}>{user.role}</div>}
</div>
<div data-mi className="mx-1 mb-1 h-px bg-[#eef0f3]" />
{menu.map((m) => (
<button
key={m.label}
data-mi
type="button"
role="menuitem"
onClick={() => (m.onSelect?.(), setOpen(false))}
className="block w-full cursor-pointer rounded-[8px] border-0 bg-transparent px-2.5 py-2 text-left text-[13px] outline-none transition-colors duration-150 hover:bg-[#f2f4f7] focus-visible:bg-[#f2f4f7]"
style={{ color: INK, font: "inherit" }}
>
{m.label}
</button>
))}
</div>
</div>
</div>
</header>
);
}
export default DashHeader;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
12 propstabsstring[]The sections.valuestringControlled section.defaultValuestringStarting section (the first by default).onValueChange(value) => voidCalled when the section changes.user{ name, role?, avatar? }The signed-in user.notificationsnumberUnread count; raising it rings the bell.default 0default 0onSearch(query) => voidCalled as the search text changes.menu{ label, onSelect? }[]Items in the account menu.accentstringLogo tile, active tab and badge colour.default "#2f6b45"default "#2f6b45"logoReactNodeReplaces the logo tile's mark.showNamebooleanShow name and role beside the avatar.default falsedefault falseclassNamestringExtra classes.