@atelic-action/ui 7.2.0 → 8.0.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.
- package/README.md +312 -126
- package/package.json +14 -10
- package/src/app/ErrorFallback.tsx +6 -2
- package/src/app/context/AppContext.tsx +10 -1
- package/src/app/index.ts +0 -1
- package/src/app/layout/AppPage.tsx +36 -7
- package/src/app/layout/DesktopRail.tsx +9 -2
- package/src/app/layout/MobileMenu.tsx +5 -1
- package/src/app/layout/PageError.tsx +6 -3
- package/src/app/layout/PageSkeleton.tsx +33 -26
- package/src/app/layout/UserMenu.tsx +12 -6
- package/src/app/ui/alert.tsx +41 -11
- package/src/app/ui/badge.tsx +1 -1
- package/src/app/ui/button.tsx +2 -1
- package/src/app/ui/command.tsx +86 -21
- package/src/app/ui/country-dropdown.tsx +26 -47
- package/src/app/ui/form.tsx +46 -7
- package/src/app/ui/pagination.tsx +1 -1
- package/src/app/ui/progress.tsx +26 -12
- package/src/app/ui/search-input.tsx +16 -3
- package/src/app/ui/select.tsx +8 -3
- package/src/app/ui/slider.tsx +62 -15
- package/src/artifact/ArtifactShell.tsx +5 -1
- package/src/artifact/ErrorFallback.tsx +8 -1
- package/src/artifact/artifactConfig.ts +1 -1
- package/src/chrome/BrandLockup.tsx +71 -16
- package/src/chrome/ClosingBar.tsx +5 -3
- package/src/chrome/ContactDock.tsx +329 -0
- package/src/chrome/Footer.tsx +32 -9
- package/src/chrome/NavBadge.tsx +8 -0
- package/src/chrome/NavMegaPanel.tsx +388 -0
- package/src/chrome/SiteHeader.tsx +235 -18
- package/src/chrome/SiteMenu.tsx +197 -19
- package/src/chrome/SiteShell.tsx +130 -13
- package/src/chrome/StickyCTABar.tsx +56 -2
- package/src/chrome/brandMark.ts +56 -0
- package/src/chrome/icons.ts +58 -0
- package/src/chrome/index.ts +16 -0
- package/src/chrome/navSections.ts +55 -0
- package/src/components/ColumnChart.tsx +27 -2
- package/src/components/DataTable.tsx +104 -85
- package/src/components/Disclosure.tsx +3 -1
- package/src/components/Hint.tsx +3 -24
- package/src/components/NotFound.tsx +4 -1
- package/src/components/StarRating.tsx +45 -19
- package/src/components/ThresholdScale.tsx +36 -26
- package/src/email/atoms.tsx +13 -57
- package/src/email/frame.tsx +4 -6
- package/src/email/index.ts +4 -10
- package/src/email/scoreboard.tsx +107 -186
- package/src/email/text.ts +30 -0
- package/src/email/theme.tsx +76 -9
- package/src/hooks/useDismiss.ts +39 -0
- package/src/lib/useScrollsSideways.ts +26 -0
- package/src/primitives/Button.tsx +2 -0
- package/src/primitives/ProseBlocks.tsx +6 -1
- package/src/primitives/SectionHeading.tsx +3 -1
- package/src/primitives/StarRow.tsx +23 -8
- package/src/sections/BlogIndex.tsx +17 -3
- package/src/sections/BlogPost.tsx +10 -1
- package/src/sections/CTASection.tsx +2 -2
- package/src/sections/CalloutPanel.tsx +34 -0
- package/src/sections/ComparisonTable.tsx +23 -2
- package/src/sections/ContactForm.tsx +61 -17
- package/src/sections/FAQBrowser.tsx +11 -2
- package/src/sections/FeatureGrid.tsx +6 -2
- package/src/sections/FullBleedVideo.tsx +158 -0
- package/src/sections/Gallery.tsx +6 -4
- package/src/sections/Hero.tsx +63 -39
- package/src/sections/JumpRail.tsx +7 -0
- package/src/sections/LegalPage.tsx +10 -2
- package/src/sections/LinkColumns.tsx +64 -0
- package/src/sections/LocationSection.tsx +28 -5
- package/src/sections/Locations.tsx +17 -4
- package/src/sections/LogoMarquee.tsx +43 -11
- package/src/sections/MapEmbed.tsx +13 -9
- package/src/sections/PageHero.tsx +16 -2
- package/src/sections/ProcessSteps.tsx +27 -4
- package/src/sections/ProfileCards.tsx +12 -2
- package/src/sections/ProofStrip.tsx +44 -0
- package/src/sections/RevealSlider.tsx +28 -7
- package/src/sections/ReviewCarousel.tsx +17 -4
- package/src/sections/ReviewWall.tsx +2 -2
- package/src/sections/SplitSection.tsx +2 -1
- package/src/sections/index.ts +15 -6
- package/src/sections/siteConfig.ts +66 -3
- package/src/styles/app.css +24 -2
- package/src/styles/artifact.css +20 -8
- package/src/styles/base.css +42 -13
- package/src/styles/chrome.css +935 -47
- package/src/styles/components.css +104 -65
- package/src/styles/defaults.css +137 -0
- package/src/styles/gate.css +21 -10
- package/src/styles/primitives.css +97 -35
- package/src/styles/sections.css +477 -437
- package/src/styles/star-rating.css +1 -4
- package/src/tokens/palettes.ts +24 -4
- package/src/types.ts +212 -2
- package/src/app/CardErrorBoundary.tsx +0 -39
- package/src/sections/CTABanner.tsx +0 -93
- package/src/sections/DeviceShowcase.tsx +0 -39
- package/src/sections/MediaBand.tsx +0 -20
- package/src/sections/MenuList.tsx +0 -44
- package/src/sections/PressQuotes.tsx +0 -51
- package/src/sections/SocialStrip.tsx +0 -83
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChevronDown, Phone as PhoneIcon } from "lucide-react";
|
|
2
|
+
import {
|
|
3
|
+
type FocusEvent,
|
|
4
|
+
type KeyboardEvent,
|
|
5
|
+
type PointerEvent,
|
|
6
|
+
useEffect,
|
|
7
|
+
useId,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { useDismiss } from "../hooks/useDismiss";
|
|
2
12
|
import { type PageStop, useScrollSpy } from "../hooks/useScrollSpy";
|
|
3
13
|
import { newTabProps } from "../lib/newTabProps";
|
|
4
|
-
import type { Brand, CallToAction, MenuContact, NavLink } from "../types";
|
|
14
|
+
import type { Brand, CallToAction, HeaderPhone, MenuContact, NavLink } from "../types";
|
|
5
15
|
import { BrandLockup } from "./BrandLockup";
|
|
16
|
+
import { NavMegaPanel } from "./NavMegaPanel";
|
|
17
|
+
import { groupHrefs, isGroup } from "./navSections";
|
|
6
18
|
import { SiteMenu } from "./SiteMenu";
|
|
7
19
|
|
|
8
20
|
/**
|
|
@@ -14,7 +26,11 @@ export type SiteHeaderVariant = "transparent" | "solid" | "dark";
|
|
|
14
26
|
export interface SiteHeaderProps {
|
|
15
27
|
/** The identity the lockup renders. */
|
|
16
28
|
brand: Brand;
|
|
17
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The site's primary nav. Omit on a page with no site nav, such as an
|
|
31
|
+
* artifact. An entry with `columns` is a group: on a desktop it opens a
|
|
32
|
+
* mega menu panel, and in the phone's menu an accordion.
|
|
33
|
+
*/
|
|
18
34
|
links?: NavLink[];
|
|
19
35
|
/** The primary action, in the bar on desktop and in the menu. */
|
|
20
36
|
primaryCTA?: CallToAction;
|
|
@@ -32,12 +48,49 @@ export interface SiteHeaderProps {
|
|
|
32
48
|
hideCTA?: boolean;
|
|
33
49
|
/** The contact block at the foot of the menu. */
|
|
34
50
|
contact?: MenuContact;
|
|
51
|
+
/**
|
|
52
|
+
* Up to two numbers the bar shows on a desktop, each a tel link, with the
|
|
53
|
+
* first as a call button beside the burger on a phone. A third is dropped.
|
|
54
|
+
*/
|
|
55
|
+
phones?: HeaderPhone[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The keys that move focus along the bar and down into an open panel. */
|
|
59
|
+
const BAR_ITEMS = ".nav-links > a, .nav-links .nav-group-btn";
|
|
60
|
+
const PANEL_ITEMS = "a[href], button:not([disabled])";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A keyboard focus opens a group the way a hover does; a click focuses the
|
|
64
|
+
* control too, and that focus must not count. jsdom and older engines that
|
|
65
|
+
* cannot answer the question get the keyboard reading.
|
|
66
|
+
*/
|
|
67
|
+
function isKeyboardFocus(element: Element): boolean {
|
|
68
|
+
try {
|
|
69
|
+
return element.matches(":focus-visible");
|
|
70
|
+
} catch {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The spoken name of a header number: its label, then the number. */
|
|
76
|
+
function phoneName(phone: HeaderPhone): string {
|
|
77
|
+
return phone.label ? `${phone.label} ${phone.display}` : phone.display;
|
|
35
78
|
}
|
|
36
79
|
|
|
37
80
|
/**
|
|
38
81
|
* The fixed header every page wears: the lockup, the nav or the page's
|
|
39
|
-
* stops, the CTA, and the burger that opens the menu. It takes
|
|
40
|
-
* path as a prop rather than asking a router, so it runs under
|
|
82
|
+
* stops, the numbers, the CTA, and the burger that opens the menu. It takes
|
|
83
|
+
* the current path as a prop rather than asking a router, so it runs under
|
|
84
|
+
* any of them.
|
|
85
|
+
*
|
|
86
|
+
* A nav group opens its panel on a mouse hover or a keyboard focus, and a
|
|
87
|
+
* click on its control pins it open (a second click closes it). Escape, a
|
|
88
|
+
* click outside the header, the pointer leaving the header, and focus
|
|
89
|
+
* leaving the group close an unpinned panel; Escape, an outside click, and
|
|
90
|
+
* focus leaving the group close a pinned one too. Left and right arrows walk the bar, the down arrow
|
|
91
|
+
* steps into a panel, and up and down walk the panel's links. A closed panel
|
|
92
|
+
* stays in the HTML, `inert`, so its links are crawlable and out of the tab
|
|
93
|
+
* order.
|
|
41
94
|
*/
|
|
42
95
|
export function SiteHeader({
|
|
43
96
|
brand,
|
|
@@ -48,10 +101,17 @@ export function SiteHeader({
|
|
|
48
101
|
stops,
|
|
49
102
|
hideCTA = false,
|
|
50
103
|
contact,
|
|
104
|
+
phones,
|
|
51
105
|
}: SiteHeaderProps) {
|
|
52
106
|
const [scrolled, setScrolled] = useState(false);
|
|
53
107
|
const [menuOpen, setMenuOpen] = useState(false);
|
|
54
|
-
|
|
108
|
+
// The open group's index, and whether a click pinned it open.
|
|
109
|
+
const [openGroup, setOpenGroup] = useState<number | null>(null);
|
|
110
|
+
const [pinned, setPinned] = useState(false);
|
|
111
|
+
const [focusPanel, setFocusPanel] = useState(false);
|
|
112
|
+
const headerRef = useRef<HTMLElement>(null);
|
|
113
|
+
const baseId = useId();
|
|
114
|
+
const menuId = `${baseId}menu`;
|
|
55
115
|
const activeId = useScrollSpy(stops ? stops.map((stop) => stop.id) : []);
|
|
56
116
|
|
|
57
117
|
useEffect(() => {
|
|
@@ -62,20 +122,89 @@ export function SiteHeader({
|
|
|
62
122
|
return () => window.removeEventListener("scroll", onScroll);
|
|
63
123
|
}, [variant]);
|
|
64
124
|
|
|
65
|
-
const
|
|
125
|
+
const close = () => {
|
|
126
|
+
setOpenGroup(null);
|
|
127
|
+
setPinned(false);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Escape and a click outside the header close whatever is open, pinned or
|
|
131
|
+
// not; Escape hands focus back to the group's control when it was inside.
|
|
132
|
+
useDismiss(openGroup !== null, headerRef, (reason) => {
|
|
133
|
+
if (reason === "escape" && headerRef.current?.contains(document.activeElement)) {
|
|
134
|
+
document.getElementById(`${baseId}g${openGroup}`)?.focus();
|
|
135
|
+
}
|
|
136
|
+
close();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// The down arrow opens a panel and moves into it once it is no longer inert.
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!focusPanel || openGroup === null) return;
|
|
142
|
+
setFocusPanel(false);
|
|
143
|
+
const panel = document.getElementById(`${baseId}p${openGroup}`);
|
|
144
|
+
panel?.querySelector<HTMLElement>(PANEL_ITEMS)?.focus();
|
|
145
|
+
}, [focusPanel, openGroup, baseId]);
|
|
146
|
+
|
|
147
|
+
const solid = variant !== "transparent" || scrolled || openGroup !== null;
|
|
66
148
|
const menuLinks = stops
|
|
67
149
|
? stops.map((stop) => ({ label: stop.label, href: `#${stop.id}` }))
|
|
68
150
|
: (links ?? []);
|
|
69
151
|
const menuCTA = stops ? undefined : primaryCTA;
|
|
70
152
|
const barCTA = hideCTA ? undefined : menuCTA;
|
|
71
153
|
const hasMenu = menuLinks.length > 0 || menuCTA !== undefined;
|
|
154
|
+
const barPhones = stops ? [] : (phones ?? []).slice(0, 2);
|
|
155
|
+
const hasGroups = !stops && (links ?? []).some(isGroup);
|
|
156
|
+
// A bar holding groups or numbers needs more width before the burger steps aside.
|
|
157
|
+
const wide = hasGroups || barPhones.length > 0;
|
|
158
|
+
|
|
159
|
+
const isCurrent = (link: NavLink) =>
|
|
160
|
+
currentPath !== undefined &&
|
|
161
|
+
(link.href === currentPath || groupHrefs(link).includes(currentPath));
|
|
162
|
+
|
|
163
|
+
// One handler for the whole nav: left and right walk the bar's entries,
|
|
164
|
+
// up and down walk the links of the panel focus is in.
|
|
165
|
+
function onNavKeyDown(event: KeyboardEvent<HTMLElement>) {
|
|
166
|
+
const target = event.target as HTMLElement;
|
|
167
|
+
const panel = target.closest(".nav-mega");
|
|
168
|
+
const vertical = event.key === "ArrowDown" || event.key === "ArrowUp";
|
|
169
|
+
const horizontal = event.key === "ArrowLeft" || event.key === "ArrowRight";
|
|
170
|
+
if (!(panel ? vertical : horizontal)) return;
|
|
171
|
+
const scope = panel ?? event.currentTarget;
|
|
172
|
+
const items = Array.from(scope.querySelectorAll<HTMLElement>(panel ? PANEL_ITEMS : BAR_ITEMS));
|
|
173
|
+
const at = items.indexOf(target);
|
|
174
|
+
if (at === -1) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
const forward = event.key === "ArrowDown" || event.key === "ArrowRight";
|
|
177
|
+
const next = forward ? at + 1 : at - 1;
|
|
178
|
+
items[(next + items.length) % items.length]?.focus();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Focus leaving the open group for anywhere else closes it. Focus lost to
|
|
182
|
+
// nothing is a click on the page, which the outside click closes.
|
|
183
|
+
function onNavBlur(event: FocusEvent<HTMLElement>) {
|
|
184
|
+
if (openGroup === null) return;
|
|
185
|
+
const next = event.relatedTarget as Node | null;
|
|
186
|
+
if (!next) return;
|
|
187
|
+
const item = document.getElementById(`${baseId}g${openGroup}`)?.closest(".nav-item");
|
|
188
|
+
if (item && !item.contains(next)) close();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function onHeaderLeave(event: PointerEvent<HTMLElement>) {
|
|
192
|
+
if (event.pointerType === "mouse" && !pinned) close();
|
|
193
|
+
}
|
|
72
194
|
|
|
73
195
|
return (
|
|
74
196
|
<>
|
|
75
197
|
<header
|
|
76
|
-
|
|
198
|
+
ref={headerRef}
|
|
199
|
+
className={[
|
|
200
|
+
"nav",
|
|
201
|
+
solid ? "is-solid" : "is-transparent",
|
|
202
|
+
variant === "dark" && "nav-dark",
|
|
203
|
+
wide && "is-wide",
|
|
204
|
+
]
|
|
77
205
|
.filter(Boolean)
|
|
78
206
|
.join(" ")}
|
|
207
|
+
onPointerLeave={onHeaderLeave}
|
|
79
208
|
>
|
|
80
209
|
<div className="nav-inner">
|
|
81
210
|
<BrandLockup brand={brand} />
|
|
@@ -95,18 +224,95 @@ export function SiteHeader({
|
|
|
95
224
|
)
|
|
96
225
|
: links &&
|
|
97
226
|
links.length > 0 && (
|
|
98
|
-
<nav
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
227
|
+
<nav
|
|
228
|
+
className="nav-links"
|
|
229
|
+
aria-label="Primary"
|
|
230
|
+
onKeyDown={onNavKeyDown}
|
|
231
|
+
onBlur={onNavBlur}
|
|
232
|
+
>
|
|
233
|
+
{links.map((link, index) =>
|
|
234
|
+
isGroup(link) ? (
|
|
235
|
+
<div className="nav-item" key={link.href}>
|
|
236
|
+
<button
|
|
237
|
+
type="button"
|
|
238
|
+
id={`${baseId}g${index}`}
|
|
239
|
+
className={["nav-group-btn", isCurrent(link) && "is-current"]
|
|
240
|
+
.filter(Boolean)
|
|
241
|
+
.join(" ")}
|
|
242
|
+
aria-expanded={openGroup === index}
|
|
243
|
+
aria-controls={`${baseId}p${index}`}
|
|
244
|
+
onPointerEnter={(event) => {
|
|
245
|
+
if (event.pointerType !== "mouse") return;
|
|
246
|
+
if (openGroup !== index) {
|
|
247
|
+
setOpenGroup(index);
|
|
248
|
+
setPinned(false);
|
|
249
|
+
}
|
|
250
|
+
}}
|
|
251
|
+
onFocus={(event) => {
|
|
252
|
+
if (openGroup !== index && isKeyboardFocus(event.currentTarget)) {
|
|
253
|
+
setOpenGroup(index);
|
|
254
|
+
setPinned(false);
|
|
255
|
+
}
|
|
256
|
+
}}
|
|
257
|
+
onClick={() => {
|
|
258
|
+
if (openGroup === index && pinned) close();
|
|
259
|
+
else {
|
|
260
|
+
setOpenGroup(index);
|
|
261
|
+
setPinned(true);
|
|
262
|
+
}
|
|
263
|
+
}}
|
|
264
|
+
onKeyDown={(event) => {
|
|
265
|
+
if (event.key !== "ArrowDown") return;
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
setOpenGroup(index);
|
|
268
|
+
setPinned(true);
|
|
269
|
+
setFocusPanel(true);
|
|
270
|
+
}}
|
|
271
|
+
>
|
|
272
|
+
{link.label}
|
|
273
|
+
<ChevronDown className="nav-chevron" size={16} aria-hidden="true" />
|
|
274
|
+
</button>
|
|
275
|
+
<NavMegaPanel
|
|
276
|
+
id={`${baseId}p${index}`}
|
|
277
|
+
group={link}
|
|
278
|
+
open={openGroup === index}
|
|
279
|
+
currentPath={currentPath}
|
|
280
|
+
onNavigate={close}
|
|
281
|
+
/>
|
|
282
|
+
</div>
|
|
283
|
+
) : (
|
|
284
|
+
<a
|
|
285
|
+
key={link.href}
|
|
286
|
+
href={link.href}
|
|
287
|
+
aria-current={currentPath === link.href ? "page" : undefined}
|
|
288
|
+
onPointerEnter={(event) => {
|
|
289
|
+
if (event.pointerType === "mouse" && !pinned) close();
|
|
290
|
+
}}
|
|
291
|
+
>
|
|
292
|
+
{link.label}
|
|
293
|
+
</a>
|
|
294
|
+
),
|
|
295
|
+
)}
|
|
108
296
|
</nav>
|
|
109
297
|
)}
|
|
298
|
+
{barPhones.length > 0 && (
|
|
299
|
+
<div className="nav-phones">
|
|
300
|
+
{barPhones.map((phone) => (
|
|
301
|
+
<a
|
|
302
|
+
key={phone.e164}
|
|
303
|
+
className="nav-phone"
|
|
304
|
+
href={`tel:${phone.e164}`}
|
|
305
|
+
aria-label={phoneName(phone)}
|
|
306
|
+
>
|
|
307
|
+
<PhoneIcon size={17} aria-hidden="true" />
|
|
308
|
+
<span className="nav-phone-text">
|
|
309
|
+
{phone.label && <span className="nav-phone-label">{phone.label}</span>}
|
|
310
|
+
<span className="nav-phone-number">{phone.display}</span>
|
|
311
|
+
</span>
|
|
312
|
+
</a>
|
|
313
|
+
))}
|
|
314
|
+
</div>
|
|
315
|
+
)}
|
|
110
316
|
{barCTA && (
|
|
111
317
|
// The class sits on a wrapper, not the button: a site's own .btn
|
|
112
318
|
// display rule lives outside the atelic-ui layer and would beat
|
|
@@ -121,6 +327,15 @@ export function SiteHeader({
|
|
|
121
327
|
</a>
|
|
122
328
|
</span>
|
|
123
329
|
)}
|
|
330
|
+
{barPhones[0] && (
|
|
331
|
+
<a
|
|
332
|
+
className="nav-call"
|
|
333
|
+
href={`tel:${barPhones[0].e164}`}
|
|
334
|
+
aria-label={phoneName(barPhones[0])}
|
|
335
|
+
>
|
|
336
|
+
<PhoneIcon size={19} aria-hidden="true" />
|
|
337
|
+
</a>
|
|
338
|
+
)}
|
|
124
339
|
{hasMenu && (
|
|
125
340
|
<button
|
|
126
341
|
type="button"
|
|
@@ -145,6 +360,8 @@ export function SiteHeader({
|
|
|
145
360
|
links={menuLinks}
|
|
146
361
|
primaryCTA={menuCTA}
|
|
147
362
|
contact={stops ? undefined : contact}
|
|
363
|
+
phones={barPhones.length > 0 ? barPhones : undefined}
|
|
364
|
+
currentPath={currentPath}
|
|
148
365
|
/>
|
|
149
366
|
)}
|
|
150
367
|
</>
|
package/src/chrome/SiteMenu.tsx
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChevronDown } from "lucide-react";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
2
3
|
import { newTabProps } from "../lib/newTabProps";
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
CallToAction,
|
|
6
|
+
HeaderPhone,
|
|
7
|
+
MenuContact,
|
|
8
|
+
NavGroupChildLink,
|
|
9
|
+
NavLink,
|
|
10
|
+
NavPanelSection,
|
|
11
|
+
} from "../types";
|
|
12
|
+
import { NavBadge } from "./NavBadge";
|
|
13
|
+
import { isGroup, isLinkColumn, panelSections } from "./navSections";
|
|
4
14
|
|
|
5
15
|
export interface SiteMenuProps {
|
|
6
16
|
/** Whether the menu is showing. The owner holds this state. */
|
|
@@ -11,12 +21,22 @@ export interface SiteMenuProps {
|
|
|
11
21
|
* the owner asked for, by passing `open={false}`, is not reported back.
|
|
12
22
|
*/
|
|
13
23
|
onClose: () => void;
|
|
14
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The entries in order: a site's nav, or a page's own stops as `#id` links.
|
|
26
|
+
* An entry with `columns` is a group, an accordion that opens one at a time.
|
|
27
|
+
*/
|
|
15
28
|
links: NavLink[];
|
|
16
29
|
/** The primary action, rendered as a standard button below the entries. */
|
|
17
30
|
primaryCTA?: CallToAction;
|
|
18
31
|
/** The phone, email, and address block at the foot. */
|
|
19
32
|
contact?: MenuContact;
|
|
33
|
+
/**
|
|
34
|
+
* The numbers the header shows, each a tel link at the foot with its
|
|
35
|
+
* label, in place of the contact block's one phone.
|
|
36
|
+
*/
|
|
37
|
+
phones?: HeaderPhone[];
|
|
38
|
+
/** The path being read, marking the matching link with aria-current. */
|
|
39
|
+
currentPath?: string;
|
|
20
40
|
id?: string;
|
|
21
41
|
/** The dialog's accessible name. Defaults to "Menu". */
|
|
22
42
|
label?: string;
|
|
@@ -28,6 +48,12 @@ export interface SiteMenuProps {
|
|
|
28
48
|
* return to the burger. The dialog renders closed on the server and opens
|
|
29
49
|
* only in an effect, so the menu stays safe to prerender. Page scroll holds
|
|
30
50
|
* still through chrome.css while the dialog is open.
|
|
51
|
+
*
|
|
52
|
+
* A group is an accordion: its label is a control that opens the group's
|
|
53
|
+
* columns under it and closes whichever group was open. Every group starts
|
|
54
|
+
* closed each time the menu opens, the one holding the current page
|
|
55
|
+
* included, so the menu always opens on the short list of entries. A closed
|
|
56
|
+
* group's links stay in the HTML, `inert`.
|
|
31
57
|
*/
|
|
32
58
|
export function SiteMenu({
|
|
33
59
|
open,
|
|
@@ -35,19 +61,30 @@ export function SiteMenu({
|
|
|
35
61
|
links,
|
|
36
62
|
primaryCTA,
|
|
37
63
|
contact,
|
|
64
|
+
phones,
|
|
65
|
+
currentPath,
|
|
38
66
|
id,
|
|
39
67
|
label = "Menu",
|
|
40
68
|
}: SiteMenuProps) {
|
|
69
|
+
const [openGroup, setOpenGroup] = useState<number | null>(null);
|
|
70
|
+
const groupId = useId();
|
|
41
71
|
const dialogRef = useRef<HTMLDialogElement>(null);
|
|
42
72
|
// Whether the owner already knows the menu is closed. Escape fires cancel
|
|
43
73
|
// and then close, and a followed link closes the dialog and notifies
|
|
44
74
|
// directly, so every path runs through reportClosed and reports once.
|
|
45
75
|
const closedRef = useRef(true);
|
|
76
|
+
// Only a plain entry wears a number, so the numbers count those alone and
|
|
77
|
+
// run 01, 02, 03 down the menu whatever groups sit between them.
|
|
78
|
+
const numbers: number[] = [];
|
|
79
|
+
let counted = 0;
|
|
80
|
+
for (const link of links) numbers.push(isGroup(link) ? 0 : ++counted);
|
|
46
81
|
|
|
47
82
|
useEffect(() => {
|
|
48
83
|
const dialog = dialogRef.current;
|
|
49
84
|
if (!dialog) return;
|
|
50
85
|
closedRef.current = !open;
|
|
86
|
+
// No group is open when the menu opens, whatever page it opens on.
|
|
87
|
+
if (open) setOpenGroup(null);
|
|
51
88
|
if (open && !dialog.open) dialog.showModal();
|
|
52
89
|
if (!open && dialog.open) dialog.close();
|
|
53
90
|
}, [open]);
|
|
@@ -80,12 +117,53 @@ export function SiteMenu({
|
|
|
80
117
|
<span />
|
|
81
118
|
<span />
|
|
82
119
|
</button>
|
|
83
|
-
{links.map((link, i) =>
|
|
84
|
-
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
120
|
+
{links.map((link, i) =>
|
|
121
|
+
isGroup(link) ? (
|
|
122
|
+
<div className="mm-group" key={link.href}>
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
className="mm-link mm-group-btn"
|
|
126
|
+
aria-expanded={openGroup === i}
|
|
127
|
+
aria-controls={`${groupId}${i}`}
|
|
128
|
+
onClick={() => setOpenGroup((current) => (current === i ? null : i))}
|
|
129
|
+
>
|
|
130
|
+
<span>{link.label}</span>
|
|
131
|
+
<ChevronDown className="mm-chevron" size={22} aria-hidden="true" />
|
|
132
|
+
</button>
|
|
133
|
+
<div
|
|
134
|
+
id={`${groupId}${i}`}
|
|
135
|
+
className={["mm-group-panel", openGroup === i && "is-open"].filter(Boolean).join(" ")}
|
|
136
|
+
inert={openGroup !== i}
|
|
137
|
+
>
|
|
138
|
+
{link.allLabel && (
|
|
139
|
+
<a className="mm-group-all" href={link.href} onClick={close}>
|
|
140
|
+
{link.allLabel}
|
|
141
|
+
</a>
|
|
142
|
+
)}
|
|
143
|
+
{panelSections(link).map((section, index) => (
|
|
144
|
+
<MenuSection
|
|
145
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a group's sections never reorder while the menu is open
|
|
146
|
+
key={index}
|
|
147
|
+
section={section}
|
|
148
|
+
currentPath={currentPath}
|
|
149
|
+
onNavigate={close}
|
|
150
|
+
/>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
) : (
|
|
155
|
+
<a
|
|
156
|
+
key={link.href}
|
|
157
|
+
className="mm-link"
|
|
158
|
+
href={link.href}
|
|
159
|
+
onClick={close}
|
|
160
|
+
aria-current={currentPath === link.href ? "page" : undefined}
|
|
161
|
+
>
|
|
162
|
+
<span>{link.label}</span>
|
|
163
|
+
<span className="idx">{String(numbers[i]).padStart(2, "0")}</span>
|
|
164
|
+
</a>
|
|
165
|
+
),
|
|
166
|
+
)}
|
|
89
167
|
{primaryCTA && (
|
|
90
168
|
<a
|
|
91
169
|
className="btn btn-primary btn-lg mm-cta"
|
|
@@ -96,25 +174,125 @@ export function SiteMenu({
|
|
|
96
174
|
{primaryCTA.label}
|
|
97
175
|
</a>
|
|
98
176
|
)}
|
|
99
|
-
{contact && <ContactBlock contact={contact} />}
|
|
177
|
+
{(contact || phones) && <ContactBlock contact={contact ?? {}} phones={phones} />}
|
|
100
178
|
</dialog>
|
|
101
179
|
);
|
|
102
180
|
}
|
|
103
181
|
|
|
104
|
-
|
|
182
|
+
/** A short word in a pill after a link's label, as on the desktop panel. */
|
|
183
|
+
function Badge({ text }: { text?: string }) {
|
|
184
|
+
return <NavBadge text={text} className="mm-badge" />;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* One section of a group, as the phone draws it: a link column with its
|
|
189
|
+
* children indented under their parent, icon rows and cards as plain links
|
|
190
|
+
* of their labels and titles, and a picture as a plain link of its caption,
|
|
191
|
+
* so the page it leads to stays reachable without the photo.
|
|
192
|
+
*/
|
|
193
|
+
function MenuSection({
|
|
194
|
+
section,
|
|
195
|
+
currentPath,
|
|
196
|
+
onNavigate,
|
|
197
|
+
}: {
|
|
198
|
+
section: NavPanelSection;
|
|
199
|
+
currentPath?: string;
|
|
200
|
+
onNavigate: () => void;
|
|
201
|
+
}) {
|
|
202
|
+
// A child may share its parent's href, and two rows may share one, so a
|
|
203
|
+
// link is keyed by its place, never its href alone.
|
|
204
|
+
const link = (
|
|
205
|
+
item: { label: string; href: string; external?: boolean; badge?: string },
|
|
206
|
+
className: string,
|
|
207
|
+
key: string,
|
|
208
|
+
) => (
|
|
209
|
+
<a
|
|
210
|
+
key={key}
|
|
211
|
+
className={className}
|
|
212
|
+
href={item.href}
|
|
213
|
+
onClick={onNavigate}
|
|
214
|
+
aria-current={currentPath === item.href ? "page" : undefined}
|
|
215
|
+
{...newTabProps(item.href, item.external)}
|
|
216
|
+
>
|
|
217
|
+
{item.label}
|
|
218
|
+
<Badge text={item.badge} />
|
|
219
|
+
</a>
|
|
220
|
+
);
|
|
221
|
+
const heading = section.kind === "picture" ? undefined : section.heading;
|
|
222
|
+
const headHref = isLinkColumn(section) ? section.href : undefined;
|
|
223
|
+
if (section.kind === "picture") {
|
|
224
|
+
return (
|
|
225
|
+
<div className="mm-group-col">
|
|
226
|
+
{link(
|
|
227
|
+
{ label: section.caption, href: section.href, external: section.external },
|
|
228
|
+
"mm-group-link",
|
|
229
|
+
"picture",
|
|
230
|
+
)}
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return (
|
|
235
|
+
<div className="mm-group-col">
|
|
236
|
+
{heading &&
|
|
237
|
+
(headHref ? (
|
|
238
|
+
<a className="mm-group-head" href={headHref} onClick={onNavigate}>
|
|
239
|
+
{heading}
|
|
240
|
+
</a>
|
|
241
|
+
) : (
|
|
242
|
+
<p className="mm-group-head">{heading}</p>
|
|
243
|
+
))}
|
|
244
|
+
{isLinkColumn(section)
|
|
245
|
+
? section.links.map((item, index) => (
|
|
246
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: two links may share an href, so the place keeps the key unique; a group's links never reorder
|
|
247
|
+
<div className="mm-group-item" key={`${index} ${item.href}`}>
|
|
248
|
+
{link(item, "mm-group-link", "self")}
|
|
249
|
+
{item.children?.map((child: NavGroupChildLink, childIndex) =>
|
|
250
|
+
link(child, "mm-group-sub", `child ${childIndex}`),
|
|
251
|
+
)}
|
|
252
|
+
</div>
|
|
253
|
+
))
|
|
254
|
+
: section.kind === "rows"
|
|
255
|
+
? section.rows.map((row, index) => link(row, "mm-group-link", `row ${index}`))
|
|
256
|
+
: section.cards.map((card, index) =>
|
|
257
|
+
link(
|
|
258
|
+
{ label: card.title, href: card.href, external: card.external },
|
|
259
|
+
"mm-group-link",
|
|
260
|
+
`card ${index}`,
|
|
261
|
+
),
|
|
262
|
+
)}
|
|
263
|
+
</div>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function ContactBlock({
|
|
268
|
+
contact: { phone, email, address },
|
|
269
|
+
phones,
|
|
270
|
+
}: {
|
|
271
|
+
contact: MenuContact;
|
|
272
|
+
phones?: HeaderPhone[];
|
|
273
|
+
}) {
|
|
105
274
|
return (
|
|
106
275
|
<div className="mm-contact">
|
|
107
276
|
{/* The number and the address are the two things a phone can act on, so
|
|
108
277
|
each is a real link: a tel link dials, a mailto opens mail. Protocol
|
|
109
278
|
links never open a new tab (rule 12). Plain text here read as friction. */}
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
279
|
+
{phones
|
|
280
|
+
? phones.map((line) => (
|
|
281
|
+
<span key={line.e164}>
|
|
282
|
+
<a className="mm-contact-link" href={`tel:${line.e164}`}>
|
|
283
|
+
{line.label ? line.label.toUpperCase() : "CALL / TEXT"} {line.display}
|
|
284
|
+
</a>
|
|
285
|
+
<br />
|
|
286
|
+
</span>
|
|
287
|
+
))
|
|
288
|
+
: phone && (
|
|
289
|
+
<>
|
|
290
|
+
<a className="mm-contact-link" href={`tel:${phone.e164}`}>
|
|
291
|
+
CALL / TEXT {phone.display}
|
|
292
|
+
</a>
|
|
293
|
+
<br />
|
|
294
|
+
</>
|
|
295
|
+
)}
|
|
118
296
|
{email && (
|
|
119
297
|
<>
|
|
120
298
|
<a className="mm-contact-link" href={`mailto:${email}`}>
|