"use client" /** * SiteHeader — breadcrumb / top bar — WCAG 2.1 AA * * ✓
landmark for AT navigation (WCAG 1.3.1) * ✓ `useDocumentTitle` — browser tab title matches breadcrumb (WCAG 2.4.2) * ✓ Sticky at top — when stuck, the rounded breadcrumb sits on the app bg and a * bottom separator appears to anchor it; transparent at rest so the rounded * corners blend into the inset card. * ✓ Uses Inter (font-sans) — Ivy Presto is reserved for PageHeader

only * * Primary sidebar expand/collapse lives on `AppSidebar` (not here) so the * control stays with the rail it affects. ⌘B still toggles via SidebarProvider. * * Compact shell: this row is not rendered. The trail and any `trailing` chrome * portal onto the utility bar instead, which is the single chrome row in that * layout (see `components/compact-header-slot.tsx`). Routes are unaffected — * they keep passing `siteHeader` the same way. */ import * as React from "react" import { createPortal } from "react-dom" import { useLocation } from "react-router" import { PageBreadcrumbBack, PageBreadcrumbTrail, type PageBreadcrumbBackProps, type PageBreadcrumbMenuOption, type PageBreadcrumbTrailItem, } from "@/components/page-breadcrumb-trail" import { useCompactHeaderSlot } from "@/components/compact-header-slot" import { deriveBackFromBreadcrumbs, useSetUtilityBarPageChrome, } from "@/components/utility-bar-page-chrome" import { useDocumentTitle } from "@/hooks/use-document-title" import { useScrollStuck } from "@/hooks/use-scroll-stuck" import { useShellLayout } from "@/contexts/shell-layout-context" import { isCompactShell } from "@/lib/shell-layout" import { isRecordDetailChromePath } from "@/lib/record-detail-chrome" import { cn } from "@/lib/utils" export type BreadcrumbItem = PageBreadcrumbTrailItem export type BreadcrumbMenuOption = PageBreadcrumbMenuOption export type SiteHeaderBackLink = Pick /** Utility bar chrome on compact shell for detail / focus routes. Default `back`. */ export type SiteHeaderUtilityBarMode = "back" | "breadcrumb" export interface SiteHeaderProps { /** Current page title (last breadcrumb segment in trail mode). */ title?: string /** Full breadcrumb trail — each item can be a link or plain text. Title is appended automatically as the last segment. */ breadcrumbs?: BreadcrumbItem[] /** Switch among peer records on the current breadcrumb segment (detail routes). */ currentPageMenu?: BreadcrumbMenuOption[] currentPageMenuAriaLabel?: string /** * Back-icon variant — parent link only (no `title` segment in the header). * Prefer when the page `

` carries the current title (e.g. New question composer). */ back?: SiteHeaderBackLink /** * Compact utility bar chrome when `back` is set or record detail derives a * parent. `breadcrumb` shows the ancestor trail instead of the back icon. * Record detail routes with `breadcrumbs` default to `breadcrumb`. */ utilityBarMode?: SiteHeaderUtilityBarMode /** Override for `` when `back` is set and the visible H1 lives in page body. */ documentTitle?: string /** Right-aligned chrome (e.g. design-system preview mode menu). */ trailing?: React.ReactNode /** * Drop the header's own surface so whatever the page puts behind it shows * through — for pages that open on a full-bleed coloured band (the product * marketing pages), where an opaque white strip cuts the band off at the top. * * Only affects the resting state. Once the page scrolls, the stuck chrome * comes back regardless, because content passing under a transparent bar is * unreadable. */ transparent?: boolean } type UtilityBarChrome = Parameters<ReturnType<typeof useSetUtilityBarPageChrome>>[0] type ResolvedChrome = { utilityBackHref: string | undefined utilityBackLabel: string | undefined mode: SiteHeaderUtilityBarMode | null barCurrentPage: string | undefined documentTitle: string | undefined scrollTitle: string } function resolveChrome({ title, breadcrumbs, back, utilityBarMode, documentTitle, pathname, }: { title: string breadcrumbs: BreadcrumbItem[] | undefined back: SiteHeaderBackLink | undefined utilityBarMode: SiteHeaderUtilityBarMode | undefined documentTitle: string | undefined pathname: string }): ResolvedChrome { const isRecordDetail = !back && isRecordDetailChromePath(pathname) const derivedRecordBack = isRecordDetail ? deriveBackFromBreadcrumbs(breadcrumbs) : null const utilityBackHref = back?.href ?? derivedRecordBack?.href const utilityBackLabel = back?.label ?? derivedRecordBack?.label const hasUtilityBack = Boolean(utilityBackHref && utilityBackLabel) const recordDetailTrail = isRecordDetail && Boolean(breadcrumbs?.length) const defaultMode: SiteHeaderUtilityBarMode | null = recordDetailTrail ? "breadcrumb" : hasUtilityBack ? "back" : null const mode: SiteHeaderUtilityBarMode | null = back ? "back" : (utilityBarMode ?? defaultMode) return { utilityBackHref, utilityBackLabel, mode, barCurrentPage: mode === "breadcrumb" && recordDetailTrail ? undefined : title, documentTitle: documentTitle ?? (back ? undefined : title), scrollTitle: documentTitle ?? title, } } function buildUtilityChrome( chrome: Omit<ResolvedChrome, "documentTitle">, breadcrumbs: BreadcrumbItem[] | undefined, currentPageMenu: BreadcrumbMenuOption[] | undefined, currentPageMenuAriaLabel: string | undefined, ): UtilityBarChrome { if (chrome.mode === "breadcrumb") { return { mode: "breadcrumb", items: breadcrumbs, currentPage: chrome.barCurrentPage, currentPageMenu, currentPageMenuAriaLabel, } } if (chrome.utilityBackHref && chrome.utilityBackLabel) { return { mode: "back", href: chrome.utilityBackHref, label: chrome.utilityBackLabel, scrollTitle: chrome.scrollTitle || undefined, scrollTitleMenu: currentPageMenu, scrollTitleMenuAriaLabel: currentPageMenuAriaLabel, } } return { mode: "default" } } function TrailingSlot({ trailing, className }: { trailing: React.ReactNode; className: string }) { return trailing ? <div className={className}>{trailing}</div> : null } function headerSurfaceClass(transparent: boolean, isStuck: boolean): string { // Transparent only while resting. The wrapper re-opaques on scroll, and an // opaque strip over an opaque strip is just the old bar. return transparent && !isStuck ? "bg-transparent" : "bg-background" } export function SiteHeader({ title = "Dashboard", breadcrumbs, currentPageMenu, currentPageMenuAriaLabel, back, utilityBarMode, documentTitle, trailing, transparent = false, }: SiteHeaderProps) { const isStuck = useScrollStuck() const compactHeaderSlot = useCompactHeaderSlot() const { variant: shellVariant } = useShellLayout() const compactShell = isCompactShell(shellVariant) const { pathname } = useLocation() const setUtilityBarChrome = useSetUtilityBarPageChrome() const chrome = resolveChrome({ title, breadcrumbs, back, utilityBarMode, documentTitle, pathname }) useDocumentTitle(chrome.documentTitle) const { mode, barCurrentPage, utilityBackHref, utilityBackLabel, scrollTitle } = chrome React.useLayoutEffect(() => { setUtilityBarChrome( buildUtilityChrome( { mode, barCurrentPage, utilityBackHref, utilityBackLabel, scrollTitle }, breadcrumbs, currentPageMenu, currentPageMenuAriaLabel, ), ) return () => setUtilityBarChrome({ mode: "default" }) }, [ setUtilityBarChrome, mode, breadcrumbs, barCurrentPage, utilityBackHref, utilityBackLabel, scrollTitle, currentPageMenu, currentPageMenuAriaLabel, ]) const breadcrumb = back ? ( <PageBreadcrumbBack {...back} scrollTitle={scrollTitle || undefined} scrollTitleMenu={currentPageMenu} scrollTitleMenuAriaLabel={currentPageMenuAriaLabel} className="min-w-0 flex-1" /> ) : ( <PageBreadcrumbTrail variant="header" items={breadcrumbs} currentPage={title} currentPageMenu={currentPageMenu} currentPageMenuAriaLabel={currentPageMenuAriaLabel} className="min-w-0 flex-1" /> ) // Compact shell: the bar is the header. Back / breadcrumb mode owns the // leading cluster on the utility bar; trail/trailing stay off the bar. // Always skip this row on compact — even before the portal slot mounts — so // we never flash a second sticky header under the utility bar. if (compactShell) { if (mode || !compactHeaderSlot) return null return createPortal( <> {breadcrumb} <TrailingSlot trailing={trailing} className="flex shrink-0 items-center gap-1.5" /> </>, compactHeaderSlot, ) } return ( <div data-site-header="" className={cn( // Sticky page chrome sits BELOW every Radix overlay (DropdownMenu / // Popover / Select / Dialog / Sheet / Tooltip all render at // z-50). Previously `z-60` here caused the school/product switcher // dropdown to open behind the breadcrumb. `z-30` keeps the header // above page content (charts, tables, scrolled rows) but below // floating overlays. // // Stuck-state chrome: subtle scrolled cue without becoming a // separate floating pill. Flush canvas has square corners; the // wrapper sticks to the top of `SidebarInset` with no radius. // When stuck we layer a faint sidebar-tinted surface, a hairline // bottom border, and a soft `shadow-sm` so the bar reads as // elevated chrome — but stays inside the page rectangle so it // doesn't compete with the table-column sticky header below. // `transition-[background-color,box-shadow]` fades the elevation // in/out alongside the bg flip. "sticky top-0 z-30 transition-[background-color,box-shadow]", isStuck ? "bg-sidebar border-b border-border shadow-sm" : "bg-transparent", )} > <header className={cn( "flex h-(--header-height) shrink-0 items-center gap-2 transition-[width,height] ease-out group-has-data-[collapsible=icon]/sidebar-wrapper:h-(--header-height)", headerSurfaceClass(transparent, isStuck), )} > <div className="flex w-full min-w-0 items-center gap-1 ps-4 pe-1.5 lg:gap-2 lg:ps-5 lg:pe-2"> {breadcrumb} <TrailingSlot trailing={trailing} className="flex shrink-0 items-center gap-1.5 ps-1" /> </div> </header> </div> ) }