@nswds/ui 4.6.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -4
- package/dist/components/badge.js +26 -6
- package/dist/components/badge.js.map +1 -1
- package/dist/components/button.js +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/expandable-search.js +2 -2
- package/dist/components/expandable-search.js.map +1 -1
- package/dist/components/field.js +1 -1
- package/dist/components/field.js.map +1 -1
- package/dist/components/footer.js +11 -8
- package/dist/components/footer.js.map +1 -1
- package/dist/components/header.d.ts +26 -1
- package/dist/components/header.js +13 -8
- package/dist/components/header.js.map +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/link.js +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/main-nav.js +4 -4
- package/dist/components/main-nav.js.map +1 -1
- package/dist/components/navigation-menu.js +7 -7
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/push-menu.d.ts +5 -5
- package/dist/components/push-menu.js +2 -2
- package/dist/components/push-menu.js.map +1 -1
- package/dist/components/side-nav.js +5 -5
- package/dist/components/side-nav.js.map +1 -1
- package/dist/components/site-search.js +2 -2
- package/dist/components/site-search.js.map +1 -1
- package/dist/components/skip-link.js +1 -1
- package/dist/components/skip-link.js.map +1 -1
- package/dist/components/spinner.js +1 -1
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/step-indicator.js +5 -5
- package/dist/components/step-indicator.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/header.tsx"],"names":[],"mappings":";;;;;;;;AA4BA,MAAM,YAAA,GAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,IAAA,EAAM,iFAAA;AAAA,EACN,KAAA,EACE,kIAAA;AAAA,EACF,KAAA,EACE,+HAAA;AAAA,EACF,IAAA,EAAM;AACR;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,CAAc,MAAA,CAAO,UAAU,CAAC,CAAA;AAAA,IAClC;AAGA,IAAA,QAAA,EAAS;AACT,IAAA,MAAA,CAAO,iBAAiB,QAAA,EAAU,QAAA,EAAU,EAAE,OAAA,EAAS,MAAM,CAAA;AAC7D,IAAA,OAAO,MAAM,MAAA,CAAO,mBAAA,CAAoB,QAAA,EAAU,QAAQ,CAAA;AAAA,EAC5D,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,uBACE,GAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,EAAA,EAAG,YAAA;AAAA,MACH,WAAA,EAAU,QAAA;AAAA,MACV,cAAY,KAAA,IAAS,oBAAA;AAAA,MAGrB,iBAAe,UAAA,IAAc,MAAA;AAAA,MAC5B,GAAG,KAAA;AAAA,MACJ,SAAA,EAAW,EAAA;AAAA,QACT,cAAA,CAAe,EAAE,KAAA,EAAO,CAAA;AAAA;AAAA;AAAA;AAAA,QAIxB,MAAA,IAAU,mBAAA;AAAA;AAAA,QAEV,MAAA,IAAU,mCAAA;AAAA;AAAA;AAAA,QAGV,MAAA,IACE,qFAAA;AAAA,QACF;AAAA,OACF;AAAA,MACA,GAAA;AAAA,MAEA,8BAAC,kBAAA,CAAmB,QAAA,EAAnB,EAA4B,KAAA,EAAO,SAAS,oBAAA,EAC3C,QAAA,kBAAA,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,WAAA,EAAU,kBAAA;AAAA,UACV,WAAW,EAAA,CAAG,uBAAA,CAAwB,EAAE,SAAA,EAAW,GAAG,kBAAkB,CAAA;AAAA,UAEvE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ","file":"header.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Badge } from '../components/badge.js'\nimport { Link } from '../components/link.js'\nimport { Logo } from '../components/logo.js'\n\n/**\n * Surface colours the header can be themed with, sharing the Masthead's and\n * SkipLink's four-name vocabulary (`dark`, `light`, `white`, `grey`) — the three\n * components stack at the top of the page and a service picks one word for the\n * whole chrome.\n *\n * Every pair is WCAG 2.2 AAA (1.4.6, 7:1), computed from the masterbrand oklch\n * tokens. Light mode: grey-800 on white 15.1:1, grey-800 on grey-100 13.8:1,\n * white on primary-800 14.4:1, white on grey-800 15.1:1. Dark mode deepens each\n * surface onto the same family's dark step and clears AAA more comfortably\n * still (17.2:1–20.2:1).\n *\n * Unlike the Masthead — a brand strip whose light/white/grey surfaces are frozen\n * across themes — the header is the page's own surface, so all four follow the\n * theme. Pair `Header color=\"dark\"` with `Masthead color=\"dark\"` when a service\n * wants the two to match in both modes.\n */\nconst headerColors = {\n // Ink values use the RAW masterbrand tokens (--grey-800) rather than\n // Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes an\n // unreferenced @theme key, and referencing one from inside an arbitrary\n // property is not a usage signal. Same reasoning as footer.tsx.\n // (--color-white is safe: `text-white` below is a real utility.)\n dark: 'bg-primary-800 text-white [--header-ink:var(--color-white)] dark:bg-primary-950',\n light:\n 'bg-grey-100 text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--header-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--header-ink:var(--color-white)]',\n grey: 'bg-grey-800 text-white [--header-ink:var(--color-white)] dark:bg-grey-950',\n}\n\ntype HeaderColor = keyof typeof headerColors\n\n// Shared by cva's defaultVariants, the data-color attribute and the logo\n// context, so the four can't drift apart.\nconst DEFAULT_HEADER_COLOR: HeaderColor = 'white'\n\nconst headerVariants = cva(\n [\n 'w-full',\n // The hairline rule derives from the surface's own ink, so it follows every\n // colour variant and both themes from one value. Mirrors the color-mix\n // derivation in footer.tsx (--footer-border) and link.tsx (--link-halo).\n '[--header-border:color-mix(in_oklch,var(--header-ink)_15%,transparent)]',\n 'transition-shadow duration-300 motion-reduce:transition-none',\n ],\n {\n variants: {\n color: headerColors,\n },\n defaultVariants: {\n color: DEFAULT_HEADER_COLOR,\n },\n },\n)\n\nconst headerContainerVariants = cva(\n [\n 'mx-auto flex w-full flex-wrap items-center justify-between gap-x-4 gap-y-3 py-3 sm:py-4 lg:py-5',\n // Lateral padding funnels through --header-padding-x so an app can retune it\n // once (via the `style` prop or a utility class) without a new variant. Same\n // mechanism, and the same 16px → 24px → 48px rhythm, as Masthead and Footer.\n 'px-(--header-padding-x)',\n '[--header-padding-x:--spacing(4)] sm:[--header-padding-x:--spacing(6)] lg:[--header-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app parity). --header-max-width is still read so a\n // shell app can constrain the inner wrapper without switching variants.\n fluid: 'max-w-[var(--header-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--header-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Lets `HeaderBrand` adapt its artwork to the surface it is drawn on — the\n * default `Logo` paints its wordmark `nsw-blue-800` and the version `Badge`\n * paints itself `primary-800`, both of which disappear on the `dark`\n * (primary-800) surface. A `logo` node supplied by the consumer overrides the\n * lockup entirely; at that point the choice is theirs.\n */\nconst HeaderColorContext = React.createContext<HeaderColor>(DEFAULT_HEADER_COLOR)\n\n/** Surfaces dark enough to need light-on-dark artwork. */\nconst DARK_SURFACE_COLORS = new Set<HeaderColor>(['dark', 'grey'])\n\ntype HeaderBrandProps = React.ComponentPropsWithoutRef<'div'> & {\n /** Home-page target for the brand link. Defaults to `/`. */\n href?: React.ComponentPropsWithoutRef<typeof Link>['href']\n /** Service or site name shown beside the logo. */\n sitename?: React.ReactNode\n /**\n * Heading level for `sitename`. Omit (the default) to render a `<span>`,\n * which is usually right: the page's own `<h1>` belongs to its main content,\n * and a site name repeated in the header on every page is not the heading\n * that describes this page. Supply a level only when a service deliberately\n * places the site name in the document outline.\n *\n * `1` is excluded for the reason above; `6` is the deepest heading HTML\n * defines.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /**\n * Version string shown in a Badge beside the brand. Sits outside the link,\n * so it never becomes part of the home link's accessible name.\n */\n version?: React.ReactNode\n /**\n * Visually-hidden prefix announced before `version`, giving the bare number\n * context for screen readers (\"2.1.0\" → \"Version 2.1.0\"). Pass an empty\n * string to suppress.\n */\n versionLabel?: string\n /**\n * `true` (default) renders the NSW Government waratah, `false` omits it, and\n * a node replaces it — pass an agency lockup here.\n */\n logo?: boolean | React.ReactNode\n /**\n * Accessible name for the brand link. Left unset by default: the link's name\n * is then its visible content — \"NSW Government\" (from `Logo`'s\n * visually-hidden text) plus `sitename` — which keeps the visible label\n * inside the accessible name (WCAG 2.2, 2.5.3 Label in Name). Overriding it\n * with something like \"Home page\" would break that, so set it only when the\n * brand renders no text at all.\n */\n label?: string\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: the\n * default `Logo` carries a visually-hidden \"NSW Government\", so a brand with\n * neither it nor a `sitename` renders a link with no text at all, and reaches\n * assistive tech unnamed (WCAG 2.2, 4.1.2 Name, Role, Value). A consumer's own\n * logo node is assumed to carry its own text. No-op in production.\n */\nfunction warnIfBrandUnlabelled({\n logo,\n sitename,\n label,\n}: Pick<HeaderBrandProps, 'logo' | 'sitename' | 'label'>) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!logo && !sitename && !label) {\n console.warn(\n '[nswds/ui] HeaderBrand has no logo and no sitename, so its home link has no accessible name — pass `label`.',\n )\n }\n}\n\n/**\n * Logo, site name and optional version badge, linked to the home page. Sits at\n * the start of the `Header` row.\n *\n * The link renders through `Link`, so it picks up the framework link component\n * from `LinkProvider` (next/link et al) rather than hardcoding one.\n */\nfunction HeaderBrand({\n className,\n href = '/',\n sitename,\n headingLevel,\n version,\n versionLabel = 'Version',\n logo = true,\n label,\n children,\n ref,\n ...props\n}: HeaderBrandProps) {\n const color = React.useContext(HeaderColorContext)\n const onDarkSurface = DARK_SURFACE_COLORS.has(color)\n const Sitename = headingLevel ? (`h${headingLevel}` as const) : 'span'\n\n warnIfBrandUnlabelled({ logo, sitename, label })\n\n const logoNode =\n logo === true ? (\n <Logo\n logoType={onDarkSurface ? 'reversed' : 'default'}\n // 64px from lg, 56px below it — 56px is the floor, so the lockup stays\n // legible on a phone. Written as mutually exclusive breakpoint ranges\n // rather than `h-14 lg:h-16`: a bare `h-14` a consumer also uses is\n // re-emitted after ours by their own Tailwind build, and a media query\n // adds no specificity, so it would outrank the lg step and freeze the\n // logo at 56px.\n className='w-auto max-lg:h-14 lg:h-16'\n />\n ) : (\n // `false` / `null` fall through as the falsy nodes they are; anything\n // else is the consumer's own lockup.\n logo\n )\n\n return (\n <div\n data-slot='header-brand'\n {...props}\n className={cn('flex grow basis-0 items-center gap-3 sm:gap-4', className)}\n ref={ref}\n >\n {/* variant='unstyled' — a brand lockup takes no underline or link\n colour. outline-current resolves to the surface's ink on every\n variant, so the focus indicator contrasts with the header\n (WCAG 2.2, 2.4.13 Focus Appearance). The negative margin keeps the\n indicator from nudging the row. */}\n <Link\n variant='unstyled'\n href={href}\n aria-label={label}\n className='-m-1 flex items-center gap-3 rounded-sm p-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current sm:gap-4'\n >\n {logoNode}\n {sitename ? (\n // Brand-blue ink on the light surfaces (14.4:1 on white, 13.2:1 on\n // grey-100 — both WCAG 2.2 AAA). The `dark` surface *is* primary-800\n // and `grey` is nearly as deep, so those keep the header's own white\n // ink; dark mode does the same, matching the `dark:text-white` the\n // light/white variants already set on the surface.\n <Sitename\n className={cn(\n 'text-lg font-bold text-balance sm:text-xl',\n !onDarkSurface && 'text-primary-800 dark:text-white',\n )}\n >\n {sitename}\n </Sitename>\n ) : null}\n </Link>\n {version ? (\n // Badge's `primary` ink is primary-800 — the `dark` header's own\n // surface — so dark surfaces take the white badge instead.\n <Badge\n data-slot='header-version'\n variant='soft'\n color={onDarkSurface ? 'white' : 'primary'}\n >\n {versionLabel ? <span className='sr-only'>{versionLabel} </span> : null}\n {version}\n </Badge>\n ) : null}\n {children}\n </div>\n )\n}\n\ntype HeaderActionsProps = React.ComponentPropsWithoutRef<'div'> & {\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Trailing cluster of header controls — search, theme switcher, sign-in, and\n * the like. Deliberately unopinionated about what goes in it: site search and\n * theme switching are app concerns (they need routing and a theme provider),\n * so the design system supplies the slot and its spacing rather than the\n * widgets.\n *\n * Not a `nav` landmark: a row of controls is not a set of navigation links, and\n * an extra landmark on every page buries the ones that matter. Wrap genuine\n * navigation in your own `<nav>` inside `Header`.\n */\nfunction HeaderActions({ className, ref, ...props }: HeaderActionsProps) {\n return (\n <div\n data-slot='header-actions'\n {...props}\n className={cn('flex basis-0 items-center justify-end gap-2 sm:gap-4 md:grow', className)}\n ref={ref}\n />\n )\n}\n\ntype HeaderProps = React.ComponentPropsWithoutRef<'header'> &\n VariantProps<typeof headerVariants> &\n VariantProps<typeof headerContainerVariants> & {\n /** Stick to the top of the viewport as the page scrolls. Defaults to `true`. */\n sticky?: boolean\n /** Hairline rule along the bottom edge. Defaults to `true`. */\n border?: boolean\n /** Raise the header with a shadow once the page is scrolled. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Top-of-page `banner` landmark: brand, site name and header controls. Render\n * it once in a shared layout, below `SkipLinks` and `Masthead`.\n *\n * - `color` themes the surface; all four pairs are WCAG 2.2 AAA and follow the\n * theme in dark mode (see `headerColors`). The bottom rule derives from the\n * surface's ink, so it follows automatically.\n * - `container` selects the inner wrapper layout: `fluid` (full-bleed,\n * nswds-app parity) or `contained` (centred 1200px column, legacy\n * `nsw-container` parity). Fine-tune either with the `--header-max-width`\n * and `--header-padding-x` custom properties.\n * - Scroll position is tracked and exposed as `data-scrolled`, which is what\n * the `shadow` treatment keys off. Style your own scrolled state with it.\n *\n * Compose the row from `HeaderBrand` and `HeaderActions`:\n *\n * ```tsx\n * <Header>\n * <HeaderBrand sitename=\"Design System\" version=\"2.1.0\" />\n * <HeaderActions>\n * <ThemeSwitcher />\n * </HeaderActions>\n * </Header>\n * ```\n *\n * The `banner` landmark comes from the native `<header>` element, which only\n * carries it outside `article`, `aside`, `main`, `nav` and `section` — wrapping\n * `div`s are fine. Keep it out of `<main>`.\n *\n * The default `id=\"nsw-header\"` is kept for compatibility with existing shells\n * that target it (override via the `id` prop).\n */\nfunction Header({\n className,\n color,\n container,\n containerClassName,\n sticky = true,\n border = true,\n shadow = true,\n children,\n ref,\n ...props\n}: HeaderProps) {\n const [isScrolled, setIsScrolled] = React.useState(false)\n\n React.useEffect(() => {\n function onScroll() {\n setIsScrolled(window.scrollY > 0)\n }\n // Read once on mount too: a page restored mid-scroll (back/forward, or a\n // deep link to a fragment) never fires a scroll event.\n onScroll()\n window.addEventListener('scroll', onScroll, { passive: true })\n return () => window.removeEventListener('scroll', onScroll)\n }, [])\n\n return (\n <header\n id='nsw-header'\n data-slot='header'\n data-color={color ?? DEFAULT_HEADER_COLOR}\n // Present-or-absent rather than \"true\"/\"false\", so it reads like Base\n // UI's data-disabled and Tailwind's bare `data-scrolled:` variant works.\n data-scrolled={isScrolled || undefined}\n {...props}\n className={cn(\n headerVariants({ color }),\n // z-40 sits below the z-50 SkipLinks: a sticky header at the same\n // level comes later in the DOM and would paint over a focused skip\n // link, hiding the page's bypass mechanism (WCAG 2.2, 2.4.1).\n sticky && 'sticky top-0 z-40',\n // Always drawn, so the scrolled state changes no box heights.\n border && 'border-b border-(--header-border)',\n // Shadows read as elevation on light surfaces only; in dark mode the\n // rule above carries the separation.\n shadow &&\n 'data-scrolled:shadow-md data-scrolled:shadow-black/5 dark:data-scrolled:shadow-none',\n className,\n )}\n ref={ref}\n >\n <HeaderColorContext.Provider value={color ?? DEFAULT_HEADER_COLOR}>\n <div\n data-slot='header-container'\n className={cn(headerContainerVariants({ container }), containerClassName)}\n >\n {children}\n </div>\n </HeaderColorContext.Provider>\n </header>\n )\n}\n\nexport { Header, HeaderActions, HeaderBrand, headerColors, headerContainerVariants, headerVariants }\nexport type { HeaderActionsProps, HeaderBrandProps, HeaderColor, HeaderProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/header.tsx"],"names":[],"mappings":";;;;;;;;AA4BA,MAAM,YAAA,GAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,IAAA,EAAM,iFAAA;AAAA,EACN,KAAA,EACE,kIAAA;AAAA,EACF,KAAA,EACE,+HAAA;AAAA,EACF,IAAA,EAAM;AACR;AAMA,MAAM,oBAAA,GAAoC,OAAA;AAE1C,MAAM,cAAA,GAAiB,GAAA;AAAA,EACrB;AAAA,IACE,QAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yEAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,KAAA,EAAO;AAAA;AACT;AAEJ;AAEA,MAAM,uBAAA,GAA0B,GAAA;AAAA,EAC9B;AAAA,IACE,+GAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yBAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,SAAA,EAAW;AAAA;AAAA;AAAA,QAGT,KAAA,EAAO,sCAAA;AAAA;AAAA,QAEP,SAAA,EAAW;AAAA;AACb,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,SAAA,EAAW;AAAA;AACb;AAEJ;AASA,MAAM,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAA2B,oBAAoB,CAAA;AAGhF,MAAM,sCAAsB,IAAI,GAAA,CAAiB,CAAC,MAAA,EAAQ,MAAM,CAAC,CAAA;AA4EjE,SAAS,qBAAA,CAAsB;AAAA,EAC7B,IA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AAA,OACF;AAAA,MACA,GAAA;AAAA,MAEA,8BAAC,kBAAA,CAAmB,QAAA,EAAnB,EAA4B,KAAA,EAAO,SAAS,oBAAA,EAC3C,QAAA,kBAAA,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,WAAA,EAAU,kBAAA;AAAA,UACV,WAAW,EAAA,CAAG,uBAAA,CAAwB,EAAE,SAAA,EAAW,GAAG,kBAAkB,CAAA;AAAA,UAEvE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ","file":"header.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Badge, type BadgeProps } from '../components/badge.js'\nimport { Link } from '../components/link.js'\nimport { Logo } from '../components/logo.js'\n\n/**\n * Surface colours the header can be themed with, sharing the Masthead's and\n * SkipLink's four-name vocabulary (`dark`, `light`, `white`, `grey`) — the three\n * components stack at the top of the page and a service picks one word for the\n * whole chrome.\n *\n * Every pair is WCAG 2.2 AAA (1.4.6, 7:1), computed from the masterbrand oklch\n * tokens. Light mode: grey-800 on white 15.1:1, grey-800 on grey-100 13.8:1,\n * white on primary-800 14.4:1, white on grey-800 15.1:1. Dark mode deepens each\n * surface onto the same family's dark step and clears AAA more comfortably\n * still (17.2:1–20.2:1).\n *\n * Unlike the Masthead — a brand strip whose light/white/grey surfaces are frozen\n * across themes — the header is the page's own surface, so all four follow the\n * theme. Pair `Header color=\"dark\"` with `Masthead color=\"dark\"` when a service\n * wants the two to match in both modes.\n */\nconst headerColors = {\n // Ink values use the RAW masterbrand tokens (--grey-800) rather than\n // Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes an\n // unreferenced @theme key, and referencing one from inside an arbitrary\n // property is not a usage signal. Same reasoning as footer.tsx.\n // (--color-white is safe: `text-white` below is a real utility.)\n dark: 'bg-primary-800 text-white [--header-ink:var(--color-white)] dark:bg-primary-950',\n light:\n 'bg-grey-100 text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--header-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--header-ink:var(--color-white)]',\n grey: 'bg-grey-800 text-white [--header-ink:var(--color-white)] dark:bg-grey-950',\n}\n\ntype HeaderColor = keyof typeof headerColors\n\n// Shared by cva's defaultVariants, the data-color attribute and the logo\n// context, so the four can't drift apart.\nconst DEFAULT_HEADER_COLOR: HeaderColor = 'white'\n\nconst headerVariants = cva(\n [\n 'w-full',\n // The hairline rule derives from the surface's own ink, so it follows every\n // colour variant and both themes from one value. Mirrors the color-mix\n // derivation in footer.tsx (--footer-border) and link.tsx (--link-halo).\n '[--header-border:color-mix(in_oklch,var(--header-ink)_15%,transparent)]',\n 'duration-300 motion-safe:transition-shadow',\n ],\n {\n variants: {\n color: headerColors,\n },\n defaultVariants: {\n color: DEFAULT_HEADER_COLOR,\n },\n },\n)\n\nconst headerContainerVariants = cva(\n [\n 'mx-auto flex w-full flex-wrap items-center justify-between gap-x-4 gap-y-3 max-sm:py-3 sm:max-lg:py-4 lg:py-5',\n // Lateral padding funnels through --header-padding-x so an app can retune it\n // once (via the `style` prop or a utility class) without a new variant. Same\n // mechanism, and the same 16px → 24px → 48px rhythm, as Masthead and Footer.\n 'px-(--header-padding-x)',\n '[--header-padding-x:--spacing(4)] sm:[--header-padding-x:--spacing(6)] lg:[--header-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app parity). --header-max-width is still read so a\n // shell app can constrain the inner wrapper without switching variants.\n fluid: 'max-w-[var(--header-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--header-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Lets `HeaderBrand` adapt its artwork to the surface it is drawn on — the\n * default `Logo` paints its wordmark `nsw-blue-800` and the version `Badge`\n * paints itself `primary-800`, both of which disappear on the `dark`\n * (primary-800) surface. A `logo` node supplied by the consumer overrides the\n * lockup entirely; at that point the choice is theirs.\n */\nconst HeaderColorContext = React.createContext<HeaderColor>(DEFAULT_HEADER_COLOR)\n\n/** Surfaces dark enough to need light-on-dark artwork. */\nconst DARK_SURFACE_COLORS = new Set<HeaderColor>(['dark', 'grey'])\n\ntype HeaderBrandProps = React.ComponentPropsWithoutRef<'div'> & {\n /** Home-page target for the brand link. Defaults to `/`. */\n href?: React.ComponentPropsWithoutRef<typeof Link>['href']\n /** Service or site name shown beside the logo. */\n sitename?: React.ReactNode\n /**\n * Heading level for `sitename`. Omit (the default) to render a `<span>`,\n * which is usually right: the page's own `<h1>` belongs to its main content,\n * and a site name repeated in the header on every page is not the heading\n * that describes this page. Supply a level only when a service deliberately\n * places the site name in the document outline.\n *\n * `1` is excluded for the reason above; `6` is the deepest heading HTML\n * defines.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /**\n * Version string shown in a Badge beside the brand. Sits outside the link,\n * so it never becomes part of the home link's accessible name.\n */\n version?: React.ReactNode\n /**\n * Visually-hidden prefix announced before `version`, giving the bare number\n * context for screen readers (\"2.1.0\" → \"Version 2.1.0\"). Pass an empty\n * string to suppress.\n */\n versionLabel?: string\n /**\n * Props forwarded to the version `Badge` — `size`, `color`, `variant`,\n * `className` and the rest of its API. Use it when the badge has to meet a\n * house rule the default does not, most often a minimum type size:\n *\n * ```tsx\n * <HeaderBrand version=\"2.1.0\" badgeProps={{ size: 'lg' }} />\n * ```\n *\n * An explicit value always wins — including `color`, whose surface-aware\n * default exists to stop the badge painting itself the same colour as a dark\n * header. Overriding it is the same trade as supplying your own `logo` node:\n * the contrast is then yours to check.\n *\n * `undefined` and `null` do *not* win: they fall back to the defaults, so a\n * conditional like `{ color: cond ? 'accent' : undefined }` keeps the\n * surface-aware colour on the falsy branch rather than dropping the badge to\n * cva's own `primary` default.\n *\n * `children` is excluded — the badge's content is `version` and\n * `versionLabel`.\n */\n badgeProps?: Omit<BadgeProps, 'children'>\n /**\n * `true` (default) renders the NSW Government waratah, `false` omits it, and\n * a node replaces it — pass an agency lockup here.\n */\n logo?: boolean | React.ReactNode\n /**\n * Accessible name for the brand link. Left unset by default: the link's name\n * is then its visible content — \"NSW Government\" (from `Logo`'s\n * visually-hidden text) plus `sitename` — which keeps the visible label\n * inside the accessible name (WCAG 2.2, 2.5.3 Label in Name). Overriding it\n * with something like \"Home page\" would break that, so set it only when the\n * brand renders no text at all.\n */\n label?: string\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: the\n * default `Logo` carries a visually-hidden \"NSW Government\", so a brand with\n * neither it nor a `sitename` renders a link with no text at all, and reaches\n * assistive tech unnamed (WCAG 2.2, 4.1.2 Name, Role, Value). A consumer's own\n * logo node is assumed to carry its own text. No-op in production.\n */\nfunction warnIfBrandUnlabelled({\n logo,\n sitename,\n label,\n}: Pick<HeaderBrandProps, 'logo' | 'sitename' | 'label'>) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!logo && !sitename && !label) {\n console.warn(\n '[nswds/ui] HeaderBrand has no logo and no sitename, so its home link has no accessible name — pass `label`.',\n )\n }\n}\n\n/**\n * Logo, site name and optional version badge, linked to the home page. Sits at\n * the start of the `Header` row.\n *\n * The link renders through `Link`, so it picks up the framework link component\n * from `LinkProvider` (next/link et al) rather than hardcoding one.\n */\nfunction HeaderBrand({\n className,\n href = '/',\n sitename,\n headingLevel,\n version,\n versionLabel = 'Version',\n badgeProps,\n logo = true,\n label,\n children,\n ref,\n ...props\n}: HeaderBrandProps) {\n const color = React.useContext(HeaderColorContext)\n const onDarkSurface = DARK_SURFACE_COLORS.has(color)\n const Sitename = headingLevel ? (`h${headingLevel}` as const) : 'span'\n\n warnIfBrandUnlabelled({ logo, sitename, label })\n\n const logoNode =\n logo === true ? (\n <Logo\n logoType={onDarkSurface ? 'reversed' : 'default'}\n // 64px from lg, 56px below it — 56px is the floor, so the lockup stays\n // legible on a phone. Written as mutually exclusive breakpoint ranges\n // rather than `h-14 lg:h-16`: a bare `h-14` a consumer also uses is\n // re-emitted after ours by their own Tailwind build, and a media query\n // adds no specificity, so it would outrank the lg step and freeze the\n // logo at 56px.\n className='w-auto max-lg:h-14 lg:h-16'\n />\n ) : (\n // `false` / `null` fall through as the falsy nodes they are; anything\n // else is the consumer's own lockup.\n logo\n )\n\n return (\n <div\n data-slot='header-brand'\n {...props}\n className={cn('flex grow basis-0 items-center max-sm:gap-3 sm:gap-4', className)}\n ref={ref}\n >\n {/* variant='unstyled' — a brand lockup takes no underline or link\n colour. outline-current resolves to the surface's ink on every\n variant, so the focus indicator contrasts with the header\n (WCAG 2.2, 2.4.13 Focus Appearance). The negative margin keeps the\n indicator from nudging the row. */}\n <Link\n variant='unstyled'\n href={href}\n aria-label={label}\n className='-m-1 flex items-center rounded-sm p-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current max-sm:gap-3 sm:gap-4'\n >\n {logoNode}\n {sitename ? (\n // Brand-blue ink on the light surfaces (14.4:1 on white, 13.2:1 on\n // grey-100 — both WCAG 2.2 AAA). The `dark` surface *is* primary-800\n // and `grey` is nearly as deep, so those keep the header's own white\n // ink; dark mode does the same, matching the `dark:text-white` the\n // light/white variants already set on the surface.\n <Sitename\n className={cn(\n 'font-bold text-balance max-sm:text-lg sm:text-xl',\n !onDarkSurface && 'text-primary-800 dark:text-white',\n )}\n >\n {sitename}\n </Sitename>\n ) : null}\n </Link>\n {version ? (\n // Badge's `primary` ink is primary-800 — the `dark` header's own\n // surface — so dark surfaces take the white badge instead.\n <Badge\n data-slot='header-version'\n {...badgeProps}\n // Derived after the spread rather than before it. Spreading last would\n // let a key that is merely *present* win, so\n // `badgeProps={{ color: cond ? 'accent' : undefined }}` would pass\n // `undefined` through to cva, which falls back to its own\n // `defaultVariants.color` of `primary` — and primary-800 is the dark\n // header's own background, so the badge would vanish into it. `??`\n // keeps explicit values winning while undefined (and null, which\n // cva's VariantProps permits and which would otherwise render an\n // unstyled badge) falls back to the surface-aware default.\n variant={badgeProps?.variant ?? 'soft'}\n color={badgeProps?.color ?? (onDarkSurface ? 'white' : 'primary')}\n >\n {versionLabel ? <span className='sr-only'>{versionLabel} </span> : null}\n {version}\n </Badge>\n ) : null}\n {children}\n </div>\n )\n}\n\ntype HeaderActionsProps = React.ComponentPropsWithoutRef<'div'> & {\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Trailing cluster of header controls — search, theme switcher, sign-in, and\n * the like. Deliberately unopinionated about what goes in it: site search and\n * theme switching are app concerns (they need routing and a theme provider),\n * so the design system supplies the slot and its spacing rather than the\n * widgets.\n *\n * Not a `nav` landmark: a row of controls is not a set of navigation links, and\n * an extra landmark on every page buries the ones that matter. Wrap genuine\n * navigation in your own `<nav>` inside `Header`.\n */\nfunction HeaderActions({ className, ref, ...props }: HeaderActionsProps) {\n return (\n <div\n data-slot='header-actions'\n {...props}\n className={cn(\n 'flex basis-0 items-center justify-end max-sm:gap-2 sm:gap-4 md:grow',\n className,\n )}\n ref={ref}\n />\n )\n}\n\ntype HeaderProps = React.ComponentPropsWithoutRef<'header'> &\n VariantProps<typeof headerVariants> &\n VariantProps<typeof headerContainerVariants> & {\n /** Stick to the top of the viewport as the page scrolls. Defaults to `true`. */\n sticky?: boolean\n /** Hairline rule along the bottom edge. Defaults to `true`. */\n border?: boolean\n /** Raise the header with a shadow once the page is scrolled. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Top-of-page `banner` landmark: brand, site name and header controls. Render\n * it once in a shared layout, below `SkipLinks` and `Masthead`.\n *\n * - `color` themes the surface; all four pairs are WCAG 2.2 AAA and follow the\n * theme in dark mode (see `headerColors`). The bottom rule derives from the\n * surface's ink, so it follows automatically.\n * - `container` selects the inner wrapper layout: `fluid` (full-bleed,\n * nswds-app parity) or `contained` (centred 1200px column, legacy\n * `nsw-container` parity). Fine-tune either with the `--header-max-width`\n * and `--header-padding-x` custom properties.\n * - Scroll position is tracked and exposed as `data-scrolled`, which is what\n * the `shadow` treatment keys off. Style your own scrolled state with it.\n *\n * Compose the row from `HeaderBrand` and `HeaderActions`:\n *\n * ```tsx\n * <Header>\n * <HeaderBrand sitename=\"Design System\" version=\"2.1.0\" />\n * <HeaderActions>\n * <ThemeSwitcher />\n * </HeaderActions>\n * </Header>\n * ```\n *\n * The `banner` landmark comes from the native `<header>` element, which only\n * carries it outside `article`, `aside`, `main`, `nav` and `section` — wrapping\n * `div`s are fine. Keep it out of `<main>`.\n *\n * The default `id=\"nsw-header\"` is kept for compatibility with existing shells\n * that target it (override via the `id` prop).\n */\nfunction Header({\n className,\n color,\n container,\n containerClassName,\n sticky = true,\n border = true,\n shadow = true,\n children,\n ref,\n ...props\n}: HeaderProps) {\n const [isScrolled, setIsScrolled] = React.useState(false)\n\n React.useEffect(() => {\n function onScroll() {\n setIsScrolled(window.scrollY > 0)\n }\n // Read once on mount too: a page restored mid-scroll (back/forward, or a\n // deep link to a fragment) never fires a scroll event.\n onScroll()\n window.addEventListener('scroll', onScroll, { passive: true })\n return () => window.removeEventListener('scroll', onScroll)\n }, [])\n\n return (\n <header\n id='nsw-header'\n data-slot='header'\n data-color={color ?? DEFAULT_HEADER_COLOR}\n // Present-or-absent rather than \"true\"/\"false\", so it reads like Base\n // UI's data-disabled and Tailwind's bare `data-scrolled:` variant works.\n data-scrolled={isScrolled || undefined}\n {...props}\n className={cn(\n headerVariants({ color }),\n // z-40 sits below the z-50 SkipLinks: a sticky header at the same\n // level comes later in the DOM and would paint over a focused skip\n // link, hiding the page's bypass mechanism (WCAG 2.2, 2.4.1).\n sticky && 'sticky top-0 z-40',\n // Always drawn, so the scrolled state changes no box heights.\n border && 'border-b border-(--header-border)',\n // Shadows read as elevation on light surfaces only; in dark mode the\n // rule above carries the separation.\n shadow &&\n 'data-scrolled:shadow-md data-scrolled:shadow-black/5 dark:data-scrolled:shadow-none',\n className,\n )}\n ref={ref}\n >\n <HeaderColorContext.Provider value={color ?? DEFAULT_HEADER_COLOR}>\n <div\n data-slot='header-container'\n className={cn(headerContainerVariants({ container }), containerClassName)}\n >\n {children}\n </div>\n </HeaderColorContext.Provider>\n </header>\n )\n}\n\nexport { Header, HeaderActions, HeaderBrand, headerColors, headerContainerVariants, headerVariants }\nexport type { HeaderActionsProps, HeaderBrandProps, HeaderColor, HeaderProps }\n"]}
|
package/dist/components/input.js
CHANGED
|
@@ -15,7 +15,7 @@ function Input({ className, type, ref, ...props }) {
|
|
|
15
15
|
// No `outline-none` here: it sets `--tw-outline-style: none` globally
|
|
16
16
|
// on the element, which then suppresses the focus outline below
|
|
17
17
|
// (which reads `outline-style: var(--tw-outline-style)`).
|
|
18
|
-
"h-12 w-full min-w-0 rounded-sm px-4 py-2 text-base
|
|
18
|
+
"h-12 w-full min-w-0 rounded-sm px-4 py-2 text-base motion-safe:transition-colors",
|
|
19
19
|
// Every colour routes through the --input-* semantic tokens (layer 3,
|
|
20
20
|
// theme.css / the registry theme item). Dark mode and brand themes
|
|
21
21
|
// restyle the input by remapping tokens — no dark: variants here.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/input.tsx"],"names":["InputPrimitive"],"mappings":";;;;AAOA,SAAS,MAAM,EAAE,SAAA,EAAW,MAAM,GAAA,EAAK,GAAG,OAAM,EAAkC;AAChF,EAAA,uBACE,GAAA;AAAA,IAACA,OAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAA,EAAU,OAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,SAAA,EAAW,EAAA;AAAA;AAAA;AAAA;AAAA,QAIT,
|
|
1
|
+
{"version":3,"sources":["../../src/components/input.tsx"],"names":["InputPrimitive"],"mappings":";;;;AAOA,SAAS,MAAM,EAAE,SAAA,EAAW,MAAM,GAAA,EAAK,GAAG,OAAM,EAAkC;AAChF,EAAA,uBACE,GAAA;AAAA,IAACA,OAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAA,EAAU,OAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,SAAA,EAAW,EAAA;AAAA;AAAA;AAAA;AAAA,QAIT,kFAAA;AAAA;AAAA;AAAA;AAAA,QAIA,+EAAA;AAAA;AAAA,QAEA,kCAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAKA,mHAAA;AAAA;AAAA,QAEA,0HAAA;AAAA;AAAA,QAEA,wCAAA;AAAA;AAAA,QAEA,8EAAA;AAAA;AAAA,QAEA,oLAAA;AAAA,QACA;AAAA,OACF;AAAA,MACC,GAAG;AAAA;AAAA,GACN;AAEJ","file":"input.js","sourcesContent":["'use client'\n\nimport { Input as InputPrimitive } from '@base-ui/react/input'\nimport * as React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nfunction Input({ className, type, ref, ...props }: React.ComponentProps<'input'>) {\n return (\n <InputPrimitive\n ref={ref}\n type={type}\n data-slot='input'\n data-type={type}\n className={cn(\n // No `outline-none` here: it sets `--tw-outline-style: none` globally\n // on the element, which then suppresses the focus outline below\n // (which reads `outline-style: var(--tw-outline-style)`).\n 'h-12 w-full min-w-0 rounded-sm px-4 py-2 text-base motion-safe:transition-colors',\n // Every colour routes through the --input-* semantic tokens (layer 3,\n // theme.css / the registry theme item). Dark mode and brand themes\n // restyle the input by remapping tokens — no dark: variants here.\n 'border border-(--input-border) bg-(--input-surface) text-(--input-foreground)',\n // Hover\n 'hover:bg-(--input-surface-hover)',\n // Focus — `focus-visible:` per the design-system policy (matches\n // Button/Link). For text fields this is behaviour-preserving:\n // browsers flag keyboard-editable controls as :focus-visible even\n // when focused by pointer, so the ring still shows on click.\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--input-ring)',\n // File input slot\n 'file:inline-flex file:h-8 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-(--input-foreground)',\n // Placeholder styles\n 'placeholder:text-(--input-placeholder)',\n // Disabled\n 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',\n // Invalid — 2px danger border, danger hover surface (Figma error variants)\n 'aria-invalid:border-2 aria-invalid:border-(--input-invalid-border) aria-invalid:hover:bg-(--input-invalid-surface-hover) aria-invalid:focus-visible:outline-(--input-invalid-ring)',\n className,\n )}\n {...props}\n />\n )\n}\n\nexport { Input }\n\nexport type InputProps = React.ComponentProps<typeof Input>\n"]}
|
package/dist/components/link.js
CHANGED
|
@@ -6,7 +6,7 @@ import { cn } from '../lib/utils.js';
|
|
|
6
6
|
|
|
7
7
|
const styledBase = [
|
|
8
8
|
// Typography + transition
|
|
9
|
-
"font-medium underline decoration-current underline-offset-4
|
|
9
|
+
"font-medium underline decoration-current underline-offset-4 motion-safe:transition-colors",
|
|
10
10
|
// Text colour derives from --link-color; --link-halo and --link-halo-active
|
|
11
11
|
// derive from --link-color via color-mix so each variant only sets the one
|
|
12
12
|
// token and the hover/active halos follow automatically.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/link.tsx"],"names":[],"mappings":";;;;;AASA,MAAM,UAAA,GAAa;AAAA;AAAA,EAEjB,6GAAA;AAAA;AAAA;AAAA;AAAA,EAIA,qBAAA;AAAA,EACA,qEAAA;AAAA,EACA,4EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,2CAAA;AAAA,EACA,mEAAA;AAAA;AAAA,EAEA,mEAAA;AAAA,EACA,mHAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AACF,CAAA;AAEA,MAAM,YAAA,GAAe,IAAI,EAAA,EAAI;AAAA,EAC3B,QAAA,EAAU;AAAA,IACR,OAAA,EAAS;AAAA,MACP,OAAA,EAAS;AAAA,QACP,GAAG,UAAA;AAAA;AAAA,QAEH,sFAAA;AAAA;AAAA;AAAA;A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AG,YAAA;AAAA,IACH,WAAW,EAAA,CAAG,YAAA,CAAa,EAAE,OAAA,EAAS,GAAG,SAAS,CAAA;AAAA,IAClD;AAAA,GACD,CAAA;AACH;AAQA,SAAS,cAAc,KAAA,EAAsC;AAC3D,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,WAAA,EAAU,MAAA;AAAA,MACV,IAAA,EAAK,cAAA;AAAA,MACL,OAAA,EAAQ,gBAAA;AAAA,MACR,aAAA,EAAY,MAAA;AAAA,MACX,GAAG,KAAA;AAAA,MAEJ,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,qZAAA,EAAsZ;AAAA;AAAA,GACha;AAEJ;AAwBA,SAAS,YAAA,CAAa;AAAA,EACpB,QAAA;AAAA,EACA,IAAA;AAAA,EACA,WAAA,GAAc,sBAAA;AAAA,EACd,MAAA,GAAS,QAAA;AAAA,EACT,GAAA,GAAM,qBAAA;AAAA,EACN,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAsB;AACpB,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,GAAO,IAAA,GAAQ,wBAAQ,GAAA,CAAC,aAAA,EAAA,EAAc,WAAU,QAAA,EAAS,CAAA;AAEvF,EAAA,4BACG,IAAA,EAAA,EAAM,GAAG,KAAA,EAAO,MAAA,EAAgB,KAAU,GAAA,EACxC,QAAA,EAAA;AAAA,IAAA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA,mBAAc,IAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,SAAA,EAAU,QAAA,EAAA;AAAA,MAAA,GAAA;AAAA,MAAE;AAAA,KAAA,EAAY,CAAA,GAAU;AAAA,GAAA,EACnE,CAAA;AAEJ","file":"link.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React, { createContext, useContext } from 'react'\n\nimport { cn } from '../lib/utils.js'\n\n// Shared visual base for all *styled* variants. Pulled out so the `unstyled`\n// variant can omit it entirely (otherwise it wouldn't actually be unstyled).\nconst styledBase = [\n // Typography + transition\n 'font-medium underline decoration-current underline-offset-4 transition-colors motion-reduce:transition-none',\n // Text colour derives from --link-color; --link-halo and --link-halo-active\n // derive from --link-color via color-mix so each variant only sets the one\n // token and the hover/active halos follow automatically.\n 'text-(--link-color)',\n '[--link-halo:color-mix(in_oklch,var(--link-color)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--link-color)_18%,transparent)]',\n // Hover / active halos use box-shadow + background-color rather than\n // padding, so inline links sit flush against surrounding text. The\n // shadows extend the halo 2px above and 4px below the line box, matching\n // the GOV.UK Design System focus pattern.\n 'hover:bg-(--link-halo) hover:decoration-2',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n // Wrapped lines each get their own halo\n '[box-decoration-break:clone] [-webkit-box-decoration-break:clone]',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--link-color)',\n // Default sizing for icon children — without this, an unsized SVG inside\n // a Link collapses to 0×0 in flex layouts. `vertical-align: -0.15em`\n // aligns the icon's box to the text's x-height for inline-flow usage;\n // flex contexts ignore vertical-align and should set `items-baseline` (or\n // similar) on the Link itself. Consumers can override per-icon by passing\n // a `size-*` or `align-*` class on the icon itself.\n '*:data-[slot=icon]:inline-block *:data-[slot=icon]:size-[1em] *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:align-[-0.15em]',\n]\n\nconst linkVariants = cva('', {\n variants: {\n variant: {\n primary: [\n ...styledBase,\n // Link\n '[--link-color:var(--color-primary-800)] dark:[--link-color:var(--color-primary-200)]',\n // Visited — set the text colour directly. `:visited` is restricted by\n // browsers to a small set of paint-only properties (color, *-color,\n // fill, stroke) and ignores custom properties, so we can't shift\n // --link-color here. Setting `text-*` works, and the underline follows\n // because the base uses `decoration-current` (currentColor).\n 'visited:text-primary-600 dark:visited:text-primary-300',\n // Active — deeper halo via --link-halo-active\n 'active:bg-(--link-halo-active) active:decoration-2',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n secondary: [\n ...styledBase,\n '[--link-color:var(--color-primary-200)] dark:[--link-color:var(--color-primary-800)]',\n ],\n white: [\n ...styledBase,\n '[--link-color:var(--color-white)] dark:[--link-color:var(--color-grey-800)]',\n ],\n // Zero classes — the consumer (typically Button / BadgeButton) is\n // supplying its own complete visual treatment and doesn't want any\n // Link styling to compose on top. Intentionally omits the icon defaults\n // too, so the wrapping component has full control of icon sizing.\n unstyled: [],\n },\n },\n defaultVariants: {\n variant: 'primary',\n },\n})\n\ntype LinkComponent = React.ElementType\n\n/**\n * Object form of a link target, mirroring the `UrlObject` accepted by framework\n * link components such as next/link. Used for `Link`'s `href` when a custom\n * element/component is supplied via `as` / `LinkProvider`; a plain anchor still\n * takes a string.\n *\n * Fields are optional, matching next/link. Typing the *shape* — rather than the\n * previous bare `object` — rejects unrelated values like arrays and functions\n * (both carry a numeric `length`, which is incompatible with `length?: never`).\n */\ntype LinkUrlObject = {\n pathname?: string | null\n query?: string | Record<string, unknown> | null\n hash?: string | null\n search?: string | null\n host?: string | null\n hostname?: string | null\n port?: string | number | null\n protocol?: string | null\n /** Brand that excludes arrays/functions (which have a numeric `length`). */\n length?: never\n}\n\ntype LinkProps = Omit<React.ComponentPropsWithoutRef<'a'>, 'href'> &\n VariantProps<typeof linkVariants> & {\n as?: LinkComponent\n href: React.ComponentPropsWithoutRef<'a'>['href'] | LinkUrlObject\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nconst LinkComponentContext = createContext<LinkComponent | null>(null)\n\nfunction LinkProvider({\n children,\n component,\n}: {\n children: React.ReactNode\n component: LinkComponent\n}) {\n return <LinkComponentContext.Provider value={component}>{children}</LinkComponentContext.Provider>\n}\n\n/**\n * Polymorphic anchor wrapper. Renders an `<a>` by default, or any element\n * provided via the `as` prop, or via a `<LinkProvider component={…}>` context\n * (use the context to inject a framework Link like Next.js `next/link`).\n *\n * Hover / active / focus styling on consumers should use the native CSS\n * pseudo-class utilities (`hover:`, `active:`, `focus-visible:`, and their\n * `group-…` variants) — Tailwind v4 maps them to real CSS, no JS state\n * tracking required.\n */\n/**\n * Anchor-only HTML attributes. When `Link` is rendered as a non-anchor\n * intrinsic element (e.g. `as=\"button\"`), forwarding these produces invalid\n * markup like `<button href=\"…\">` and React DOM warnings, so they are\n * stripped. Custom components passed via `as` / `LinkProvider` are assumed to\n * be anchor-like (e.g. `next/link`) and receive the full prop set.\n */\nconst ANCHOR_ONLY_PROPS = [\n 'href',\n 'target',\n 'rel',\n 'download',\n 'ping',\n 'referrerPolicy',\n 'hrefLang',\n] as const\n\nfunction Link({ as, variant, className, ref, ...props }: LinkProps) {\n const ContextLink = useContext(LinkComponentContext)\n const component = as ?? ContextLink ?? 'a'\n\n // Drop anchor-only props when the resolved element is a non-anchor\n // intrinsic tag (e.g. `as=\"button\"`). String components other than 'a'\n // are real DOM tags that can't accept `href`/`target`/etc; non-string\n // components (framework links) keep the full set.\n const isNonAnchorIntrinsic = typeof component === 'string' && component !== 'a'\n\n const elementProps = { ...props } as Record<string, unknown>\n if (isNonAnchorIntrinsic) {\n for (const prop of ANCHOR_ONLY_PROPS) {\n delete elementProps[prop]\n }\n }\n\n return React.createElement(component, {\n ...elementProps,\n className: cn(linkVariants({ variant }), className),\n ref,\n })\n}\n\n/**\n * Open-in-new-tab glyph used by `ExternalLink`. Defined inline (rather than\n * imported from `Icons`) so that consumers of `Link` / `ExternalLink` don't\n * tree-pull the full icon set. Sized and aligned through the `[data-slot=icon]`\n * rules in `linkVariants`.\n */\nfunction OpenInNewIcon(props: React.SVGProps<SVGSVGElement>) {\n return (\n <svg\n data-slot='icon'\n fill='currentColor'\n viewBox='0 -960 960 960'\n aria-hidden='true'\n {...props}\n >\n <path d='M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h240q17 0 28.5 11.5T480-800q0 17-11.5 28.5T440-760H200v560h560v-240q0-17 11.5-28.5T800-480q17 0 28.5 11.5T840-440v240q0 33-23.5 56.5T760-120H200Zm560-584L416-360q-11 11-28 11t-28-11q-11-11-11-28t11-28l344-344H600q-17 0-28.5-11.5T560-800q0-17 11.5-28.5T600-840h200q17 0 28.5 11.5T840-800v200q0 17-11.5 28.5T800-560q-17 0-28.5-11.5T760-600v-104Z' />\n </svg>\n )\n}\n\ntype ExternalLinkProps = LinkProps & {\n /**\n * Screen-reader suffix announced after the link text. Defaults to\n * `\"(opens in a new tab)\"`. Pass an empty string to suppress.\n */\n newTabLabel?: string\n /**\n * Custom trailing icon. Pass `null` to hide the icon entirely. If omitted,\n * the default open-in-new glyph is rendered.\n */\n icon?: React.ReactNode | null\n}\n\n/**\n * Anchor preconfigured for cross-origin / new-tab navigation. Sets\n * `target=\"_blank\"` and `rel=\"noopener noreferrer\"` by default, renders a\n * trailing open-in-new icon, and appends a visually-hidden suffix so screen\n * readers announce that the link opens a new tab.\n *\n * All `Link` props are forwarded — `variant`, `as`, `className`, etc. —\n * and any of `target`, `rel`, `icon`, or `newTabLabel` can be overridden.\n */\nfunction ExternalLink({\n children,\n icon,\n newTabLabel = '(opens in a new tab)',\n target = '_blank',\n rel = 'noopener noreferrer',\n ref,\n ...props\n}: ExternalLinkProps) {\n const trailingIcon = icon === null ? null : (icon ?? <OpenInNewIcon className='ml-0.5' />)\n\n return (\n <Link {...props} target={target} rel={rel} ref={ref}>\n {children}\n {trailingIcon}\n {newTabLabel ? <span className='sr-only'> {newTabLabel}</span> : null}\n </Link>\n )\n}\n\nexport { ExternalLink, Link, LinkProvider, linkVariants }\nexport type { ExternalLinkProps, LinkComponent, LinkProps, LinkUrlObject }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/link.tsx"],"names":[],"mappings":";;;;;AASA,MAAM,UAAA,GAAa;AAAA;AAAA,EAEjB,2FAAA;AAAA;AAAA;AAAA;AAAA,EAIA,qBAAA;AAAA,EACA,qEAAA;AAAA,EACA,4EAAA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AAA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA,mBAAc,IAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,SAAA,EAAU,QAAA,EAAA;AAAA,MAAA,GAAA;AAAA,MAAE;AAAA,KAAA,EAAY,CAAA,GAAU;AAAA,GAAA,EACnE,CAAA;AAEJ","file":"link.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React, { createContext, useContext } from 'react'\n\nimport { cn } from '../lib/utils.js'\n\n// Shared visual base for all *styled* variants. Pulled out so the `unstyled`\n// variant can omit it entirely (otherwise it wouldn't actually be unstyled).\nconst styledBase = [\n // Typography + transition\n 'font-medium underline decoration-current underline-offset-4 motion-safe:transition-colors',\n // Text colour derives from --link-color; --link-halo and --link-halo-active\n // derive from --link-color via color-mix so each variant only sets the one\n // token and the hover/active halos follow automatically.\n 'text-(--link-color)',\n '[--link-halo:color-mix(in_oklch,var(--link-color)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--link-color)_18%,transparent)]',\n // Hover / active halos use box-shadow + background-color rather than\n // padding, so inline links sit flush against surrounding text. The\n // shadows extend the halo 2px above and 4px below the line box, matching\n // the GOV.UK Design System focus pattern.\n 'hover:bg-(--link-halo) hover:decoration-2',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n // Wrapped lines each get their own halo\n '[box-decoration-break:clone] [-webkit-box-decoration-break:clone]',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--link-color)',\n // Default sizing for icon children — without this, an unsized SVG inside\n // a Link collapses to 0×0 in flex layouts. `vertical-align: -0.15em`\n // aligns the icon's box to the text's x-height for inline-flow usage;\n // flex contexts ignore vertical-align and should set `items-baseline` (or\n // similar) on the Link itself. Consumers can override per-icon by passing\n // a `size-*` or `align-*` class on the icon itself.\n '*:data-[slot=icon]:inline-block *:data-[slot=icon]:size-[1em] *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:align-[-0.15em]',\n]\n\nconst linkVariants = cva('', {\n variants: {\n variant: {\n primary: [\n ...styledBase,\n // Link\n '[--link-color:var(--color-primary-800)] dark:[--link-color:var(--color-primary-200)]',\n // Visited — set the text colour directly. `:visited` is restricted by\n // browsers to a small set of paint-only properties (color, *-color,\n // fill, stroke) and ignores custom properties, so we can't shift\n // --link-color here. Setting `text-*` works, and the underline follows\n // because the base uses `decoration-current` (currentColor).\n 'visited:text-primary-600 dark:visited:text-primary-300',\n // Active — deeper halo via --link-halo-active\n 'active:bg-(--link-halo-active) active:decoration-2',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n secondary: [\n ...styledBase,\n '[--link-color:var(--color-primary-200)] dark:[--link-color:var(--color-primary-800)]',\n ],\n white: [\n ...styledBase,\n '[--link-color:var(--color-white)] dark:[--link-color:var(--color-grey-800)]',\n ],\n // Zero classes — the consumer (typically Button / BadgeButton) is\n // supplying its own complete visual treatment and doesn't want any\n // Link styling to compose on top. Intentionally omits the icon defaults\n // too, so the wrapping component has full control of icon sizing.\n unstyled: [],\n },\n },\n defaultVariants: {\n variant: 'primary',\n },\n})\n\ntype LinkComponent = React.ElementType\n\n/**\n * Object form of a link target, mirroring the `UrlObject` accepted by framework\n * link components such as next/link. Used for `Link`'s `href` when a custom\n * element/component is supplied via `as` / `LinkProvider`; a plain anchor still\n * takes a string.\n *\n * Fields are optional, matching next/link. Typing the *shape* — rather than the\n * previous bare `object` — rejects unrelated values like arrays and functions\n * (both carry a numeric `length`, which is incompatible with `length?: never`).\n */\ntype LinkUrlObject = {\n pathname?: string | null\n query?: string | Record<string, unknown> | null\n hash?: string | null\n search?: string | null\n host?: string | null\n hostname?: string | null\n port?: string | number | null\n protocol?: string | null\n /** Brand that excludes arrays/functions (which have a numeric `length`). */\n length?: never\n}\n\ntype LinkProps = Omit<React.ComponentPropsWithoutRef<'a'>, 'href'> &\n VariantProps<typeof linkVariants> & {\n as?: LinkComponent\n href: React.ComponentPropsWithoutRef<'a'>['href'] | LinkUrlObject\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nconst LinkComponentContext = createContext<LinkComponent | null>(null)\n\nfunction LinkProvider({\n children,\n component,\n}: {\n children: React.ReactNode\n component: LinkComponent\n}) {\n return <LinkComponentContext.Provider value={component}>{children}</LinkComponentContext.Provider>\n}\n\n/**\n * Polymorphic anchor wrapper. Renders an `<a>` by default, or any element\n * provided via the `as` prop, or via a `<LinkProvider component={…}>` context\n * (use the context to inject a framework Link like Next.js `next/link`).\n *\n * Hover / active / focus styling on consumers should use the native CSS\n * pseudo-class utilities (`hover:`, `active:`, `focus-visible:`, and their\n * `group-…` variants) — Tailwind v4 maps them to real CSS, no JS state\n * tracking required.\n */\n/**\n * Anchor-only HTML attributes. When `Link` is rendered as a non-anchor\n * intrinsic element (e.g. `as=\"button\"`), forwarding these produces invalid\n * markup like `<button href=\"…\">` and React DOM warnings, so they are\n * stripped. Custom components passed via `as` / `LinkProvider` are assumed to\n * be anchor-like (e.g. `next/link`) and receive the full prop set.\n */\nconst ANCHOR_ONLY_PROPS = [\n 'href',\n 'target',\n 'rel',\n 'download',\n 'ping',\n 'referrerPolicy',\n 'hrefLang',\n] as const\n\nfunction Link({ as, variant, className, ref, ...props }: LinkProps) {\n const ContextLink = useContext(LinkComponentContext)\n const component = as ?? ContextLink ?? 'a'\n\n // Drop anchor-only props when the resolved element is a non-anchor\n // intrinsic tag (e.g. `as=\"button\"`). String components other than 'a'\n // are real DOM tags that can't accept `href`/`target`/etc; non-string\n // components (framework links) keep the full set.\n const isNonAnchorIntrinsic = typeof component === 'string' && component !== 'a'\n\n const elementProps = { ...props } as Record<string, unknown>\n if (isNonAnchorIntrinsic) {\n for (const prop of ANCHOR_ONLY_PROPS) {\n delete elementProps[prop]\n }\n }\n\n return React.createElement(component, {\n ...elementProps,\n className: cn(linkVariants({ variant }), className),\n ref,\n })\n}\n\n/**\n * Open-in-new-tab glyph used by `ExternalLink`. Defined inline (rather than\n * imported from `Icons`) so that consumers of `Link` / `ExternalLink` don't\n * tree-pull the full icon set. Sized and aligned through the `[data-slot=icon]`\n * rules in `linkVariants`.\n */\nfunction OpenInNewIcon(props: React.SVGProps<SVGSVGElement>) {\n return (\n <svg\n data-slot='icon'\n fill='currentColor'\n viewBox='0 -960 960 960'\n aria-hidden='true'\n {...props}\n >\n <path d='M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h240q17 0 28.5 11.5T480-800q0 17-11.5 28.5T440-760H200v560h560v-240q0-17 11.5-28.5T800-480q17 0 28.5 11.5T840-440v240q0 33-23.5 56.5T760-120H200Zm560-584L416-360q-11 11-28 11t-28-11q-11-11-11-28t11-28l344-344H600q-17 0-28.5-11.5T560-800q0-17 11.5-28.5T600-840h200q17 0 28.5 11.5T840-800v200q0 17-11.5 28.5T800-560q-17 0-28.5-11.5T760-600v-104Z' />\n </svg>\n )\n}\n\ntype ExternalLinkProps = LinkProps & {\n /**\n * Screen-reader suffix announced after the link text. Defaults to\n * `\"(opens in a new tab)\"`. Pass an empty string to suppress.\n */\n newTabLabel?: string\n /**\n * Custom trailing icon. Pass `null` to hide the icon entirely. If omitted,\n * the default open-in-new glyph is rendered.\n */\n icon?: React.ReactNode | null\n}\n\n/**\n * Anchor preconfigured for cross-origin / new-tab navigation. Sets\n * `target=\"_blank\"` and `rel=\"noopener noreferrer\"` by default, renders a\n * trailing open-in-new icon, and appends a visually-hidden suffix so screen\n * readers announce that the link opens a new tab.\n *\n * All `Link` props are forwarded — `variant`, `as`, `className`, etc. —\n * and any of `target`, `rel`, `icon`, or `newTabLabel` can be overridden.\n */\nfunction ExternalLink({\n children,\n icon,\n newTabLabel = '(opens in a new tab)',\n target = '_blank',\n rel = 'noopener noreferrer',\n ref,\n ...props\n}: ExternalLinkProps) {\n const trailingIcon = icon === null ? null : (icon ?? <OpenInNewIcon className='ml-0.5' />)\n\n return (\n <Link {...props} target={target} rel={rel} ref={ref}>\n {children}\n {trailingIcon}\n {newTabLabel ? <span className='sr-only'> {newTabLabel}</span> : null}\n </Link>\n )\n}\n\nexport { ExternalLink, Link, LinkProvider, linkVariants }\nexport type { ExternalLinkProps, LinkComponent, LinkProps, LinkUrlObject }\n"]}
|
|
@@ -149,7 +149,7 @@ const mainNavItemInk = "[--nav-menu-ink:var(--main-nav-ink)] dark:[--nav-menu-in
|
|
|
149
149
|
const mainNavPanelInk = "[--nav-menu-ink:var(--main-nav-panel-ink)] dark:[--nav-menu-ink:var(--main-nav-panel-ink)]";
|
|
150
150
|
const mainNavTriggerClassName = [
|
|
151
151
|
mainNavItemInk,
|
|
152
|
-
"mb-0 h-auto min-h-14 w-auto justify-start rounded-none px-4 py-2 text-base leading-6 font-bold text-(--main-nav-ink)",
|
|
152
|
+
"mb-0 h-auto min-h-14 w-auto justify-start rounded-none max-lg:px-4 py-2 text-base leading-6 font-bold text-(--main-nav-ink)",
|
|
153
153
|
"lg:px-8",
|
|
154
154
|
"[&_svg]:size-6",
|
|
155
155
|
"data-popup-open:shadow-[inset_0_-4px_0_0_currentColor]",
|
|
@@ -157,7 +157,7 @@ const mainNavTriggerClassName = [
|
|
|
157
157
|
].join(" ");
|
|
158
158
|
const mainNavTopLinkClassName = [
|
|
159
159
|
mainNavItemInk,
|
|
160
|
-
"inline-flex min-h-14 flex-row items-center justify-start gap-1 rounded-none px-4 py-2 text-base leading-6 font-bold whitespace-nowrap text-(--main-nav-ink)",
|
|
160
|
+
"inline-flex min-h-14 flex-row items-center justify-start gap-1 rounded-none max-lg:px-4 py-2 text-base leading-6 font-bold whitespace-nowrap text-(--main-nav-ink)",
|
|
161
161
|
"lg:px-8",
|
|
162
162
|
"data-active:shadow-[inset_0_-4px_0_0_currentColor]"
|
|
163
163
|
].join(" ");
|
|
@@ -233,7 +233,7 @@ function MainNavMenuItem({ item, color, currentHref, panelWidth }) {
|
|
|
233
233
|
IconEast,
|
|
234
234
|
{
|
|
235
235
|
"aria-hidden": "true",
|
|
236
|
-
className: "ml-4 size-6 shrink-0 text-current
|
|
236
|
+
className: "ml-4 size-6 shrink-0 text-current duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover:translate-x-1 motion-safe:transition-transform"
|
|
237
237
|
}
|
|
238
238
|
)
|
|
239
239
|
]
|
|
@@ -243,7 +243,7 @@ function MainNavMenuItem({ item, color, currentHref, panelWidth }) {
|
|
|
243
243
|
"div",
|
|
244
244
|
{
|
|
245
245
|
"data-slot": "main-nav-panel-links",
|
|
246
|
-
className: "grid
|
|
246
|
+
className: "grid overflow-hidden px-4 pb-12 max-sm:grid-cols-1 sm:max-lg:grid-cols-2 lg:grid-cols-3",
|
|
247
247
|
children: links.map((link, index) => /* @__PURE__ */ jsx(
|
|
248
248
|
NavigationMenuLink,
|
|
249
249
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/main-nav.tsx"],"names":[],"mappings":";;;;;;;AAoCA,MAAM,aAAA,GAAgB;AAAA,EACpB,aAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF;AAMA,MAAM,sBAAA,GAAuC,OAAA;AAE7C,MAAM,eAAA,GAAkB,GAAA;AAAA,EACtB;AAAA,IACE,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAUA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAeR,KAAA,EAAO;AAAA,QACL,aAAA,EACE,mFAAA;AAAA,QACF,aAAA,EACE,mFAAA;AAAA,QACF,aAAA,EACE,kJAAA;AAAA,Q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,EAAA,EAAI,CAAA;AAAA,cACb,SAAA,EAAU,iCAAA;AAAA,cACV,IAAA,EAAK,QAAA;AAAA,cACL,UAAA,EAAY,CAAA;AAAA,cACZ,KAAA,EAAM,OAAA;AAAA,cACN,WAAA;AAAA,cACA,gBAAA,EAAkB,CAAA;AAAA,cAClB,kBAAA,EAAoB,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,MAAA,EAAO;AAAA,cAClD,UAAA,EAAY,GAAA;AAAA,cAGZ,cAAA,EAAe,yBAAA;AAAA,cAMf,YAAY,UAAA,KAAe,IAAA,GAAO,MAAA,GAAY,EAAE,OAAO,UAAA,EAAW;AAAA,cAElE,8BAAC,kBAAA,EAAA,EAAmB,SAAA,EAAU,yCAC3B,QAAA,EAAA,UAAA,CAAW,GAAA,CAAI,CAAC,IAAA,qBACf,GAAA;AAAA,gBAAC,eAAA;AAAA,gBAAA;AAAA,kBAEC,IAAA;AAAA,kBACA,OAAO,KAAA,IAAS,sBAAA;AAAA,kBAChB,WAAA;AAAA,kBACA;AAAA,iBAAA;AAAA,gBAJK,GAAG,IAAA,CAAK,KAAK,CAAA,CAAA,EAAI,IAAA,CAAK,QAAQ,SAAS,CAAA;AAAA,eAM/C,CAAA,EACH;AAAA;AAAA;AACF;AAAA;AACF;AAAA,GACF;AAEJ","file":"main-nav.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { IconEast } from '../icons/east.js'\nimport { cn } from '../lib/utils.js'\n\nimport {\n NavigationMenu,\n NavigationMenuContent,\n NavigationMenuItem,\n NavigationMenuLink,\n NavigationMenuList,\n NavigationMenuTrigger,\n} from '../components/navigation-menu.js'\n\n/**\n * Surface colours the main navigation can be themed with — exactly the\n * Footer's thirteen-name vocabulary, so a service that themes its footer\n * `primary-800` writes the same word here. Each name is the LIGHT-mode\n * surface; dark mode deepens it onto the same family's dark steps (see the\n * `color` variants below), so `color` expresses tonal weight rather than a\n * literal colour.\n *\n * The bar's text/background pairs are identical to the Footer's, so its\n * contrast conclusions carry over verbatim: every light pair clears WCAG 2.2\n * AA (1.4.3, 4.5:1) for the bar's text and 11 of the 13 also clear AAA\n * (1.4.6, 7:1). The two AA-only pairs are `primary-600` (4.57:1) and\n * `accent-600` (5.18:1), both with white ink; prefer the `-800` steps when a\n * service is held to AAA. In dark mode all thirteen clear AAA (worst 13.6:1).\n *\n * The mega panels always render on the house popup surface (`bg-popover`),\n * matching the nswds-app source where every dropdown was white regardless of\n * bar colour — only the panel's accent ink follows the colour family.\n */\nconst mainNavColors = [\n 'primary-800',\n 'primary-600',\n 'primary-400',\n 'primary-200',\n 'grey-800',\n 'grey-600',\n 'grey-400',\n 'grey-200',\n 'accent-800',\n 'accent-600',\n 'accent-400',\n 'accent-200',\n 'white',\n] as const\n\ntype MainNavColor = (typeof mainNavColors)[number]\n\n// Shared by cva's defaultVariants, the data-color attribute and the panel\n// variant lookup, so the three can't drift apart.\nconst DEFAULT_MAIN_NAV_COLOR: MainNavColor = 'white'\n\nconst mainNavVariants = cva(\n [\n 'w-full',\n // Every derived colour on the bar resolves from a single --main-nav-ink\n // token, so a colour variant only has to declare the surface utilities and\n // that one value — this replaces the nswds-app source's hand-written\n // 13-variant × 8-slot style table. The border derivation is written\n // literally here (once) rather than per-variant: Tailwind scans source\n // text for class names, so a template-built arbitrary property would\n // never be emitted. Hover/active halos are not derived here — the\n // triggers ride navigation-menu.tsx's --nav-menu-halo chain, re-pointed\n // at this ink (see mainNavItemInk), so there is exactly one halo recipe.\n '[--main-nav-border:color-mix(in_oklch,var(--main-nav-ink)_15%,transparent)]',\n ],\n {\n variants: {\n // Ink values use the RAW masterbrand tokens (--primary-800, --grey-800,\n // --accent-800) rather than Tailwind's --color-* bridge aliases. Tailwind\n // v4 tree-shakes an unreferenced @theme key, and referencing one from\n // inside an arbitrary property is not a usage signal — the raw tokens are\n // plain :root declarations from @nswds/tokens and always resolve.\n // (--color-white is safe: `text-white` / `bg-white` below are real\n // utilities, so that key is always emitted.)\n //\n // Dark mode deepens every surface onto the same family's dark steps —\n // -800→-950, -600→-900, -400→-850, -200→-800, white→grey-900 — the\n // Footer's exact mapping, so the luminance ORDER within a family is\n // preserved and a stacked Footer + MainNav sharing one colour word stay\n // in step in both themes. Ink goes white on all thirteen; every dark\n // pair is WCAG 2.2 AAA (worst 13.6:1).\n color: {\n 'primary-800':\n 'bg-primary-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-primary-950',\n 'primary-600':\n 'bg-primary-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-primary-900',\n 'primary-400':\n 'bg-primary-400 text-primary-800 [--main-nav-ink:var(--primary-800)] dark:bg-primary-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'primary-200':\n 'bg-primary-200 text-primary-800 [--main-nav-ink:var(--primary-800)] dark:bg-primary-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'grey-800': 'bg-grey-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-grey-950',\n 'grey-600': 'bg-grey-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-grey-900',\n 'grey-400':\n 'bg-grey-400 text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'grey-200':\n 'bg-grey-200 text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'accent-800':\n 'bg-accent-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-accent-950',\n 'accent-600':\n 'bg-accent-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-accent-900',\n 'accent-400':\n 'bg-accent-400 text-accent-800 [--main-nav-ink:var(--accent-800)] dark:bg-accent-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'accent-200':\n 'bg-accent-200 text-accent-800 [--main-nav-ink:var(--accent-800)] dark:bg-accent-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n },\n // Rules along the bar's edges, drawn from the ink-derived border token so\n // they follow every colour variant and both themes. Replaces the app\n // source's deprecated showTopBorder/showBottomBorder booleans, which are\n // deliberately not ported.\n border: {\n none: '',\n top: 'border-t border-(--main-nav-border)',\n bottom: 'border-b border-(--main-nav-border)',\n both: 'border-y border-(--main-nav-border)',\n },\n },\n defaultVariants: {\n color: DEFAULT_MAIN_NAV_COLOR,\n border: 'none',\n },\n },\n)\n\nconst mainNavContainerVariants = cva(\n [\n 'mx-auto flex w-full items-center',\n // Lateral padding funnels through --main-nav-padding-x so an app can\n // retune it once (via the `style` prop or a utility class) without a new\n // variant. Same mechanism, and the same 16px → 24px → 48px rhythm, as\n // Masthead, Header and Footer.\n 'px-(--main-nav-padding-x)',\n '[--main-nav-padding-x:--spacing(4)] sm:[--main-nav-padding-x:--spacing(6)] lg:[--main-nav-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app fullBleed parity). --main-nav-max-width is\n // still read so a shell app can constrain the inner wrapper without\n // switching variants.\n fluid: 'max-w-[var(--main-nav-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--main-nav-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Mega-panel accent ink, keyed by the same thirteen colour names as the bar.\n * The panel itself is always the house popup surface (`bg-popover`, white in\n * light mode) — parity with the app source, whose dropdown was white for\n * every variant — so the family only tints the featured lead link, hover ink\n * and cell borders. Declared on the Content element (not inherited from the\n * bar) because Base UI portals the panel to `document.body`: a custom\n * property set on the `<nav>` can never reach it.\n *\n * Light inks are the family's -800 step on white — grey-800 on white is\n * 15.1:1 and white on primary-800 is 14.4:1 (both AAA; contrast is symmetric,\n * ratios from header.tsx); accent-800 on white clears AAA per the Footer's\n * verified pairs. Dark inks step to the family's -200 — the same dark-mode\n * interactive ink link.tsx and navigation-menu.tsx already use on this\n * popover surface. The featured lead is text-xl bold, so even the softest\n * pair is far above the large-text AA floor (1.4.3, 3:1).\n */\nconst mainNavPanelVariants = cva(\n [\n 'p-0 whitespace-normal',\n // The sibling Content (and the shared popup, via popupClassName below)\n // cap themselves at --available-width, which Base UI measures from the\n // active trigger — for a mid-bar trigger that is less than the nav's\n // width, which would shrink right-hand panels. The panel's width is\n // container-measured and can never exceed the viewport, so the cap is\n // safely lifted.\n 'max-w-none',\n '[--main-nav-panel-border:color-mix(in_oklch,var(--main-nav-panel-ink)_15%,transparent)]',\n ],\n {\n variants: {\n color: {\n 'primary-800':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-600':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-400':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-200':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'grey-800':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-600':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-400':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-200':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'accent-800':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-600':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-400':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-200':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n white: '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n },\n },\n defaultVariants: {\n color: DEFAULT_MAIN_NAV_COLOR,\n },\n },\n)\n\n// Re-points the sibling navigation-menu's ink at the bar's surface ink. The\n// trigger/link halos and focus outlines in navigation-menu.tsx all derive\n// from --nav-menu-ink via color-mix ON THE SAME ELEMENT, so overriding the\n// one token retargets the whole chain: hover/active halos and the\n// focus-visible outline become surface-relative, guaranteeing the indicator\n// contrasts on all thirteen surfaces (WCAG 2.2, 2.4.13 Focus Appearance).\n// Both light and dark are overridden because the sibling pins its own\n// dark-mode ink (primary-200); --main-nav-ink is already theme-aware.\nconst mainNavItemInk =\n '[--nav-menu-ink:var(--main-nav-ink)] dark:[--nav-menu-ink:var(--main-nav-ink)]'\n\n// Same re-point for links INSIDE the portalled panel, where the bar's ink\n// cannot reach — these derive from the panel accent ink instead.\nconst mainNavPanelInk =\n '[--nav-menu-ink:var(--main-nav-panel-ink)] dark:[--nav-menu-ink:var(--main-nav-panel-ink)]'\n\n// Restyles the sibling trigger to the app source's bar metrics: 56px min\n// height, square corners, bold base text, wider gutters from lg up. The open\n// panel is marked with the app's 4px inset underline (data-popup-open comes\n// from Base UI); data-current draws the same underline persistently when\n// `currentHref` falls inside this section, so the underline means \"you are\n// here\" at rest and \"this panel is open\" during use.\nconst mainNavTriggerClassName = [\n mainNavItemInk,\n 'mb-0 h-auto min-h-14 w-auto justify-start rounded-none px-4 py-2 text-base leading-6 font-bold text-(--main-nav-ink)',\n 'lg:px-8',\n '[&_svg]:size-6',\n 'data-popup-open:shadow-[inset_0_-4px_0_0_currentColor]',\n 'data-current:shadow-[inset_0_-4px_0_0_currentColor]',\n].join(' ')\n\n// A panel-less item, restyled from the sibling link to sit visually beside\n// the triggers (cn's conflict merge lets these win over the link's stacked\n// defaults). `active` → data-active draws the current-page underline; Base UI\n// pairs it with aria-current='page' on the same element (WCAG 2.4.8).\nconst mainNavTopLinkClassName = [\n mainNavItemInk,\n 'inline-flex min-h-14 flex-row items-center justify-start gap-1 rounded-none px-4 py-2 text-base leading-6 font-bold whitespace-nowrap text-(--main-nav-ink)',\n 'lg:px-8',\n 'data-active:shadow-[inset_0_-4px_0_0_currentColor]',\n].join(' ')\n\n// The featured lead link at the top of a mega panel: the section title,\n// oversized, with an east arrow that nudges forward on hover (the app\n// source's exact affordance, on the house easing curve; the nudge is a\n// transition, so motion-reduce users get an instant state change — WCAG\n// 2.3.3). `group` scopes the icon's group-hover to this anchor — the panel is\n// portalled, so no other `group` ancestor can capture it.\nconst mainNavFeaturedLinkClassName = [\n mainNavPanelInk,\n 'group relative flex-row items-center rounded-none px-8 py-8 text-xl font-bold whitespace-normal text-(--main-nav-panel-ink)',\n].join(' ')\n\n// The lead when the section has no `href`: the same visual weight as the\n// featured link, but a plain heading row — no anchor (a dead link announced\n// as a link fails the reader who activates it), no hover halo, and no east\n// arrow (an arrow on a non-link promises navigation that never happens). No\n// mainNavPanelInk re-point either: that chain only feeds interactive halos.\nconst mainNavFeaturedHeadingClassName =\n 'flex flex-row items-center px-8 py-8 text-xl font-bold whitespace-normal text-(--main-nav-panel-ink)'\n\n// One bordered grid cell per section link. The anchor itself is the cell —\n// the app source wrapped a div around a stretched-link span, but making the\n// whole cell the anchor gives the same hit area with one element and no\n// aria-hidden overlay. Cells draw a top hairline from the panel ink; the last\n// grid row closes with a bottom hairline via the app's :nth-last-child(-n+3)\n// selector (tuned to the widest, 3-column layout — at narrower widths the\n// final one or two cells simply carry the closing rule, matching the app).\nconst mainNavSectionLinkClassName = [\n mainNavPanelInk,\n 'relative mx-2 justify-center rounded-none border-t border-(--main-nav-panel-border) p-4 text-base font-semibold whitespace-normal text-popover-foreground',\n 'hover:text-(--main-nav-panel-ink)',\n '[&:nth-last-child(-n+3)]:border-b',\n].join(' ')\n\n/** One link inside a mega panel. */\ntype MainNavLinkItem = {\n /** Visible link text, e.g. \"Find support near you\". */\n title: string\n href: string\n}\n\n/**\n * One top-level navigation item. With `links` it renders as a trigger opening\n * a mega panel (with `href` becoming the panel's featured lead link; without\n * an `href` the lead is a plain heading row — dev builds warn); without\n * `links` it renders as a plain link styled like the triggers. Recursion is\n * deliberately one level deep — mega panels list flat links, per the app\n * source's NavigationSection shape.\n */\ntype MainNavItem = {\n title: string\n href?: string\n links?: MainNavLinkItem[]\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: an item\n * with neither `href` nor `links` renders a dead `\"#\"` link — almost always a\n * data mistake, and a trap for keyboard and screen-reader users who activate\n * it and go nowhere. A section (`links`, no `href`) is legal but demoted —\n * its panel lead renders as a plain heading instead of the featured link —\n * so it gets its own nudge. No-op in production.\n */\nfunction warnIfItemUnlinked(item: MainNavItem) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] MainNav item \"${item.title}\" has no href and no links — it will render as a dead \"#\" link.`,\n )\n }\n if (!item.href && item.links?.length) {\n console.warn(\n `[nswds/ui] MainNav section \"${item.title}\" has links but no href — its panel lead renders as a plain heading; pass href to make it a link.`,\n )\n }\n}\n\ntype MainNavMenuItemProps = {\n item: MainNavItem\n color: MainNavColor\n currentHref?: string\n /** Measured container width, forwarded as the panel's inline width. */\n panelWidth: number | null\n}\n\n/**\n * One bar entry: a plain link for items without `links`, a trigger + mega\n * panel for items with them. Internal — the data-driven `MainNav` API is the\n * public surface; compose the navigation-menu primitives directly for layouts\n * this doesn't cover.\n */\nfunction MainNavMenuItem({ item, color, currentHref, panelWidth }: MainNavMenuItemProps) {\n warnIfItemUnlinked(item)\n\n const links = item.links\n const isExactCurrent = item.href !== undefined && item.href === currentHref\n const isSectionCurrent =\n isExactCurrent ||\n (currentHref !== undefined && (links?.some((link) => link.href === currentHref) ?? false))\n\n if (!links?.length) {\n return (\n <NavigationMenuItem className='shrink-0'>\n <NavigationMenuLink\n data-slot='main-nav-top-link'\n href={item.href ?? '#'}\n active={isExactCurrent}\n className={mainNavTopLinkClassName}\n >\n {item.title}\n </NavigationMenuLink>\n </NavigationMenuItem>\n )\n }\n\n return (\n <NavigationMenuItem className='shrink-0'>\n {/* The trigger is a button (it discloses, it doesn't navigate), so it\n can't carry aria-current — data-current draws the visual \"you are\n here\" underline while the aria-current announcement lives on the\n exact matching link inside the panel. */}\n <NavigationMenuTrigger\n data-current={isSectionCurrent || undefined}\n className={mainNavTriggerClassName}\n >\n {item.title}\n </NavigationMenuTrigger>\n {/* Inline width (not a CSS var): the panel is portalled to\n document.body, so a custom property set on the nav can't reach it.\n Before the first measurement resolves the panel falls back to the\n sibling's natural w-max sizing. */}\n <NavigationMenuContent\n data-slot='main-nav-panel'\n className={mainNavPanelVariants({ color })}\n style={panelWidth === null ? undefined : { width: panelWidth }}\n >\n <div className='grid w-full'>\n {/* No section href → no featured LINK: an `href=\"#\"` fallback here\n would be a dead link announced as a link. The heading row keeps\n the lead's visual weight without the anchor, halo or arrow — see\n mainNavFeaturedHeadingClassName. */}\n {item.href === undefined ? (\n <div data-slot='main-nav-featured-heading' className={mainNavFeaturedHeadingClassName}>\n {item.title}\n </div>\n ) : (\n <NavigationMenuLink\n data-slot='main-nav-featured-link'\n href={item.href}\n active={isExactCurrent}\n className={mainNavFeaturedLinkClassName}\n >\n {item.title}\n <IconEast\n aria-hidden='true'\n className='ml-4 size-6 shrink-0 text-current transition-transform duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover:translate-x-1 motion-reduce:transition-none'\n />\n </NavigationMenuLink>\n )}\n <div\n data-slot='main-nav-panel-links'\n className='grid grid-cols-1 overflow-hidden px-4 pb-12 sm:grid-cols-2 lg:grid-cols-3'\n >\n {links.map((link, index) => (\n <NavigationMenuLink\n key={`${link.title}-${link.href}-${index}`}\n data-slot='main-nav-section-link'\n href={link.href}\n active={link.href === currentHref}\n className={mainNavSectionLinkClassName}\n >\n {link.title}\n </NavigationMenuLink>\n ))}\n </div>\n </div>\n </NavigationMenuContent>\n </NavigationMenuItem>\n )\n}\n\ntype MainNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> &\n VariantProps<typeof mainNavVariants> &\n VariantProps<typeof mainNavContainerVariants> & {\n /** Top-level items; items with `links` open mega panels. */\n navigation: MainNavItem[]\n /**\n * The current page's href. The exact matching link gets\n * `aria-current=\"page\"`, and the top-level item it belongs to (a plain\n * link, or the trigger whose panel contains it) gets the current-item\n * underline. The app source read this from next/navigation's\n * `usePathname` — a framework API this package must not import; compare\n * in the consumer and pass the result down.\n */\n currentHref?: string\n /**\n * Stick to the top of the viewport as the page scrolls. Defaults to\n * `false`. When the nav renders below a sticky `Header`, set\n * `--main-nav-top` to the header's height so the two stack instead of\n * overlapping — this custom property replaces the app source's\n * `useSelectorHeight` DOM-measuring hook (the app measured `#nsw-header`\n * on every resize; a consumer that needs a live value can still measure\n * its own header and write the property, see the Sticky story).\n */\n sticky?: boolean\n /** Drop shadow under the bar. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Full-width NSW site navigation bar with mega-menu panels — the data-driven\n * consolidation of the nswds-app `NavigationMenuMainNavigation` /\n * `MainNavigation` components, rebuilt on this package's `NavigationMenu`\n * (Base UI underneath).\n *\n * - `navigation` drives everything: items with `links` render a trigger whose\n * mega panel shows a featured lead link (the section `href`; with no `href`\n * the lead demotes to a plain heading row — dev builds warn) above a\n * responsive 1/2/3-column grid of bordered section links; items without\n * `links` render plain links styled like the triggers. All anchors render\n * through `Link`, so a framework link injected via `LinkProvider`\n * (e.g. next/link) is used automatically.\n * - `color` themes the bar with the Footer's thirteen-name vocabulary and its\n * exact dark-mode deepening; every derived colour (halos, borders, focus\n * outlines) resolves from a single `--main-nav-ink` per variant. Contrast\n * conclusions are the Footer's, verbatim (see `mainNavColors`).\n * - Panels span the nav container's full width: a ResizeObserver on the inner\n * container feeds each panel's inline width, and an `alignOffset` function\n * shifts Base UI's trigger-anchored positioner back to the container's left\n * edge (measured at position time from the open trigger, so it is exact for\n * every trigger — this replaces the app source's panelMetrics state).\n * Assumes LTR; see the class comments.\n * - `container`, `border`, `shadow`, `sticky` mirror the house chrome\n * components; the app's deprecated `showTopBorder`/`showBottomBorder` and\n * `responsive` props are not ported (use `border` and\n * `className=\"hidden lg:block\"`).\n *\n * Accessibility: the outer `<nav>` is the landmark (default label \"Main\n * navigation\"; Base UI's own root is demoted to a `<div>` via `render` so the\n * page doesn't gain a nested nav landmark). Everything interactive is\n * inherited from Base UI via the sibling: triggers are real buttons with\n * `aria-expanded`/`aria-controls`, ArrowDown/Enter opens, arrow keys rove,\n * Escape and focus-out close, and the current page announces\n * `aria-current=\"page\"` (WCAG 2.4.8). Focus indicators are 2px ink-derived\n * outlines that contrast on all thirteen surfaces and on the panel surface\n * (2.4.7, 2.4.13). The 220ms `closeDelay` reproduces the app's hover-out\n * grace timer through Base UI instead of a hand-rolled setTimeout.\n *\n * The default `id=\"nsw-main-navigation\"` is kept for compatibility with\n * existing shells that target it (override via the `id` prop).\n */\nfunction MainNav({\n className,\n containerClassName,\n color,\n container,\n border,\n navigation,\n currentHref,\n sticky = false,\n shadow = true,\n 'aria-label': ariaLabel = 'Main navigation',\n ref,\n ...props\n}: MainNavProps) {\n const containerRef = React.useRef<HTMLDivElement>(null)\n const [panelWidth, setPanelWidth] = React.useState<number | null>(null)\n\n React.useEffect(() => {\n const element = containerRef.current\n if (!element) {\n return\n }\n const measure = () => {\n setPanelWidth(element.getBoundingClientRect().width)\n }\n // Read once on mount: panels can open before the first resize.\n measure()\n const observer = new ResizeObserver(measure)\n observer.observe(element)\n return () => observer.disconnect()\n }, [])\n\n // Shifts the popup from Base UI's anchor (the open trigger) to the\n // container's left edge. Called by the positioner at position time, when\n // the open trigger is findable via data-popup-open — so the offset is exact\n // per trigger with no per-trigger state. Assumes LTR (`align='start'` maps\n // to the left edge); RTL would need the mirrored calculation.\n //\n // The ref caches the last successful offset for the windows when NO trigger\n // carries data-popup-open — chiefly the ~300ms close fade, when a recompute\n // (scroll/resize mid-fade) returning 0 would snap the still-visible\n // full-width panel back to the trigger's edge. Repeating the last real\n // offset holds the fading panel where it was.\n const lastAlignOffsetRef = React.useRef(0)\n const alignOffset = React.useCallback(() => {\n const element = containerRef.current\n if (!element) {\n return lastAlignOffsetRef.current\n }\n const trigger = element.querySelector('[data-popup-open]')\n if (!trigger) {\n return lastAlignOffsetRef.current\n }\n lastAlignOffsetRef.current =\n element.getBoundingClientRect().left - trigger.getBoundingClientRect().left\n return lastAlignOffsetRef.current\n }, [])\n\n return (\n <nav\n id='nsw-main-navigation'\n data-slot='main-nav'\n data-color={color ?? DEFAULT_MAIN_NAV_COLOR}\n aria-label={ariaLabel}\n {...props}\n className={cn(\n mainNavVariants({ color, border }),\n // z-40 matches Header (both sit below the z-50 SkipLinks). An app\n // stacking this under a sticky Header sets --main-nav-top to the\n // header's height.\n sticky && 'sticky top-[var(--main-nav-top,0px)] z-40',\n // House scrolled-header shadow; in dark mode borders carry separation.\n shadow && 'shadow-md shadow-black/5 dark:shadow-none',\n className,\n )}\n ref={ref}\n >\n <div\n ref={containerRef}\n data-slot='main-nav-container'\n className={cn(mainNavContainerVariants({ container }), containerClassName)}\n >\n {/* render={<div/>}: Base UI's root is itself a <nav>; demoting it\n keeps this component to ONE navigation landmark. sideOffset 0\n seats the panel flush under the bar; collision handling is off\n because alignOffset/width already pin the panel inside the\n viewport. closeDelay 220 = the app's PANEL_CLOSE_DELAY_MS. */}\n <NavigationMenu\n render={<div />}\n className='w-full max-w-none justify-start'\n side='bottom'\n sideOffset={0}\n align='start'\n alignOffset={alignOffset}\n collisionPadding={0}\n collisionAvoidance={{ side: 'none', align: 'none' }}\n closeDelay={220}\n // Square corners (the full-width panel meets the bar edge-to-edge)\n // and no --available-width cap — see mainNavPanelVariants.\n popupClassName='max-w-none rounded-none'\n // The popup itself must follow the measured width too: Base UI\n // sizes it from --popup-width, measured once when a section\n // activates, so a panel opened before the first measurement lands\n // (or resized while open) would keep a stale popup width and clip\n // the full-width panel to a sliver. An inline width stays reactive.\n popupStyle={panelWidth === null ? undefined : { width: panelWidth }}\n >\n <NavigationMenuList className='w-full justify-start gap-0 border-b-0'>\n {navigation.map((item) => (\n <MainNavMenuItem\n key={`${item.title}-${item.href ?? 'section'}`}\n item={item}\n color={color ?? DEFAULT_MAIN_NAV_COLOR}\n currentHref={currentHref}\n panelWidth={panelWidth}\n />\n ))}\n </NavigationMenuList>\n </NavigationMenu>\n </div>\n </nav>\n )\n}\n\nexport { MainNav, mainNavColors, mainNavContainerVariants, mainNavPanelVariants, mainNavVariants }\nexport type { MainNavColor, MainNavItem, MainNavLinkItem, MainNavProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/main-nav.tsx"],"names":[],"mappings":";;;;;;;AAoCA,MAAM,aAAA,GAAgB;AAAA,EACpB,aAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF;AAMA,MAAM,sBAAA,GAAuC,OAAA;AAE7C,MAAM,eAAA,GAAkB,GAAA;AAAA,EACtB;AAAA,IACE,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAUA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAeR,KAAA,EAAO;AAAA,QACL,aAAA,EACE,mFAAA;AAAA,QACF,aAAA,EACE,mFAAA;AAAA,QACF,aAAA,EACE,kJAAA;AAAA,QACF,aAAA,EACE,kJAAA;AAAA,QACF,UAAA,EAA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iCAAA;AAAA,cACV,IAAA,EAAK,QAAA;AAAA,cACL,UAAA,EAAY,CAAA;AAAA,cACZ,KAAA,EAAM,OAAA;AAAA,cACN,WAAA;AAAA,cACA,gBAAA,EAAkB,CAAA;AAAA,cAClB,kBAAA,EAAoB,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,MAAA,EAAO;AAAA,cAClD,UAAA,EAAY,GAAA;AAAA,cAGZ,cAAA,EAAe,yBAAA;AAAA,cAMf,YAAY,UAAA,KAAe,IAAA,GAAO,MAAA,GAAY,EAAE,OAAO,UAAA,EAAW;AAAA,cAElE,8BAAC,kBAAA,EAAA,EAAmB,SAAA,EAAU,yCAC3B,QAAA,EAAA,UAAA,CAAW,GAAA,CAAI,CAAC,IAAA,qBACf,GAAA;AAAA,gBAAC,eAAA;AAAA,gBAAA;AAAA,kBAEC,IAAA;AAAA,kBACA,OAAO,KAAA,IAAS,sBAAA;AAAA,kBAChB,WAAA;AAAA,kBACA;AAAA,iBAAA;AAAA,gBAJK,GAAG,IAAA,CAAK,KAAK,CAAA,CAAA,EAAI,IAAA,CAAK,QAAQ,SAAS,CAAA;AAAA,eAM/C,CAAA,EACH;AAAA;AAAA;AACF;AAAA;AACF;AAAA,GACF;AAEJ","file":"main-nav.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { IconEast } from '../icons/east.js'\nimport { cn } from '../lib/utils.js'\n\nimport {\n NavigationMenu,\n NavigationMenuContent,\n NavigationMenuItem,\n NavigationMenuLink,\n NavigationMenuList,\n NavigationMenuTrigger,\n} from '../components/navigation-menu.js'\n\n/**\n * Surface colours the main navigation can be themed with — exactly the\n * Footer's thirteen-name vocabulary, so a service that themes its footer\n * `primary-800` writes the same word here. Each name is the LIGHT-mode\n * surface; dark mode deepens it onto the same family's dark steps (see the\n * `color` variants below), so `color` expresses tonal weight rather than a\n * literal colour.\n *\n * The bar's text/background pairs are identical to the Footer's, so its\n * contrast conclusions carry over verbatim: every light pair clears WCAG 2.2\n * AA (1.4.3, 4.5:1) for the bar's text and 11 of the 13 also clear AAA\n * (1.4.6, 7:1). The two AA-only pairs are `primary-600` (4.57:1) and\n * `accent-600` (5.18:1), both with white ink; prefer the `-800` steps when a\n * service is held to AAA. In dark mode all thirteen clear AAA (worst 13.6:1).\n *\n * The mega panels always render on the house popup surface (`bg-popover`),\n * matching the nswds-app source where every dropdown was white regardless of\n * bar colour — only the panel's accent ink follows the colour family.\n */\nconst mainNavColors = [\n 'primary-800',\n 'primary-600',\n 'primary-400',\n 'primary-200',\n 'grey-800',\n 'grey-600',\n 'grey-400',\n 'grey-200',\n 'accent-800',\n 'accent-600',\n 'accent-400',\n 'accent-200',\n 'white',\n] as const\n\ntype MainNavColor = (typeof mainNavColors)[number]\n\n// Shared by cva's defaultVariants, the data-color attribute and the panel\n// variant lookup, so the three can't drift apart.\nconst DEFAULT_MAIN_NAV_COLOR: MainNavColor = 'white'\n\nconst mainNavVariants = cva(\n [\n 'w-full',\n // Every derived colour on the bar resolves from a single --main-nav-ink\n // token, so a colour variant only has to declare the surface utilities and\n // that one value — this replaces the nswds-app source's hand-written\n // 13-variant × 8-slot style table. The border derivation is written\n // literally here (once) rather than per-variant: Tailwind scans source\n // text for class names, so a template-built arbitrary property would\n // never be emitted. Hover/active halos are not derived here — the\n // triggers ride navigation-menu.tsx's --nav-menu-halo chain, re-pointed\n // at this ink (see mainNavItemInk), so there is exactly one halo recipe.\n '[--main-nav-border:color-mix(in_oklch,var(--main-nav-ink)_15%,transparent)]',\n ],\n {\n variants: {\n // Ink values use the RAW masterbrand tokens (--primary-800, --grey-800,\n // --accent-800) rather than Tailwind's --color-* bridge aliases. Tailwind\n // v4 tree-shakes an unreferenced @theme key, and referencing one from\n // inside an arbitrary property is not a usage signal — the raw tokens are\n // plain :root declarations from @nswds/tokens and always resolve.\n // (--color-white is safe: `text-white` / `bg-white` below are real\n // utilities, so that key is always emitted.)\n //\n // Dark mode deepens every surface onto the same family's dark steps —\n // -800→-950, -600→-900, -400→-850, -200→-800, white→grey-900 — the\n // Footer's exact mapping, so the luminance ORDER within a family is\n // preserved and a stacked Footer + MainNav sharing one colour word stay\n // in step in both themes. Ink goes white on all thirteen; every dark\n // pair is WCAG 2.2 AAA (worst 13.6:1).\n color: {\n 'primary-800':\n 'bg-primary-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-primary-950',\n 'primary-600':\n 'bg-primary-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-primary-900',\n 'primary-400':\n 'bg-primary-400 text-primary-800 [--main-nav-ink:var(--primary-800)] dark:bg-primary-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'primary-200':\n 'bg-primary-200 text-primary-800 [--main-nav-ink:var(--primary-800)] dark:bg-primary-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'grey-800': 'bg-grey-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-grey-950',\n 'grey-600': 'bg-grey-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-grey-900',\n 'grey-400':\n 'bg-grey-400 text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'grey-200':\n 'bg-grey-200 text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'accent-800':\n 'bg-accent-800 text-white [--main-nav-ink:var(--color-white)] dark:bg-accent-950',\n 'accent-600':\n 'bg-accent-600 text-white [--main-nav-ink:var(--color-white)] dark:bg-accent-900',\n 'accent-400':\n 'bg-accent-400 text-accent-800 [--main-nav-ink:var(--accent-800)] dark:bg-accent-850 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n 'accent-200':\n 'bg-accent-200 text-accent-800 [--main-nav-ink:var(--accent-800)] dark:bg-accent-800 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--main-nav-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--main-nav-ink:var(--color-white)]',\n },\n // Rules along the bar's edges, drawn from the ink-derived border token so\n // they follow every colour variant and both themes. Replaces the app\n // source's deprecated showTopBorder/showBottomBorder booleans, which are\n // deliberately not ported.\n border: {\n none: '',\n top: 'border-t border-(--main-nav-border)',\n bottom: 'border-b border-(--main-nav-border)',\n both: 'border-y border-(--main-nav-border)',\n },\n },\n defaultVariants: {\n color: DEFAULT_MAIN_NAV_COLOR,\n border: 'none',\n },\n },\n)\n\nconst mainNavContainerVariants = cva(\n [\n 'mx-auto flex w-full items-center',\n // Lateral padding funnels through --main-nav-padding-x so an app can\n // retune it once (via the `style` prop or a utility class) without a new\n // variant. Same mechanism, and the same 16px → 24px → 48px rhythm, as\n // Masthead, Header and Footer.\n 'px-(--main-nav-padding-x)',\n '[--main-nav-padding-x:--spacing(4)] sm:[--main-nav-padding-x:--spacing(6)] lg:[--main-nav-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app fullBleed parity). --main-nav-max-width is\n // still read so a shell app can constrain the inner wrapper without\n // switching variants.\n fluid: 'max-w-[var(--main-nav-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--main-nav-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Mega-panel accent ink, keyed by the same thirteen colour names as the bar.\n * The panel itself is always the house popup surface (`bg-popover`, white in\n * light mode) — parity with the app source, whose dropdown was white for\n * every variant — so the family only tints the featured lead link, hover ink\n * and cell borders. Declared on the Content element (not inherited from the\n * bar) because Base UI portals the panel to `document.body`: a custom\n * property set on the `<nav>` can never reach it.\n *\n * Light inks are the family's -800 step on white — grey-800 on white is\n * 15.1:1 and white on primary-800 is 14.4:1 (both AAA; contrast is symmetric,\n * ratios from header.tsx); accent-800 on white clears AAA per the Footer's\n * verified pairs. Dark inks step to the family's -200 — the same dark-mode\n * interactive ink link.tsx and navigation-menu.tsx already use on this\n * popover surface. The featured lead is text-xl bold, so even the softest\n * pair is far above the large-text AA floor (1.4.3, 3:1).\n */\nconst mainNavPanelVariants = cva(\n [\n 'p-0 whitespace-normal',\n // The sibling Content (and the shared popup, via popupClassName below)\n // cap themselves at --available-width, which Base UI measures from the\n // active trigger — for a mid-bar trigger that is less than the nav's\n // width, which would shrink right-hand panels. The panel's width is\n // container-measured and can never exceed the viewport, so the cap is\n // safely lifted.\n 'max-w-none',\n '[--main-nav-panel-border:color-mix(in_oklch,var(--main-nav-panel-ink)_15%,transparent)]',\n ],\n {\n variants: {\n color: {\n 'primary-800':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-600':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-400':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'primary-200':\n '[--main-nav-panel-ink:var(--primary-800)] dark:[--main-nav-panel-ink:var(--primary-200)]',\n 'grey-800':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-600':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-400':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'grey-200':\n '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n 'accent-800':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-600':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-400':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n 'accent-200':\n '[--main-nav-panel-ink:var(--accent-800)] dark:[--main-nav-panel-ink:var(--accent-200)]',\n white: '[--main-nav-panel-ink:var(--grey-800)] dark:[--main-nav-panel-ink:var(--grey-200)]',\n },\n },\n defaultVariants: {\n color: DEFAULT_MAIN_NAV_COLOR,\n },\n },\n)\n\n// Re-points the sibling navigation-menu's ink at the bar's surface ink. The\n// trigger/link halos and focus outlines in navigation-menu.tsx all derive\n// from --nav-menu-ink via color-mix ON THE SAME ELEMENT, so overriding the\n// one token retargets the whole chain: hover/active halos and the\n// focus-visible outline become surface-relative, guaranteeing the indicator\n// contrasts on all thirteen surfaces (WCAG 2.2, 2.4.13 Focus Appearance).\n// Both light and dark are overridden because the sibling pins its own\n// dark-mode ink (primary-200); --main-nav-ink is already theme-aware.\nconst mainNavItemInk =\n '[--nav-menu-ink:var(--main-nav-ink)] dark:[--nav-menu-ink:var(--main-nav-ink)]'\n\n// Same re-point for links INSIDE the portalled panel, where the bar's ink\n// cannot reach — these derive from the panel accent ink instead.\nconst mainNavPanelInk =\n '[--nav-menu-ink:var(--main-nav-panel-ink)] dark:[--nav-menu-ink:var(--main-nav-panel-ink)]'\n\n// Restyles the sibling trigger to the app source's bar metrics: 56px min\n// height, square corners, bold base text, wider gutters from lg up. The open\n// panel is marked with the app's 4px inset underline (data-popup-open comes\n// from Base UI); data-current draws the same underline persistently when\n// `currentHref` falls inside this section, so the underline means \"you are\n// here\" at rest and \"this panel is open\" during use.\nconst mainNavTriggerClassName = [\n mainNavItemInk,\n 'mb-0 h-auto min-h-14 w-auto justify-start rounded-none max-lg:px-4 py-2 text-base leading-6 font-bold text-(--main-nav-ink)',\n 'lg:px-8',\n '[&_svg]:size-6',\n 'data-popup-open:shadow-[inset_0_-4px_0_0_currentColor]',\n 'data-current:shadow-[inset_0_-4px_0_0_currentColor]',\n].join(' ')\n\n// A panel-less item, restyled from the sibling link to sit visually beside\n// the triggers (cn's conflict merge lets these win over the link's stacked\n// defaults). `active` → data-active draws the current-page underline; Base UI\n// pairs it with aria-current='page' on the same element (WCAG 2.4.8).\nconst mainNavTopLinkClassName = [\n mainNavItemInk,\n 'inline-flex min-h-14 flex-row items-center justify-start gap-1 rounded-none max-lg:px-4 py-2 text-base leading-6 font-bold whitespace-nowrap text-(--main-nav-ink)',\n 'lg:px-8',\n 'data-active:shadow-[inset_0_-4px_0_0_currentColor]',\n].join(' ')\n\n// The featured lead link at the top of a mega panel: the section title,\n// oversized, with an east arrow that nudges forward on hover (the app\n// source's exact affordance, on the house easing curve; the nudge is a\n// transition, so motion-reduce users get an instant state change — WCAG\n// 2.3.3). `group` scopes the icon's group-hover to this anchor — the panel is\n// portalled, so no other `group` ancestor can capture it.\nconst mainNavFeaturedLinkClassName = [\n mainNavPanelInk,\n 'group relative flex-row items-center rounded-none px-8 py-8 text-xl font-bold whitespace-normal text-(--main-nav-panel-ink)',\n].join(' ')\n\n// The lead when the section has no `href`: the same visual weight as the\n// featured link, but a plain heading row — no anchor (a dead link announced\n// as a link fails the reader who activates it), no hover halo, and no east\n// arrow (an arrow on a non-link promises navigation that never happens). No\n// mainNavPanelInk re-point either: that chain only feeds interactive halos.\nconst mainNavFeaturedHeadingClassName =\n 'flex flex-row items-center px-8 py-8 text-xl font-bold whitespace-normal text-(--main-nav-panel-ink)'\n\n// One bordered grid cell per section link. The anchor itself is the cell —\n// the app source wrapped a div around a stretched-link span, but making the\n// whole cell the anchor gives the same hit area with one element and no\n// aria-hidden overlay. Cells draw a top hairline from the panel ink; the last\n// grid row closes with a bottom hairline via the app's :nth-last-child(-n+3)\n// selector (tuned to the widest, 3-column layout — at narrower widths the\n// final one or two cells simply carry the closing rule, matching the app).\nconst mainNavSectionLinkClassName = [\n mainNavPanelInk,\n 'relative mx-2 justify-center rounded-none border-t border-(--main-nav-panel-border) p-4 text-base font-semibold whitespace-normal text-popover-foreground',\n 'hover:text-(--main-nav-panel-ink)',\n '[&:nth-last-child(-n+3)]:border-b',\n].join(' ')\n\n/** One link inside a mega panel. */\ntype MainNavLinkItem = {\n /** Visible link text, e.g. \"Find support near you\". */\n title: string\n href: string\n}\n\n/**\n * One top-level navigation item. With `links` it renders as a trigger opening\n * a mega panel (with `href` becoming the panel's featured lead link; without\n * an `href` the lead is a plain heading row — dev builds warn); without\n * `links` it renders as a plain link styled like the triggers. Recursion is\n * deliberately one level deep — mega panels list flat links, per the app\n * source's NavigationSection shape.\n */\ntype MainNavItem = {\n title: string\n href?: string\n links?: MainNavLinkItem[]\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: an item\n * with neither `href` nor `links` renders a dead `\"#\"` link — almost always a\n * data mistake, and a trap for keyboard and screen-reader users who activate\n * it and go nowhere. A section (`links`, no `href`) is legal but demoted —\n * its panel lead renders as a plain heading instead of the featured link —\n * so it gets its own nudge. No-op in production.\n */\nfunction warnIfItemUnlinked(item: MainNavItem) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] MainNav item \"${item.title}\" has no href and no links — it will render as a dead \"#\" link.`,\n )\n }\n if (!item.href && item.links?.length) {\n console.warn(\n `[nswds/ui] MainNav section \"${item.title}\" has links but no href — its panel lead renders as a plain heading; pass href to make it a link.`,\n )\n }\n}\n\ntype MainNavMenuItemProps = {\n item: MainNavItem\n color: MainNavColor\n currentHref?: string\n /** Measured container width, forwarded as the panel's inline width. */\n panelWidth: number | null\n}\n\n/**\n * One bar entry: a plain link for items without `links`, a trigger + mega\n * panel for items with them. Internal — the data-driven `MainNav` API is the\n * public surface; compose the navigation-menu primitives directly for layouts\n * this doesn't cover.\n */\nfunction MainNavMenuItem({ item, color, currentHref, panelWidth }: MainNavMenuItemProps) {\n warnIfItemUnlinked(item)\n\n const links = item.links\n const isExactCurrent = item.href !== undefined && item.href === currentHref\n const isSectionCurrent =\n isExactCurrent ||\n (currentHref !== undefined && (links?.some((link) => link.href === currentHref) ?? false))\n\n if (!links?.length) {\n return (\n <NavigationMenuItem className='shrink-0'>\n <NavigationMenuLink\n data-slot='main-nav-top-link'\n href={item.href ?? '#'}\n active={isExactCurrent}\n className={mainNavTopLinkClassName}\n >\n {item.title}\n </NavigationMenuLink>\n </NavigationMenuItem>\n )\n }\n\n return (\n <NavigationMenuItem className='shrink-0'>\n {/* The trigger is a button (it discloses, it doesn't navigate), so it\n can't carry aria-current — data-current draws the visual \"you are\n here\" underline while the aria-current announcement lives on the\n exact matching link inside the panel. */}\n <NavigationMenuTrigger\n data-current={isSectionCurrent || undefined}\n className={mainNavTriggerClassName}\n >\n {item.title}\n </NavigationMenuTrigger>\n {/* Inline width (not a CSS var): the panel is portalled to\n document.body, so a custom property set on the nav can't reach it.\n Before the first measurement resolves the panel falls back to the\n sibling's natural w-max sizing. */}\n <NavigationMenuContent\n data-slot='main-nav-panel'\n className={mainNavPanelVariants({ color })}\n style={panelWidth === null ? undefined : { width: panelWidth }}\n >\n <div className='grid w-full'>\n {/* No section href → no featured LINK: an `href=\"#\"` fallback here\n would be a dead link announced as a link. The heading row keeps\n the lead's visual weight without the anchor, halo or arrow — see\n mainNavFeaturedHeadingClassName. */}\n {item.href === undefined ? (\n <div data-slot='main-nav-featured-heading' className={mainNavFeaturedHeadingClassName}>\n {item.title}\n </div>\n ) : (\n <NavigationMenuLink\n data-slot='main-nav-featured-link'\n href={item.href}\n active={isExactCurrent}\n className={mainNavFeaturedLinkClassName}\n >\n {item.title}\n <IconEast\n aria-hidden='true'\n className='ml-4 size-6 shrink-0 text-current duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover:translate-x-1 motion-safe:transition-transform'\n />\n </NavigationMenuLink>\n )}\n <div\n data-slot='main-nav-panel-links'\n className='grid overflow-hidden px-4 pb-12 max-sm:grid-cols-1 sm:max-lg:grid-cols-2 lg:grid-cols-3'\n >\n {links.map((link, index) => (\n <NavigationMenuLink\n key={`${link.title}-${link.href}-${index}`}\n data-slot='main-nav-section-link'\n href={link.href}\n active={link.href === currentHref}\n className={mainNavSectionLinkClassName}\n >\n {link.title}\n </NavigationMenuLink>\n ))}\n </div>\n </div>\n </NavigationMenuContent>\n </NavigationMenuItem>\n )\n}\n\ntype MainNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> &\n VariantProps<typeof mainNavVariants> &\n VariantProps<typeof mainNavContainerVariants> & {\n /** Top-level items; items with `links` open mega panels. */\n navigation: MainNavItem[]\n /**\n * The current page's href. The exact matching link gets\n * `aria-current=\"page\"`, and the top-level item it belongs to (a plain\n * link, or the trigger whose panel contains it) gets the current-item\n * underline. The app source read this from next/navigation's\n * `usePathname` — a framework API this package must not import; compare\n * in the consumer and pass the result down.\n */\n currentHref?: string\n /**\n * Stick to the top of the viewport as the page scrolls. Defaults to\n * `false`. When the nav renders below a sticky `Header`, set\n * `--main-nav-top` to the header's height so the two stack instead of\n * overlapping — this custom property replaces the app source's\n * `useSelectorHeight` DOM-measuring hook (the app measured `#nsw-header`\n * on every resize; a consumer that needs a live value can still measure\n * its own header and write the property, see the Sticky story).\n */\n sticky?: boolean\n /** Drop shadow under the bar. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Full-width NSW site navigation bar with mega-menu panels — the data-driven\n * consolidation of the nswds-app `NavigationMenuMainNavigation` /\n * `MainNavigation` components, rebuilt on this package's `NavigationMenu`\n * (Base UI underneath).\n *\n * - `navigation` drives everything: items with `links` render a trigger whose\n * mega panel shows a featured lead link (the section `href`; with no `href`\n * the lead demotes to a plain heading row — dev builds warn) above a\n * responsive 1/2/3-column grid of bordered section links; items without\n * `links` render plain links styled like the triggers. All anchors render\n * through `Link`, so a framework link injected via `LinkProvider`\n * (e.g. next/link) is used automatically.\n * - `color` themes the bar with the Footer's thirteen-name vocabulary and its\n * exact dark-mode deepening; every derived colour (halos, borders, focus\n * outlines) resolves from a single `--main-nav-ink` per variant. Contrast\n * conclusions are the Footer's, verbatim (see `mainNavColors`).\n * - Panels span the nav container's full width: a ResizeObserver on the inner\n * container feeds each panel's inline width, and an `alignOffset` function\n * shifts Base UI's trigger-anchored positioner back to the container's left\n * edge (measured at position time from the open trigger, so it is exact for\n * every trigger — this replaces the app source's panelMetrics state).\n * Assumes LTR; see the class comments.\n * - `container`, `border`, `shadow`, `sticky` mirror the house chrome\n * components; the app's deprecated `showTopBorder`/`showBottomBorder` and\n * `responsive` props are not ported (use `border` and\n * `className=\"hidden lg:block\"`).\n *\n * Accessibility: the outer `<nav>` is the landmark (default label \"Main\n * navigation\"; Base UI's own root is demoted to a `<div>` via `render` so the\n * page doesn't gain a nested nav landmark). Everything interactive is\n * inherited from Base UI via the sibling: triggers are real buttons with\n * `aria-expanded`/`aria-controls`, ArrowDown/Enter opens, arrow keys rove,\n * Escape and focus-out close, and the current page announces\n * `aria-current=\"page\"` (WCAG 2.4.8). Focus indicators are 2px ink-derived\n * outlines that contrast on all thirteen surfaces and on the panel surface\n * (2.4.7, 2.4.13). The 220ms `closeDelay` reproduces the app's hover-out\n * grace timer through Base UI instead of a hand-rolled setTimeout.\n *\n * The default `id=\"nsw-main-navigation\"` is kept for compatibility with\n * existing shells that target it (override via the `id` prop).\n */\nfunction MainNav({\n className,\n containerClassName,\n color,\n container,\n border,\n navigation,\n currentHref,\n sticky = false,\n shadow = true,\n 'aria-label': ariaLabel = 'Main navigation',\n ref,\n ...props\n}: MainNavProps) {\n const containerRef = React.useRef<HTMLDivElement>(null)\n const [panelWidth, setPanelWidth] = React.useState<number | null>(null)\n\n React.useEffect(() => {\n const element = containerRef.current\n if (!element) {\n return\n }\n const measure = () => {\n setPanelWidth(element.getBoundingClientRect().width)\n }\n // Read once on mount: panels can open before the first resize.\n measure()\n const observer = new ResizeObserver(measure)\n observer.observe(element)\n return () => observer.disconnect()\n }, [])\n\n // Shifts the popup from Base UI's anchor (the open trigger) to the\n // container's left edge. Called by the positioner at position time, when\n // the open trigger is findable via data-popup-open — so the offset is exact\n // per trigger with no per-trigger state. Assumes LTR (`align='start'` maps\n // to the left edge); RTL would need the mirrored calculation.\n //\n // The ref caches the last successful offset for the windows when NO trigger\n // carries data-popup-open — chiefly the ~300ms close fade, when a recompute\n // (scroll/resize mid-fade) returning 0 would snap the still-visible\n // full-width panel back to the trigger's edge. Repeating the last real\n // offset holds the fading panel where it was.\n const lastAlignOffsetRef = React.useRef(0)\n const alignOffset = React.useCallback(() => {\n const element = containerRef.current\n if (!element) {\n return lastAlignOffsetRef.current\n }\n const trigger = element.querySelector('[data-popup-open]')\n if (!trigger) {\n return lastAlignOffsetRef.current\n }\n lastAlignOffsetRef.current =\n element.getBoundingClientRect().left - trigger.getBoundingClientRect().left\n return lastAlignOffsetRef.current\n }, [])\n\n return (\n <nav\n id='nsw-main-navigation'\n data-slot='main-nav'\n data-color={color ?? DEFAULT_MAIN_NAV_COLOR}\n aria-label={ariaLabel}\n {...props}\n className={cn(\n mainNavVariants({ color, border }),\n // z-40 matches Header (both sit below the z-50 SkipLinks). An app\n // stacking this under a sticky Header sets --main-nav-top to the\n // header's height.\n sticky && 'sticky top-[var(--main-nav-top,0px)] z-40',\n // House scrolled-header shadow; in dark mode borders carry separation.\n shadow && 'shadow-md shadow-black/5 dark:shadow-none',\n className,\n )}\n ref={ref}\n >\n <div\n ref={containerRef}\n data-slot='main-nav-container'\n className={cn(mainNavContainerVariants({ container }), containerClassName)}\n >\n {/* render={<div/>}: Base UI's root is itself a <nav>; demoting it\n keeps this component to ONE navigation landmark. sideOffset 0\n seats the panel flush under the bar; collision handling is off\n because alignOffset/width already pin the panel inside the\n viewport. closeDelay 220 = the app's PANEL_CLOSE_DELAY_MS. */}\n <NavigationMenu\n render={<div />}\n className='w-full max-w-none justify-start'\n side='bottom'\n sideOffset={0}\n align='start'\n alignOffset={alignOffset}\n collisionPadding={0}\n collisionAvoidance={{ side: 'none', align: 'none' }}\n closeDelay={220}\n // Square corners (the full-width panel meets the bar edge-to-edge)\n // and no --available-width cap — see mainNavPanelVariants.\n popupClassName='max-w-none rounded-none'\n // The popup itself must follow the measured width too: Base UI\n // sizes it from --popup-width, measured once when a section\n // activates, so a panel opened before the first measurement lands\n // (or resized while open) would keep a stale popup width and clip\n // the full-width panel to a sliver. An inline width stays reactive.\n popupStyle={panelWidth === null ? undefined : { width: panelWidth }}\n >\n <NavigationMenuList className='w-full justify-start gap-0 border-b-0'>\n {navigation.map((item) => (\n <MainNavMenuItem\n key={`${item.title}-${item.href ?? 'section'}`}\n item={item}\n color={color ?? DEFAULT_MAIN_NAV_COLOR}\n currentHref={currentHref}\n panelWidth={panelWidth}\n />\n ))}\n </NavigationMenuList>\n </NavigationMenu>\n </div>\n </nav>\n )\n}\n\nexport { MainNav, mainNavColors, mainNavContainerVariants, mainNavPanelVariants, mainNavVariants }\nexport type { MainNavColor, MainNavItem, MainNavLinkItem, MainNavProps }\n"]}
|
|
@@ -17,7 +17,7 @@ const navigationMenuTriggerVariants = cva([
|
|
|
17
17
|
// mb-2 pairs with the list's bottom hairline, matching the app source.
|
|
18
18
|
"group mb-2 inline-flex h-9 w-max cursor-pointer items-center justify-center gap-1 rounded-sm px-4 py-2 text-sm font-medium whitespace-nowrap select-none",
|
|
19
19
|
"bg-transparent text-foreground",
|
|
20
|
-
"
|
|
20
|
+
"motion-safe:transition-colors",
|
|
21
21
|
// Resting halo on hover/focus/open. `focus:` (not focus-visible) is
|
|
22
22
|
// deliberate for the tint — like Button, triggers give click feedback —
|
|
23
23
|
// while the *outline* below stays keyboard-only.
|
|
@@ -67,9 +67,9 @@ function NavigationMenu({
|
|
|
67
67
|
// Base UI reports its measured geometry through these vars; sizing
|
|
68
68
|
// the box from them lets top/left glide between triggers.
|
|
69
69
|
"isolate z-50 box-border h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)]",
|
|
70
|
-
"
|
|
70
|
+
"duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[top,left,right,bottom]",
|
|
71
71
|
// data-instant: Base UI disables the glide (e.g. keyboard re-anchor).
|
|
72
|
-
"data-instant:transition-none
|
|
72
|
+
"data-instant:transition-none"
|
|
73
73
|
),
|
|
74
74
|
children: /* @__PURE__ */ jsx(
|
|
75
75
|
NavigationMenu$1.Popup,
|
|
@@ -82,7 +82,7 @@ function NavigationMenu({
|
|
|
82
82
|
// it into --popup-*), so switching sections morphs the surface
|
|
83
83
|
// instead of jump-cutting.
|
|
84
84
|
"h-[var(--popup-height)] w-[var(--popup-width)] max-w-[var(--available-width)] origin-(--transform-origin)",
|
|
85
|
-
"
|
|
85
|
+
"duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[opacity,transform,width,height,scale,translate]",
|
|
86
86
|
// Open/close via Base UI transition attributes.
|
|
87
87
|
"data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
88
88
|
"data-ending-style:scale-95 data-ending-style:opacity-0",
|
|
@@ -142,7 +142,7 @@ function NavigationMenuTrigger({ className, children, ...props }) {
|
|
|
142
142
|
{
|
|
143
143
|
"data-slot": "navigation-menu-icon",
|
|
144
144
|
"aria-hidden": "true",
|
|
145
|
-
className: "flex
|
|
145
|
+
className: "flex duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] data-popup-open:rotate-180 motion-safe:transition-transform",
|
|
146
146
|
children: /* @__PURE__ */ jsx(IconKeyboardArrowDown, { className: "size-5" })
|
|
147
147
|
}
|
|
148
148
|
)
|
|
@@ -157,7 +157,7 @@ function NavigationMenuContent({ className, ...props }) {
|
|
|
157
157
|
"data-slot": "navigation-menu-content",
|
|
158
158
|
className: cn(
|
|
159
159
|
"h-full w-max max-w-[var(--available-width)] p-2",
|
|
160
|
-
"
|
|
160
|
+
"duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[opacity,translate]",
|
|
161
161
|
"data-ending-style:opacity-0 data-starting-style:opacity-0",
|
|
162
162
|
// Slide with the direction of travel between adjacent triggers.
|
|
163
163
|
"data-starting-style:data-[activation-direction=left]:-translate-x-1/2",
|
|
@@ -184,7 +184,7 @@ function NavigationMenuLink({
|
|
|
184
184
|
className: cn(
|
|
185
185
|
navigationMenuInk,
|
|
186
186
|
"flex flex-col gap-1 rounded-sm p-2 text-sm text-foreground",
|
|
187
|
-
"
|
|
187
|
+
"motion-safe:transition-colors",
|
|
188
188
|
"hover:bg-(--nav-menu-halo) focus:bg-(--nav-menu-halo) active:bg-(--nav-menu-halo-active)",
|
|
189
189
|
// Persistent tint for the current page (`active` prop → data-active).
|
|
190
190
|
"data-active:bg-(--nav-menu-halo)",
|