{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "nonprofit-header",
  "title": "Nonprofit: Header",
  "description": "The campaign is the bar: the appeal's progress along the bar's foot with the gift being chosen in the sun, the families funded and the days left beside the logo, the pages in one panel beside Donate with a chip that glides to the current page, a bar that folds away as you read down and leaves the appeal on screen, and a full-screen phone menu in the sea with its water risen to the appeal's level. Once the appeal closes it says so and takes no gift.",
  "dependencies": [
    "motion",
    "@base-ui/react"
  ],
  "registryDependencies": [
    "https://eased.dev/r/eased-tokens.json",
    "https://eased.dev/r/eased-motion.json",
    "https://eased.dev/r/nonprofit-core.json",
    "https://eased.dev/r/eased-indicator.json",
    "https://eased.dev/r/button.json"
  ],
  "files": [
    {
      "path": "src/registry/eased/templates/nonprofit/header.tsx",
      "content": "\"use client\";\n\nimport { Dialog } from \"@base-ui/react/dialog\";\nimport { motion } from \"motion/react\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\nimport { Indicator, IndicatorGroup } from \"../../_primitives/indicator/indicator\";\nimport { Button } from \"../../button/button\";\nimport { enter, reducedFade, smooth, stagger, useSafeReducedMotion } from \"../../lib/motion\";\nimport { BaseLink, useHref } from \"../_shared/base\";\nimport { AppealBar, appealWith, target, useAppealTime } from \"./appeal\";\nimport { appeal, brand, nav } from \"./content\";\nimport { amountOf, useAddedGift } from \"./gift\";\nimport { yearly } from \"./giving\";\nimport { COLUMN, Mark, Wordmark } from \"./kit\";\n\n/**\n * The top bar, and the template's navigation device: the campaign is the bar. Its bottom edge is\n * the appeal's progress, a thin bar that fills to what is raised, with a sun-coloured stretch for\n * the gift being chosen in the hero (or the one chosen earlier in the visit). Beside the pages\n * it reads the families funded and the days left, worked out on the client from the closing day\n * in content.ts, so it is never stale and reads \"Appeal closed\" once the day has passed.\n *\n * It stays at the top while you read up the page and folds away as you read down, leaving only\n * the bar, so the appeal is on screen the whole way. The pages sit in one panel at the right\n * beside Donate; a chip marks the page you are on, with a sea dot,\n * and glides to the link under a resting mouse (after 120ms, mouse only) or keyboard focus, then\n * back. Below lg the pages fold into a menu that fills the screen with the sea, its water risen\n * to the appeal's level. `current` is the page's own path, passed by the page so the header\n * needs no router.\n */\nexport function Header({ current = \"\" }: { current?: string }) {\n  const to = useHref();\n  const layer = useRef<HTMLDivElement>(null);\n  const bar = useRef<HTMLElement>(null);\n  const [open, setOpen] = useState(false);\n  const away = useAway(bar, open);\n\n  useEffect(() => {\n    if (!open) return;\n    const wide = window.matchMedia(WIDE);\n    const onWide = () => wide.matches && setOpen(false);\n    wide.addEventListener(\"change\", onWide);\n    return () => wide.removeEventListener(\"change\", onWide);\n  }, [open]);\n\n  return (\n    <Dialog.Root open={open} onOpenChange={setOpen}>\n      <a\n        href=\"#main\"\n        className=\"fixed top-3 left-3 z-50 inline-flex min-h-11 -translate-y-24 items-center rounded-control bg-surface-raised px-4 text-ui font-medium text-text shadow-floating transition-transform duration-(--eased-duration-standard) ease-enter focus-visible:translate-y-0 reduced:transition-none\"\n      >\n        {nav.skip}\n      </a>\n      <header\n        ref={bar}\n        data-away={away || undefined}\n        className=\"sticky top-0 z-30 bg-bg transition-transform duration-(--eased-duration-slow) ease-standard data-away:-translate-y-[calc(100%-var(--nf-bar))] reduced:transition-none\"\n      >\n        <div className={`${COLUMN} flex h-16 items-center gap-pad-sm sm:gap-pad-md`}>\n          <BaseLink href=\"/\" aria-label={nav.home} className=\"focus-ring -ms-1 flex min-h-11 items-center rounded-control-xs px-1 text-text\">\n            <Wordmark className=\"max-[359px]:[&>span:last-child]:sr-only\" />\n          </BaseLink>\n          <Readout className=\"max-[359px]:hidden max-lg:ms-auto lg:ms-pad-lg lg:items-start lg:text-left\" />\n          <Nav path={current} className=\"ms-auto max-lg:hidden\" />\n          <div className=\"flex items-center gap-1.5 max-[359px]:ms-auto\">\n            <Button variant=\"primary\" size=\"md\" nativeButton={false} render={<a href={to(nav.donate.href)} />} hitArea>\n              {nav.donate.label}\n            </Button>\n            <Dialog.Trigger render={<Button variant=\"ghost\" size=\"md\" hitArea edge=\"end\" className=\"text-text lg:hidden\" />}>{nav.menu}</Dialog.Trigger>\n          </div>\n        </div>\n        <Progress />\n      </header>\n      {/* Outside the header, whose transform would otherwise pin the menu to it. */}\n      <div ref={layer} />\n      <Menu path={current} container={layer} onNavigate={() => setOpen(false)} />\n    </Dialog.Root>\n  );\n}\n\n/** Wide enough for the pages in the bar: the menu closes when the window grows past it. */\nconst WIDE = \"(min-width: 64rem)\";\n\n/**\n * Away while reading down the page, back on any move up, at the top, with the menu open or with\n * focus inside it. Small moves (under 6px) are ignored, so a trackpad's jitter doesn't flicker it.\n */\nfunction useAway(ref: RefObject<HTMLElement | null>, open: boolean) {\n  const [away, setAway] = useState(false);\n  useEffect(() => {\n    let last = window.scrollY;\n    const onScroll = () => {\n      const y = window.scrollY;\n      const height = ref.current?.offsetHeight ?? 68;\n      if (Math.abs(y - last) < 6) return;\n      setAway(y > last && y > height * 2 && !ref.current?.contains(document.activeElement));\n      last = y;\n    };\n    window.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => window.removeEventListener(\"scroll\", onScroll);\n  }, [ref]);\n  return away && !open;\n}\n\n/** The appeal's numbers, at the bar's end: the families funded of the target, and the days left. */\nfunction Readout({ className = \"\" }: { className?: string }) {\n  const { before } = appealWith(0);\n  const time = useAppealTime();\n  return (\n    <p className={`flex min-w-0 flex-col items-end text-right leading-tight sm:flex-row sm:items-baseline sm:gap-2 ${className}`}>\n      <span className=\"text-ui-sm whitespace-nowrap text-text\">\n        <span className=\"font-medium tabular-nums\">{before}</span>\n        <span className=\"text-text-muted\">\n          {\" \"}\n          {appeal.of(appeal.target)}\n          <span className=\"max-md:hidden\"> {appeal.families}</span>\n        </span>\n      </span>\n      <span className={`text-ui-xs whitespace-nowrap sm:text-ui-sm ${time.closed ? \"text-text\" : \"text-text-muted\"}`}>\n        <span aria-hidden className=\"max-sm:hidden\">· </span>\n        {time.text}\n      </span>\n    </p>\n  );\n}\n\n/** The bar itself: the appeal's progress, named, with the gift being chosen in the sun. */\nfunction Progress() {\n  const added = useAddedGift();\n  const time = useAppealTime();\n  const { before } = appealWith(0);\n  return (\n    <div\n      role=\"progressbar\"\n      aria-label={appeal.name}\n      aria-valuemin={0}\n      aria-valuemax={target}\n      aria-valuenow={appeal.raised}\n      aria-valuetext={appeal.spoken(before, appeal.target, time.text)}\n    >\n      {/* Ink, not the sea, so the bar stays a line of its own over the hero's sea band. A closed appeal takes no more gifts. */}\n      <AppealBar added={added && !time.closed ? yearly(amountOf(added), added.frequency) : 0} className=\"h-(--nf-bar)\" raisedClassName=\"bg-text\" />\n    </div>\n  );\n}\n\nconst within = (path: string, href: string) => path === href || path.startsWith(`${href}/`);\n\n/** How long a resting mouse waits on a link before the level glides to it. */\nconst INTENT = 120;\n\n/**\n * The pages. The level rests under the page you are in, glides to a link under a resting mouse\n * or keyboard focus, and fades out at rest on a page outside the list (the home page, legal).\n */\nfunction Nav({ path, className = \"\" }: { path: string; className?: string }) {\n  const to = useHref();\n  const current = nav.links.findIndex((link) => within(path, link.href));\n  const [pointed, setPointed] = useState<number | null>(null);\n  const timer = useRef(0);\n  const at = pointed ?? current;\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n  const point = (i: number | null, delay = 0) => {\n    window.clearTimeout(timer.current);\n    if (delay) timer.current = window.setTimeout(() => setPointed(i), delay);\n    else setPointed(i);\n  };\n  return (\n    <nav aria-label={nav.label} className={className}>\n      <IndicatorGroup>\n        <ul className=\"flex items-center rounded-panel border border-line-subtle bg-surface p-1\" onPointerLeave={(e) => e.pointerType === \"mouse\" && point(null)}>\n          {nav.links.map((link, i) => (\n            <li key={link.href}>\n              <a\n                href={to(link.href)}\n                aria-current={i === current ? \"page\" : undefined}\n                onPointerEnter={(e) => e.pointerType === \"mouse\" && point(i, INTENT)}\n                onFocus={() => point(i)}\n                onBlur={() => point(null)}\n                className={`relative flex h-9 items-center rounded-control-sm px-3.5 text-ui font-medium transition-colors duration-(--eased-duration-fast) ease-standard focus-ring ${\n                  i === current ? \"text-text\" : \"text-text-secondary hover-fine:text-text\"\n                }`}\n              >\n                {at === i && <Indicator name=\"level\" className=\"inset-0 rounded-control-sm bg-surface-active\" />}\n                <span className=\"relative\">{link.label}</span>\n                {i === current && <span aria-hidden className=\"relative ms-1.5 size-1.5 rounded-full bg-(--nf-sea)\" />}\n              </a>\n            </li>\n          ))}\n        </ul>\n      </IndicatorGroup>\n    </nav>\n  );\n}\n\n/**\n * Below lg, the menu fills the screen with the sea: the pages set large, one to a line, rising\n * 80ms apart, with a sun dot after the page you are on; the appeal at the foot with its bar and\n * Donate. Behind it all, deeper water rises to the appeal's level as the menu opens. A modal:\n * focus stays inside, the page under it does not scroll, and Escape, Close or choosing a page\n * closes it, focus back on the button that opened it. Reduced motion fades it.\n */\nfunction Menu({ path, container, onNavigate }: { path: string; container: RefObject<HTMLDivElement | null>; onNavigate: () => void }) {\n  const to = useHref();\n  const reduced = useSafeReducedMotion();\n  const added = useAddedGift();\n  const time = useAppealTime();\n  const { before, raised } = appealWith(0);\n  const rise = (i: number) => (reduced ? { initial: { opacity: 0 }, animate: { opacity: 1 }, transition: reducedFade } : { initial: { opacity: 0, y: 12 }, animate: { opacity: 1, y: 0 }, transition: { ...enter, duration: 0.4, delay: 0.05 + i * stagger.line } });\n  return (\n    <Dialog.Portal container={container}>\n      <Dialog.Popup\n        data-nf-sea=\"\"\n        className=\"fixed inset-0 z-50 flex flex-col overflow-y-auto bg-bg text-text opacity-100 transition-opacity duration-(--eased-duration-standard) ease-enter data-ending-style:opacity-0 data-ending-style:duration-(--eased-duration-fast) data-ending-style:ease-standard data-starting-style:opacity-0 reduced:duration-(--eased-duration-instant)\"\n      >\n        <motion.div\n          aria-hidden\n          className=\"pointer-events-none fixed inset-x-0 bottom-0 -z-10 h-full\"\n          initial={{ y: reduced ? `${(1 - raised) * 100}%` : \"100%\" }}\n          animate={{ y: `${(1 - raised) * 100}%` }}\n          transition={reduced ? { duration: 0 } : { ...smooth, delay: 0.1 }}\n        >\n          <svg viewBox=\"0 0 400 24\" preserveAspectRatio=\"none\" className=\"block h-6 w-full text-(--nf-sea-deep)\">\n            <path d=\"M0 12c50-12 100 12 150 0s100-12 150 0 75 6 100 0v12H0Z\" fill=\"currentColor\" />\n          </svg>\n          <div className=\"h-full bg-(--nf-sea-deep)\" />\n        </motion.div>\n        <div className={`${COLUMN} flex h-16 shrink-0 items-center justify-between`}>\n          <Dialog.Title className=\"flex items-center gap-1.5 text-ui-lg font-semibold tracking-[-0.03em]\">\n            <Mark className=\"size-6\" />\n            {brand.name}\n          </Dialog.Title>\n          <Dialog.Close render={<Button variant=\"ghost\" size=\"md\" hitArea edge=\"end\" className=\"text-text\" />}>{nav.close}</Dialog.Close>\n        </div>\n        <nav aria-label={nav.menu} className={`${COLUMN} flex flex-1 flex-col justify-center py-pad-lg`}>\n          <ul className=\"flex flex-col\">\n            {[...nav.links, nav.contact].map((link, i) => (\n              <motion.li key={link.href} {...rise(i)}>\n                <a\n                  href={to(link.href)}\n                  aria-current={within(path, link.href) ? \"page\" : undefined}\n                  onClick={onNavigate}\n                  className=\"group focus-ring inline-flex min-h-14 items-center gap-3 rounded-control-sm font-display text-display-5xl font-semibold tracking-display text-text\"\n                >\n                  {link.label}\n                  <span aria-hidden className=\"hidden size-3 rounded-full bg-(--nf-sun) group-aria-[current=page]:inline-block\" />\n                </a>\n              </motion.li>\n            ))}\n          </ul>\n        </nav>\n        <motion.div {...rise(nav.links.length + 1)} className={`${COLUMN} flex shrink-0 flex-col gap-pad-base pb-pad-lg`}>\n          <div className=\"flex flex-col gap-2\">\n            <p className=\"flex flex-wrap items-baseline justify-between gap-x-pad-base text-ui text-text-secondary\">\n              <span className=\"font-medium text-text\">{appeal.name}</span>\n              <span>{time.text}</span>\n            </p>\n            <p className=\"text-ui-md text-text\">\n              <span className=\"font-semibold tabular-nums\">{before}</span> {appeal.of(appeal.target)} {appeal.families}\n            </p>\n            <AppealBar added={added && !time.closed ? yearly(amountOf(added), added.frequency) : 0} className=\"h-3 rounded-pill\" trackClassName=\"bg-surface-sunken\" raisedClassName=\"bg-text\" />\n          </div>\n          <Button variant=\"primary\" size=\"lg\" nativeButton={false} render={<a href={to(nav.donate.href)} onClick={onNavigate} />} className=\"h-12!\">\n            {nav.donate.label}\n          </Button>\n        </motion.div>\n      </Dialog.Popup>\n    </Dialog.Portal>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/eased/templates/nonprofit/header.tsx"
    }
  ],
  "meta": {
    "template": "nonprofit",
    "kind": "template-section",
    "industries": [
      "health"
    ]
  },
  "type": "registry:block"
}