@nswds/ui 4.2.0 → 4.4.0

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.
@@ -0,0 +1,221 @@
1
+ "use client"
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { cva } from 'class-variance-authority';
4
+ import React from 'react';
5
+ import { cn } from '../lib/utils.js';
6
+ import { Badge } from '../components/badge.js';
7
+ import { Link } from '../components/link.js';
8
+ import { Logo } from '../components/logo.js';
9
+
10
+ const headerColors = {
11
+ // Ink values use the RAW masterbrand tokens (--grey-800) rather than
12
+ // Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes an
13
+ // unreferenced @theme key, and referencing one from inside an arbitrary
14
+ // property is not a usage signal. Same reasoning as footer.tsx.
15
+ // (--color-white is safe: `text-white` below is a real utility.)
16
+ dark: "bg-primary-800 text-white [--header-ink:var(--color-white)] dark:bg-primary-950",
17
+ light: "bg-grey-100 text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--header-ink:var(--color-white)]",
18
+ white: "bg-white text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--header-ink:var(--color-white)]",
19
+ grey: "bg-grey-800 text-white [--header-ink:var(--color-white)] dark:bg-grey-950"
20
+ };
21
+ const DEFAULT_HEADER_COLOR = "white";
22
+ const headerVariants = cva(
23
+ [
24
+ "w-full",
25
+ // The hairline rule derives from the surface's own ink, so it follows every
26
+ // colour variant and both themes from one value. Mirrors the color-mix
27
+ // derivation in footer.tsx (--footer-border) and link.tsx (--link-halo).
28
+ "[--header-border:color-mix(in_oklch,var(--header-ink)_15%,transparent)]",
29
+ "transition-shadow duration-300 motion-reduce:transition-none"
30
+ ],
31
+ {
32
+ variants: {
33
+ color: headerColors
34
+ },
35
+ defaultVariants: {
36
+ color: DEFAULT_HEADER_COLOR
37
+ }
38
+ }
39
+ );
40
+ const headerContainerVariants = cva(
41
+ [
42
+ "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",
43
+ // Lateral padding funnels through --header-padding-x so an app can retune it
44
+ // once (via the `style` prop or a utility class) without a new variant. Same
45
+ // mechanism, and the same 16px → 24px → 48px rhythm, as Masthead and Footer.
46
+ "px-(--header-padding-x)",
47
+ "[--header-padding-x:--spacing(4)] sm:[--header-padding-x:--spacing(6)] lg:[--header-padding-x:--spacing(12)]"
48
+ ],
49
+ {
50
+ variants: {
51
+ container: {
52
+ // Full-bleed (nswds-app parity). --header-max-width is still read so a
53
+ // shell app can constrain the inner wrapper without switching variants.
54
+ fluid: "max-w-[var(--header-max-width,none)]",
55
+ // Centred content column, legacy nsw-container parity (1200px).
56
+ contained: "max-w-[var(--header-max-width,75rem)]"
57
+ }
58
+ },
59
+ defaultVariants: {
60
+ container: "fluid"
61
+ }
62
+ }
63
+ );
64
+ const HeaderColorContext = React.createContext(DEFAULT_HEADER_COLOR);
65
+ const DARK_SURFACE_COLORS = /* @__PURE__ */ new Set(["dark", "grey"]);
66
+ function warnIfBrandUnlabelled({
67
+ logo,
68
+ sitename,
69
+ label
70
+ }) {
71
+ if (process.env.NODE_ENV === "production") {
72
+ return;
73
+ }
74
+ if (!logo && !sitename && !label) {
75
+ console.warn(
76
+ "[nswds/ui] HeaderBrand has no logo and no sitename, so its home link has no accessible name \u2014 pass `label`."
77
+ );
78
+ }
79
+ }
80
+ function HeaderBrand({
81
+ className,
82
+ href = "/",
83
+ sitename,
84
+ headingLevel,
85
+ version,
86
+ versionLabel = "Version",
87
+ logo = true,
88
+ label,
89
+ children,
90
+ ref,
91
+ ...props
92
+ }) {
93
+ const color = React.useContext(HeaderColorContext);
94
+ const onDarkSurface = DARK_SURFACE_COLORS.has(color);
95
+ const Sitename = headingLevel ? `h${headingLevel}` : "span";
96
+ warnIfBrandUnlabelled({ logo, sitename, label });
97
+ const logoNode = logo === true ? /* @__PURE__ */ jsx(
98
+ Logo,
99
+ {
100
+ logoType: onDarkSurface ? "reversed" : "default",
101
+ className: "h-10 w-auto sm:h-12 lg:h-14"
102
+ }
103
+ ) : (
104
+ // `false` / `null` fall through as the falsy nodes they are; anything
105
+ // else is the consumer's own lockup.
106
+ logo
107
+ );
108
+ return /* @__PURE__ */ jsxs(
109
+ "div",
110
+ {
111
+ "data-slot": "header-brand",
112
+ ...props,
113
+ className: cn("flex grow basis-0 items-center gap-3 sm:gap-4", className),
114
+ ref,
115
+ children: [
116
+ /* @__PURE__ */ jsxs(
117
+ Link,
118
+ {
119
+ variant: "unstyled",
120
+ href,
121
+ "aria-label": label,
122
+ 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",
123
+ children: [
124
+ logoNode,
125
+ sitename ? /* @__PURE__ */ jsx(Sitename, { className: "text-lg font-bold text-balance sm:text-xl", children: sitename }) : null
126
+ ]
127
+ }
128
+ ),
129
+ version ? (
130
+ // Badge's `primary` ink is primary-800 — the `dark` header's own
131
+ // surface — so dark surfaces take the white badge instead.
132
+ /* @__PURE__ */ jsxs(
133
+ Badge,
134
+ {
135
+ "data-slot": "header-version",
136
+ variant: "soft",
137
+ color: onDarkSurface ? "white" : "primary",
138
+ children: [
139
+ versionLabel ? /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
140
+ versionLabel,
141
+ " "
142
+ ] }) : null,
143
+ version
144
+ ]
145
+ }
146
+ )
147
+ ) : null,
148
+ children
149
+ ]
150
+ }
151
+ );
152
+ }
153
+ function HeaderActions({ className, ref, ...props }) {
154
+ return /* @__PURE__ */ jsx(
155
+ "div",
156
+ {
157
+ "data-slot": "header-actions",
158
+ ...props,
159
+ className: cn("flex basis-0 items-center justify-end gap-2 sm:gap-4 md:grow", className),
160
+ ref
161
+ }
162
+ );
163
+ }
164
+ function Header({
165
+ className,
166
+ color,
167
+ container,
168
+ containerClassName,
169
+ sticky = true,
170
+ border = true,
171
+ shadow = true,
172
+ children,
173
+ ref,
174
+ ...props
175
+ }) {
176
+ const [isScrolled, setIsScrolled] = React.useState(false);
177
+ React.useEffect(() => {
178
+ function onScroll() {
179
+ setIsScrolled(window.scrollY > 0);
180
+ }
181
+ onScroll();
182
+ window.addEventListener("scroll", onScroll, { passive: true });
183
+ return () => window.removeEventListener("scroll", onScroll);
184
+ }, []);
185
+ return /* @__PURE__ */ jsx(
186
+ "header",
187
+ {
188
+ id: "nsw-header",
189
+ "data-slot": "header",
190
+ "data-color": color ?? DEFAULT_HEADER_COLOR,
191
+ "data-scrolled": isScrolled || void 0,
192
+ ...props,
193
+ className: cn(
194
+ headerVariants({ color }),
195
+ // z-40 sits below the z-50 SkipLinks: a sticky header at the same
196
+ // level comes later in the DOM and would paint over a focused skip
197
+ // link, hiding the page's bypass mechanism (WCAG 2.2, 2.4.1).
198
+ sticky && "sticky top-0 z-40",
199
+ // Always drawn, so the scrolled state changes no box heights.
200
+ border && "border-b border-(--header-border)",
201
+ // Shadows read as elevation on light surfaces only; in dark mode the
202
+ // rule above carries the separation.
203
+ shadow && "data-scrolled:shadow-md data-scrolled:shadow-black/5 dark:data-scrolled:shadow-none",
204
+ className
205
+ ),
206
+ ref,
207
+ children: /* @__PURE__ */ jsx(HeaderColorContext.Provider, { value: color ?? DEFAULT_HEADER_COLOR, children: /* @__PURE__ */ jsx(
208
+ "div",
209
+ {
210
+ "data-slot": "header-container",
211
+ className: cn(headerContainerVariants({ container }), containerClassName),
212
+ children
213
+ }
214
+ ) })
215
+ }
216
+ );
217
+ }
218
+
219
+ export { Header, HeaderActions, HeaderBrand, headerColors, headerContainerVariants, headerVariants };
220
+ //# sourceMappingURL=header.js.map
221
+ //# sourceMappingURL=header.js.map
@@ -0,0 +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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AAA,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 className='h-10 w-auto sm:h-12 lg:h-14'\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 <Sitename className='text-lg font-bold text-balance sm:text-xl'>{sitename}</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"]}
@@ -0,0 +1,144 @@
1
+ import * as class_variance_authority_types from 'class-variance-authority/types';
2
+ import { VariantProps } from 'class-variance-authority';
3
+ import React__default from 'react';
4
+
5
+ /**
6
+ * Surface colours the main navigation can be themed with — exactly the
7
+ * Footer's thirteen-name vocabulary, so a service that themes its footer
8
+ * `primary-800` writes the same word here. Each name is the LIGHT-mode
9
+ * surface; dark mode deepens it onto the same family's dark steps (see the
10
+ * `color` variants below), so `color` expresses tonal weight rather than a
11
+ * literal colour.
12
+ *
13
+ * The bar's text/background pairs are identical to the Footer's, so its
14
+ * contrast conclusions carry over verbatim: every light pair clears WCAG 2.2
15
+ * AA (1.4.3, 4.5:1) for the bar's text and 11 of the 13 also clear AAA
16
+ * (1.4.6, 7:1). The two AA-only pairs are `primary-600` (4.57:1) and
17
+ * `accent-600` (5.18:1), both with white ink; prefer the `-800` steps when a
18
+ * service is held to AAA. In dark mode all thirteen clear AAA (worst 13.6:1).
19
+ *
20
+ * The mega panels always render on the house popup surface (`bg-popover`),
21
+ * matching the nswds-app source where every dropdown was white regardless of
22
+ * bar colour — only the panel's accent ink follows the colour family.
23
+ */
24
+ declare const mainNavColors: readonly ["primary-800", "primary-600", "primary-400", "primary-200", "grey-800", "grey-600", "grey-400", "grey-200", "accent-800", "accent-600", "accent-400", "accent-200", "white"];
25
+ type MainNavColor = (typeof mainNavColors)[number];
26
+ declare const mainNavVariants: (props?: ({
27
+ color?: "white" | "primary-800" | "primary-600" | "primary-400" | "primary-200" | "grey-800" | "grey-600" | "grey-400" | "grey-200" | "accent-800" | "accent-600" | "accent-400" | "accent-200" | null | undefined;
28
+ border?: "none" | "both" | "top" | "bottom" | null | undefined;
29
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
30
+ declare const mainNavContainerVariants: (props?: ({
31
+ container?: "fluid" | "contained" | null | undefined;
32
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
33
+ /**
34
+ * Mega-panel accent ink, keyed by the same thirteen colour names as the bar.
35
+ * The panel itself is always the house popup surface (`bg-popover`, white in
36
+ * light mode) — parity with the app source, whose dropdown was white for
37
+ * every variant — so the family only tints the featured lead link, hover ink
38
+ * and cell borders. Declared on the Content element (not inherited from the
39
+ * bar) because Base UI portals the panel to `document.body`: a custom
40
+ * property set on the `<nav>` can never reach it.
41
+ *
42
+ * Light inks are the family's -800 step on white — grey-800 on white is
43
+ * 15.1:1 and white on primary-800 is 14.4:1 (both AAA; contrast is symmetric,
44
+ * ratios from header.tsx); accent-800 on white clears AAA per the Footer's
45
+ * verified pairs. Dark inks step to the family's -200 — the same dark-mode
46
+ * interactive ink link.tsx and navigation-menu.tsx already use on this
47
+ * popover surface. The featured lead is text-xl bold, so even the softest
48
+ * pair is far above the large-text AA floor (1.4.3, 3:1).
49
+ */
50
+ declare const mainNavPanelVariants: (props?: ({
51
+ color?: "white" | "primary-800" | "primary-600" | "primary-400" | "primary-200" | "grey-800" | "grey-600" | "grey-400" | "grey-200" | "accent-800" | "accent-600" | "accent-400" | "accent-200" | null | undefined;
52
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
53
+ /** One link inside a mega panel. */
54
+ type MainNavLinkItem = {
55
+ /** Visible link text, e.g. "Find support near you". */
56
+ title: string;
57
+ href: string;
58
+ };
59
+ /**
60
+ * One top-level navigation item. With `links` it renders as a trigger opening
61
+ * a mega panel (with `href` becoming the panel's featured lead link; without
62
+ * an `href` the lead is a plain heading row — dev builds warn); without
63
+ * `links` it renders as a plain link styled like the triggers. Recursion is
64
+ * deliberately one level deep — mega panels list flat links, per the app
65
+ * source's NavigationSection shape.
66
+ */
67
+ type MainNavItem = {
68
+ title: string;
69
+ href?: string;
70
+ links?: MainNavLinkItem[];
71
+ };
72
+ type MainNavProps = Omit<React__default.ComponentPropsWithoutRef<'nav'>, 'children'> & VariantProps<typeof mainNavVariants> & VariantProps<typeof mainNavContainerVariants> & {
73
+ /** Top-level items; items with `links` open mega panels. */
74
+ navigation: MainNavItem[];
75
+ /**
76
+ * The current page's href. The exact matching link gets
77
+ * `aria-current="page"`, and the top-level item it belongs to (a plain
78
+ * link, or the trigger whose panel contains it) gets the current-item
79
+ * underline. The app source read this from next/navigation's
80
+ * `usePathname` — a framework API this package must not import; compare
81
+ * in the consumer and pass the result down.
82
+ */
83
+ currentHref?: string;
84
+ /**
85
+ * Stick to the top of the viewport as the page scrolls. Defaults to
86
+ * `false`. When the nav renders below a sticky `Header`, set
87
+ * `--main-nav-top` to the header's height so the two stack instead of
88
+ * overlapping — this custom property replaces the app source's
89
+ * `useSelectorHeight` DOM-measuring hook (the app measured `#nsw-header`
90
+ * on every resize; a consumer that needs a live value can still measure
91
+ * its own header and write the property, see the Sticky story).
92
+ */
93
+ sticky?: boolean;
94
+ /** Drop shadow under the bar. Defaults to `true`. */
95
+ shadow?: boolean;
96
+ /** Classes applied to the inner width-constraining wrapper. */
97
+ containerClassName?: string;
98
+ ref?: React__default.Ref<HTMLElement>;
99
+ };
100
+ /**
101
+ * Full-width NSW site navigation bar with mega-menu panels — the data-driven
102
+ * consolidation of the nswds-app `NavigationMenuMainNavigation` /
103
+ * `MainNavigation` components, rebuilt on this package's `NavigationMenu`
104
+ * (Base UI underneath).
105
+ *
106
+ * - `navigation` drives everything: items with `links` render a trigger whose
107
+ * mega panel shows a featured lead link (the section `href`; with no `href`
108
+ * the lead demotes to a plain heading row — dev builds warn) above a
109
+ * responsive 1/2/3-column grid of bordered section links; items without
110
+ * `links` render plain links styled like the triggers. All anchors render
111
+ * through `Link`, so a framework link injected via `LinkProvider`
112
+ * (e.g. next/link) is used automatically.
113
+ * - `color` themes the bar with the Footer's thirteen-name vocabulary and its
114
+ * exact dark-mode deepening; every derived colour (halos, borders, focus
115
+ * outlines) resolves from a single `--main-nav-ink` per variant. Contrast
116
+ * conclusions are the Footer's, verbatim (see `mainNavColors`).
117
+ * - Panels span the nav container's full width: a ResizeObserver on the inner
118
+ * container feeds each panel's inline width, and an `alignOffset` function
119
+ * shifts Base UI's trigger-anchored positioner back to the container's left
120
+ * edge (measured at position time from the open trigger, so it is exact for
121
+ * every trigger — this replaces the app source's panelMetrics state).
122
+ * Assumes LTR; see the class comments.
123
+ * - `container`, `border`, `shadow`, `sticky` mirror the house chrome
124
+ * components; the app's deprecated `showTopBorder`/`showBottomBorder` and
125
+ * `responsive` props are not ported (use `border` and
126
+ * `className="hidden lg:block"`).
127
+ *
128
+ * Accessibility: the outer `<nav>` is the landmark (default label "Main
129
+ * navigation"; Base UI's own root is demoted to a `<div>` via `render` so the
130
+ * page doesn't gain a nested nav landmark). Everything interactive is
131
+ * inherited from Base UI via the sibling: triggers are real buttons with
132
+ * `aria-expanded`/`aria-controls`, ArrowDown/Enter opens, arrow keys rove,
133
+ * Escape and focus-out close, and the current page announces
134
+ * `aria-current="page"` (WCAG 2.4.8). Focus indicators are 2px ink-derived
135
+ * outlines that contrast on all thirteen surfaces and on the panel surface
136
+ * (2.4.7, 2.4.13). The 220ms `closeDelay` reproduces the app's hover-out
137
+ * grace timer through Base UI instead of a hand-rolled setTimeout.
138
+ *
139
+ * The default `id="nsw-main-navigation"` is kept for compatibility with
140
+ * existing shells that target it (override via the `id` prop).
141
+ */
142
+ declare function MainNav({ className, containerClassName, color, container, border, navigation, currentHref, sticky, shadow, 'aria-label': ariaLabel, ref, ...props }: MainNavProps): React__default.JSX.Element;
143
+
144
+ export { MainNav, type MainNavColor, type MainNavItem, type MainNavLinkItem, type MainNavProps, mainNavColors, mainNavContainerVariants, mainNavPanelVariants, mainNavVariants };