@nswds/ui 4.1.6 → 4.3.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,147 @@
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
+ import { Link } from './link.js';
5
+
6
+ /**
7
+ * Surface colours the header can be themed with, sharing the Masthead's and
8
+ * SkipLink's four-name vocabulary (`dark`, `light`, `white`, `grey`) — the three
9
+ * components stack at the top of the page and a service picks one word for the
10
+ * whole chrome.
11
+ *
12
+ * Every pair is WCAG 2.2 AAA (1.4.6, 7:1), computed from the masterbrand oklch
13
+ * tokens. Light mode: grey-800 on white 15.1:1, grey-800 on grey-100 13.8:1,
14
+ * white on primary-800 14.4:1, white on grey-800 15.1:1. Dark mode deepens each
15
+ * surface onto the same family's dark step and clears AAA more comfortably
16
+ * still (17.2:1–20.2:1).
17
+ *
18
+ * Unlike the Masthead — a brand strip whose light/white/grey surfaces are frozen
19
+ * across themes — the header is the page's own surface, so all four follow the
20
+ * theme. Pair `Header color="dark"` with `Masthead color="dark"` when a service
21
+ * wants the two to match in both modes.
22
+ */
23
+ declare const headerColors: {
24
+ dark: string;
25
+ light: string;
26
+ white: string;
27
+ grey: string;
28
+ };
29
+ type HeaderColor = keyof typeof headerColors;
30
+ declare const headerVariants: (props?: ({
31
+ color?: "light" | "white" | "grey" | "dark" | null | undefined;
32
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
33
+ declare const headerContainerVariants: (props?: ({
34
+ container?: "fluid" | "contained" | null | undefined;
35
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
36
+ type HeaderBrandProps = React__default.ComponentPropsWithoutRef<'div'> & {
37
+ /** Home-page target for the brand link. Defaults to `/`. */
38
+ href?: React__default.ComponentPropsWithoutRef<typeof Link>['href'];
39
+ /** Service or site name shown beside the logo. */
40
+ sitename?: React__default.ReactNode;
41
+ /**
42
+ * Heading level for `sitename`. Omit (the default) to render a `<span>`,
43
+ * which is usually right: the page's own `<h1>` belongs to its main content,
44
+ * and a site name repeated in the header on every page is not the heading
45
+ * that describes this page. Supply a level only when a service deliberately
46
+ * places the site name in the document outline.
47
+ *
48
+ * `1` is excluded for the reason above; `6` is the deepest heading HTML
49
+ * defines.
50
+ */
51
+ headingLevel?: 2 | 3 | 4 | 5 | 6;
52
+ /**
53
+ * Version string shown in a Badge beside the brand. Sits outside the link,
54
+ * so it never becomes part of the home link's accessible name.
55
+ */
56
+ version?: React__default.ReactNode;
57
+ /**
58
+ * Visually-hidden prefix announced before `version`, giving the bare number
59
+ * context for screen readers ("2.1.0" → "Version 2.1.0"). Pass an empty
60
+ * string to suppress.
61
+ */
62
+ versionLabel?: string;
63
+ /**
64
+ * `true` (default) renders the NSW Government waratah, `false` omits it, and
65
+ * a node replaces it — pass an agency lockup here.
66
+ */
67
+ logo?: boolean | React__default.ReactNode;
68
+ /**
69
+ * Accessible name for the brand link. Left unset by default: the link's name
70
+ * is then its visible content — "NSW Government" (from `Logo`'s
71
+ * visually-hidden text) plus `sitename` — which keeps the visible label
72
+ * inside the accessible name (WCAG 2.2, 2.5.3 Label in Name). Overriding it
73
+ * with something like "Home page" would break that, so set it only when the
74
+ * brand renders no text at all.
75
+ */
76
+ label?: string;
77
+ ref?: React__default.Ref<HTMLDivElement>;
78
+ };
79
+ /**
80
+ * Logo, site name and optional version badge, linked to the home page. Sits at
81
+ * the start of the `Header` row.
82
+ *
83
+ * The link renders through `Link`, so it picks up the framework link component
84
+ * from `LinkProvider` (next/link et al) rather than hardcoding one.
85
+ */
86
+ declare function HeaderBrand({ className, href, sitename, headingLevel, version, versionLabel, logo, label, children, ref, ...props }: HeaderBrandProps): React__default.JSX.Element;
87
+ type HeaderActionsProps = React__default.ComponentPropsWithoutRef<'div'> & {
88
+ ref?: React__default.Ref<HTMLDivElement>;
89
+ };
90
+ /**
91
+ * Trailing cluster of header controls — search, theme switcher, sign-in, and
92
+ * the like. Deliberately unopinionated about what goes in it: site search and
93
+ * theme switching are app concerns (they need routing and a theme provider),
94
+ * so the design system supplies the slot and its spacing rather than the
95
+ * widgets.
96
+ *
97
+ * Not a `nav` landmark: a row of controls is not a set of navigation links, and
98
+ * an extra landmark on every page buries the ones that matter. Wrap genuine
99
+ * navigation in your own `<nav>` inside `Header`.
100
+ */
101
+ declare function HeaderActions({ className, ref, ...props }: HeaderActionsProps): React__default.JSX.Element;
102
+ type HeaderProps = React__default.ComponentPropsWithoutRef<'header'> & VariantProps<typeof headerVariants> & VariantProps<typeof headerContainerVariants> & {
103
+ /** Stick to the top of the viewport as the page scrolls. Defaults to `true`. */
104
+ sticky?: boolean;
105
+ /** Hairline rule along the bottom edge. Defaults to `true`. */
106
+ border?: boolean;
107
+ /** Raise the header with a shadow once the page is scrolled. Defaults to `true`. */
108
+ shadow?: boolean;
109
+ /** Classes applied to the inner width-constraining wrapper. */
110
+ containerClassName?: string;
111
+ ref?: React__default.Ref<HTMLElement>;
112
+ };
113
+ /**
114
+ * Top-of-page `banner` landmark: brand, site name and header controls. Render
115
+ * it once in a shared layout, below `SkipLinks` and `Masthead`.
116
+ *
117
+ * - `color` themes the surface; all four pairs are WCAG 2.2 AAA and follow the
118
+ * theme in dark mode (see `headerColors`). The bottom rule derives from the
119
+ * surface's ink, so it follows automatically.
120
+ * - `container` selects the inner wrapper layout: `fluid` (full-bleed,
121
+ * nswds-app parity) or `contained` (centred 1200px column, legacy
122
+ * `nsw-container` parity). Fine-tune either with the `--header-max-width`
123
+ * and `--header-padding-x` custom properties.
124
+ * - Scroll position is tracked and exposed as `data-scrolled`, which is what
125
+ * the `shadow` treatment keys off. Style your own scrolled state with it.
126
+ *
127
+ * Compose the row from `HeaderBrand` and `HeaderActions`:
128
+ *
129
+ * ```tsx
130
+ * <Header>
131
+ * <HeaderBrand sitename="Design System" version="2.1.0" />
132
+ * <HeaderActions>
133
+ * <ThemeSwitcher />
134
+ * </HeaderActions>
135
+ * </Header>
136
+ * ```
137
+ *
138
+ * The `banner` landmark comes from the native `<header>` element, which only
139
+ * carries it outside `article`, `aside`, `main`, `nav` and `section` — wrapping
140
+ * `div`s are fine. Keep it out of `<main>`.
141
+ *
142
+ * The default `id="nsw-header"` is kept for compatibility with existing shells
143
+ * that target it (override via the `id` prop).
144
+ */
145
+ declare function Header({ className, color, container, containerClassName, sticky, border, shadow, children, ref, ...props }: HeaderProps): React__default.JSX.Element;
146
+
147
+ export { Header, HeaderActions, type HeaderActionsProps, HeaderBrand, type HeaderBrandProps, type HeaderColor, type HeaderProps, headerColors, headerContainerVariants, headerVariants };
@@ -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,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,iGAAA;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;AAqDjE,SAAS,qBAAA,CAAsB;AAAA,EAC7B,IAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA,EAA0D;AACxD,EAAA,IAAI,OAAA,CAAQ,GAA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"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"]}
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export { Card, CardAction, CardActionProps, CardContent, CardContentProps, CardD
5
5
  export { Collapsible, CollapsibleContent, CollapsibleTrigger } from './components/collapsible.js';
6
6
  export { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger } from './components/drawer.js';
7
7
  export { Field, FieldContent, FieldContentProps, FieldDescription, FieldDescriptionProps, FieldError, FieldErrorProps, FieldGroup, FieldGroupProps, FieldLabel, FieldLabelProps, FieldLegend, FieldLegendProps, FieldProps, FieldSeparator, FieldSeparatorProps, FieldSet, FieldSetProps, FieldTitle, FieldTitleProps } from './components/field.js';
8
+ export { Footer, FooterAcknowledgement, FooterAcknowledgementProps, FooterColor, FooterLegalLinkItem, FooterLegalLinks, FooterLegalLinksProps, FooterLinkItem, FooterNav, FooterNavColumn, FooterNavColumnProps, FooterNavLink, FooterNavLinkProps, FooterNavProps, FooterProps, FooterSmallPrint, FooterSmallPrintProps, FooterSocialLink, FooterSocialLinkItem, FooterSocialLinkProps, footerColors, footerContainerVariants, footerVariants } from './components/footer.js';
9
+ export { Header, HeaderActions, HeaderActionsProps, HeaderBrand, HeaderBrandProps, HeaderColor, HeaderProps, headerColors, headerContainerVariants, headerVariants } from './components/header.js';
8
10
  export { HoverCard, HoverCardContent, HoverCardTrigger } from './components/hover-card.js';
9
11
  export { Input, InputProps } from './components/input.js';
10
12
  export { Label, LabelProps } from './components/label.js';
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@ export * from './components/card.js';
5
5
  export * from './components/collapsible.js';
6
6
  export * from './components/drawer.js';
7
7
  export * from './components/field.js';
8
+ export * from './components/footer.js';
9
+ export * from './components/header.js';
8
10
  export * from './components/hover-card.js';
9
11
  export * from './components/input.js';
10
12
  export * from './components/label.js';