@atelic-action/ui 7.2.0 → 8.1.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.
Files changed (131) hide show
  1. package/README.md +439 -132
  2. package/bin/atelic-check-sentry.ts +5 -0
  3. package/dist/gate/middleware.js +15 -1
  4. package/dist/monitoring/server.d.ts +72 -0
  5. package/dist/monitoring/server.js +201 -0
  6. package/dist/vite/index.d.ts +1 -1
  7. package/dist/vite/index.js +1 -1
  8. package/dist/vite/marketing-config.d.ts +28 -1
  9. package/dist/vite/marketing-config.js +62 -0
  10. package/package.json +23 -11
  11. package/src/app/ErrorFallback.tsx +6 -2
  12. package/src/app/context/AppContext.tsx +10 -1
  13. package/src/app/index.ts +0 -1
  14. package/src/app/layout/AppPage.tsx +36 -7
  15. package/src/app/layout/DesktopRail.tsx +15 -6
  16. package/src/app/layout/MobileMenu.tsx +14 -5
  17. package/src/app/layout/MobileTabBar.tsx +3 -2
  18. package/src/app/layout/PageError.tsx +7 -4
  19. package/src/app/layout/PageSkeleton.tsx +33 -26
  20. package/src/app/layout/SectionCards.tsx +7 -2
  21. package/src/app/layout/UserMenu.tsx +13 -7
  22. package/src/app/ui/alert.tsx +42 -12
  23. package/src/app/ui/badge.tsx +1 -1
  24. package/src/app/ui/button.tsx +2 -1
  25. package/src/app/ui/command.tsx +86 -21
  26. package/src/app/ui/country-dropdown.tsx +26 -47
  27. package/src/app/ui/form.tsx +48 -9
  28. package/src/app/ui/pagination.tsx +1 -1
  29. package/src/app/ui/progress.tsx +26 -12
  30. package/src/app/ui/search-input.tsx +16 -3
  31. package/src/app/ui/select.tsx +8 -3
  32. package/src/app/ui/slider.tsx +62 -15
  33. package/src/artifact/AppErrorBoundary.tsx +12 -7
  34. package/src/artifact/ArtifactShell.tsx +5 -1
  35. package/src/artifact/ErrorFallback.tsx +8 -1
  36. package/src/artifact/artifactConfig.ts +1 -1
  37. package/src/chrome/BrandLockup.tsx +102 -17
  38. package/src/chrome/ClosingBar.tsx +5 -3
  39. package/src/chrome/ContactDock.tsx +361 -0
  40. package/src/chrome/Footer.tsx +126 -31
  41. package/src/chrome/NavBadge.tsx +8 -0
  42. package/src/chrome/NavMegaPanel.tsx +399 -0
  43. package/src/chrome/SiteHeader.tsx +268 -23
  44. package/src/chrome/SiteMenu.tsx +200 -19
  45. package/src/chrome/SiteShell.tsx +151 -14
  46. package/src/chrome/StickyCTABar.tsx +60 -2
  47. package/src/chrome/brandMark.ts +56 -0
  48. package/src/chrome/icons.ts +58 -0
  49. package/src/chrome/index.ts +16 -0
  50. package/src/chrome/navSections.ts +55 -0
  51. package/src/components/ColumnChart.tsx +27 -2
  52. package/src/components/DataTable.tsx +104 -85
  53. package/src/components/Disclosure.tsx +3 -1
  54. package/src/components/Hint.tsx +3 -24
  55. package/src/components/NotFound.tsx +7 -3
  56. package/src/components/StarRating.tsx +45 -19
  57. package/src/components/ThresholdScale.tsx +36 -26
  58. package/src/email/atoms.tsx +13 -57
  59. package/src/email/frame.tsx +4 -6
  60. package/src/email/index.ts +4 -10
  61. package/src/email/scoreboard.tsx +107 -186
  62. package/src/email/text.ts +30 -0
  63. package/src/email/theme.tsx +76 -9
  64. package/src/gate/middleware.ts +15 -1
  65. package/src/hooks/useDismiss.ts +39 -0
  66. package/src/lib/emailText.tsx +26 -0
  67. package/src/lib/phoneText.tsx +40 -0
  68. package/src/lib/useScrollsSideways.ts +26 -0
  69. package/src/monitoring/ErrorCatcherScript.tsx +15 -0
  70. package/src/monitoring/catcher.ts +118 -0
  71. package/src/monitoring/index.ts +25 -0
  72. package/src/monitoring/sdk.ts +112 -0
  73. package/src/monitoring/server.ts +244 -0
  74. package/src/monitoring/start.ts +118 -0
  75. package/src/primitives/Button.tsx +5 -1
  76. package/src/primitives/Eyebrow.tsx +6 -2
  77. package/src/primitives/ProseBlocks.tsx +6 -1
  78. package/src/primitives/SectionHeading.tsx +3 -1
  79. package/src/primitives/StarRow.tsx +23 -8
  80. package/src/routing/index.ts +1 -0
  81. package/src/routing/miss.ts +32 -0
  82. package/src/scripts/check-sentry.ts +77 -0
  83. package/src/sections/BlogIndex.tsx +17 -3
  84. package/src/sections/BlogPost.tsx +10 -1
  85. package/src/sections/CTASection.tsx +2 -2
  86. package/src/sections/CalloutPanel.tsx +34 -0
  87. package/src/sections/ComparisonTable.tsx +23 -2
  88. package/src/sections/ContactForm.tsx +61 -17
  89. package/src/sections/FAQBrowser.tsx +11 -2
  90. package/src/sections/FeatureGrid.tsx +6 -2
  91. package/src/sections/FullBleedVideo.tsx +167 -0
  92. package/src/sections/Gallery.tsx +6 -4
  93. package/src/sections/Hero.tsx +70 -39
  94. package/src/sections/JumpRail.tsx +7 -0
  95. package/src/sections/LegalPage.tsx +10 -2
  96. package/src/sections/LinkColumns.tsx +80 -0
  97. package/src/sections/LocationSection.tsx +28 -5
  98. package/src/sections/Locations.tsx +18 -5
  99. package/src/sections/LogoMarquee.tsx +43 -11
  100. package/src/sections/MapEmbed.tsx +13 -9
  101. package/src/sections/PageHero.tsx +16 -2
  102. package/src/sections/ProcessSteps.tsx +27 -4
  103. package/src/sections/ProfileCards.tsx +12 -2
  104. package/src/sections/ProofStrip.tsx +44 -0
  105. package/src/sections/RevealSlider.tsx +28 -7
  106. package/src/sections/ReviewCarousel.tsx +17 -4
  107. package/src/sections/ReviewWall.tsx +2 -2
  108. package/src/sections/SplitSection.tsx +2 -1
  109. package/src/sections/index.ts +15 -6
  110. package/src/sections/siteConfig.ts +101 -8
  111. package/src/styles/app.css +33 -2
  112. package/src/styles/artifact.css +20 -8
  113. package/src/styles/base.css +68 -13
  114. package/src/styles/chrome.css +1134 -56
  115. package/src/styles/components.css +104 -65
  116. package/src/styles/defaults.css +140 -0
  117. package/src/styles/gate.css +21 -10
  118. package/src/styles/primitives.css +108 -39
  119. package/src/styles/sections.css +500 -437
  120. package/src/styles/star-rating.css +1 -4
  121. package/src/tokens/palettes.ts +24 -4
  122. package/src/types.ts +220 -3
  123. package/src/vite/index.ts +4 -0
  124. package/src/vite/marketing-config.ts +81 -1
  125. package/src/app/CardErrorBoundary.tsx +0 -39
  126. package/src/sections/CTABanner.tsx +0 -93
  127. package/src/sections/DeviceShowcase.tsx +0 -39
  128. package/src/sections/MediaBand.tsx +0 -20
  129. package/src/sections/MenuList.tsx +0 -44
  130. package/src/sections/PressQuotes.tsx +0 -51
  131. package/src/sections/SocialStrip.tsx +0 -83
@@ -1,34 +1,119 @@
1
- import type { Brand } from "../types";
1
+ import type { Brand, BrandLogo } from "../types";
2
+ import { hasMark, type MarkSurface, type ResolvedMark, resolveMark, tintClass } from "./brandMark";
2
3
 
3
4
  export interface BrandLockupProps {
4
5
  brand: Brand;
5
- /** The link's accessible name. Defaults to "<name> home". */
6
+ /**
7
+ * The link's accessible name. Defaults to the words the lockup shows (the
8
+ * brand's name when they are its name in another case), then "home".
9
+ */
6
10
  ariaLabel?: string;
7
11
  }
8
12
 
13
+ /**
14
+ * The glyph tile mark (`logo.tile`): the favicon's design, its letter drawn
15
+ * by the stylesheet from `data-glyph` so it is never text in the link. Were
16
+ * it text, a link reading "K" then "Kestrel Hollow" would show words its
17
+ * name does not hold. Decorative, and hidden from assistive technology.
18
+ */
19
+ export function LogoTile({ glyph }: { glyph: string }) {
20
+ return <span className="logo-tile" data-glyph={glyph} aria-hidden="true" />;
21
+ }
22
+
23
+ function MarkImage({ mark, surface }: { mark: ResolvedMark; surface?: "light" | "dark" }) {
24
+ const className = ["mark", surface && `is-on-${surface}`, tintClass(mark)]
25
+ .filter(Boolean)
26
+ .join(" ");
27
+ return <img className={className} src={mark.src} alt="" />;
28
+ }
29
+
30
+ /**
31
+ * The header's mark: a glyph tile, or the image each surface resolves to
32
+ * (`resolveMark`), one per surface, each shown on its own bar by chrome.css.
33
+ * When both surfaces draw the same image the same way, it is drawn once.
34
+ * Given a `surface`, it draws that surface's image alone, for a place that
35
+ * only ever wears one ground (the footer's dark band).
36
+ */
37
+ function Mark({ logo, surface }: { logo?: BrandLogo; surface?: MarkSurface }) {
38
+ if (logo?.tile) return <LogoTile glyph={logo.tile} />;
39
+ if (surface) {
40
+ const mark = resolveMark(logo, surface);
41
+ return mark ? <MarkImage mark={mark} /> : null;
42
+ }
43
+ const light = resolveMark(logo, "light");
44
+ const dark = resolveMark(logo, "dark");
45
+ if (!light || !dark) return null;
46
+ if (light.src === dark.src && light.tint === dark.tint) return <MarkImage mark={light} />;
47
+ return (
48
+ <>
49
+ <MarkImage mark={light} surface="light" />
50
+ <MarkImage mark={dark} surface="dark" />
51
+ </>
52
+ );
53
+ }
54
+
55
+ /**
56
+ * The live words beside the mark: the wordmark the logo names, else the
57
+ * brand's name. `wordmark: false` drops them beside artwork that spells the
58
+ * name, and only there: with no mark to stand in, the name stays, so the
59
+ * home link is never empty.
60
+ */
61
+ export function lockupWords(name: string, logo: BrandLogo | undefined): string | null {
62
+ if (logo?.wordmark === false) return hasMark(logo) ? null : name;
63
+ return logo?.wordmark ?? name;
64
+ }
65
+
66
+ /**
67
+ * The lockup's parts, in the order the header draws them: the mark, the
68
+ * live words beside it (`lockupWords`), and the trailing run. The header
69
+ * wraps them in its home link; the footer sets them on its dark band, passing
70
+ * `surface` so only that ground's image is drawn. The mark's image carries
71
+ * empty alt text, since the words beside it name the lockup.
72
+ */
73
+ export function LockupParts({
74
+ name,
75
+ logo,
76
+ surface,
77
+ }: {
78
+ name: string;
79
+ logo?: BrandLogo;
80
+ surface?: MarkSurface;
81
+ }) {
82
+ const wordmark = lockupWords(name, logo);
83
+ return (
84
+ <>
85
+ <Mark logo={logo} surface={surface} />
86
+ {wordmark !== null && <span className="wordmark">{wordmark}</span>}
87
+ {logo?.run && <span className="wordmark-run" aria-hidden="true" />}
88
+ </>
89
+ );
90
+ }
91
+
9
92
  /**
10
93
  * The header's identity as one link: the mark (a glyph tile or an image),
11
94
  * the wordmark, and the trailing run. The image carries empty alt text
12
- * because the link's own label already names it. On a sent artifact the
13
- * recipient's mark follows, after a times sign: "atelic × Wynkoop Athletics",
14
- * the sender's identity and the business the document is for in one lockup.
15
- * The anchor's aria-label folds in the recipient's alt too, since it
16
- * overrides accessible-name computation for every child, image alt included.
95
+ * because the link's own label already names it. A mark is as tall as
96
+ * `--brand-mark-height` and as wide as its own ratio; a site whose artwork is
97
+ * cut per surface passes `onLight` and `onDark`, and a cut is never
98
+ * recolored on its own surface (see `resolveMark` for a surface with none).
99
+ * On a sent artifact the recipient's mark follows, after a times sign:
100
+ * "atelic × Wynkoop Athletics", the sender's identity and the business the
101
+ * document is for in one lockup. The anchor's aria-label folds in the
102
+ * recipient's alt too, since it overrides accessible-name computation for
103
+ * every child, image alt included, and it always holds the words the link
104
+ * shows, so what a reader sees is what a voice user can say.
17
105
  */
18
106
  export function BrandLockup({ brand, ariaLabel }: BrandLockupProps) {
19
107
  const { name, href = "/", logo, recipient } = brand;
20
- const label = ariaLabel ?? (recipient ? `${name} × ${recipient.alt} home` : `${name} home`);
108
+ const wordmark = lockupWords(name, logo);
109
+ // The visible words lead the name. A wordmark that is the name in another
110
+ // case (or a part of it) keeps the name's own spelling.
111
+ const words =
112
+ wordmark === null || name.toLowerCase().includes(wordmark.toLowerCase()) ? name : wordmark;
113
+ const label = ariaLabel ?? (recipient ? `${words} × ${recipient.alt} home` : `${words} home`);
21
114
  return (
22
115
  <a className="nav-logo" href={href} aria-label={label}>
23
- {logo?.tile ? (
24
- <span className="logo-tile" aria-hidden="true">
25
- {logo.tile}
26
- </span>
27
- ) : (
28
- logo?.src && <img className="mark" src={logo.src} alt="" />
29
- )}
30
- <span className="wordmark">{logo?.wordmark ?? name}</span>
31
- {logo?.run && <span className="wordmark-run" aria-hidden="true" />}
116
+ <LockupParts name={name} logo={logo} />
32
117
  {recipient && (
33
118
  <>
34
119
  <span className="nav-x" aria-hidden="true">
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from "react";
1
+ import type { ReactNode, Ref } from "react";
2
2
  import { Copyright } from "./Copyright";
3
3
  import { Credit } from "./Credit";
4
4
 
@@ -15,6 +15,8 @@ export interface ClosingBarProps {
15
15
  * it; anything else renders as given.
16
16
  */
17
17
  right?: ReactNode;
18
+ /** The bar's element, for a caller that measures it. */
19
+ ref?: Ref<HTMLDivElement>;
18
20
  }
19
21
 
20
22
  /**
@@ -25,7 +27,7 @@ export interface ClosingBarProps {
25
27
  * sent document closes the way a site does); with nothing on the left, the
26
28
  * right side sits centered.
27
29
  */
28
- export function ClosingBar({ name, left, right }: ClosingBarProps) {
30
+ export function ClosingBar({ name, left, right, ref }: ClosingBarProps) {
29
31
  const leftSide = left === undefined ? name ? <Copyright name={name} /> : null : left;
30
32
  const rightSide = right === undefined ? <Credit /> : right;
31
33
  const hasLeft = leftSide !== null && leftSide !== false;
@@ -33,7 +35,7 @@ export function ClosingBar({ name, left, right }: ClosingBarProps) {
33
35
  if (!hasLeft && !hasRight) return null;
34
36
 
35
37
  return (
36
- <div className={hasLeft ? "closing-bar" : "closing-bar is-solo"}>
38
+ <div ref={ref} className={hasLeft ? "closing-bar" : "closing-bar is-solo"}>
37
39
  <div className="wrap closing-bar-line">
38
40
  {hasLeft && <div className="closing-bar-left">{leftSide}</div>}
39
41
  {hasRight && <div className="closing-bar-right">{rightSide}</div>}
@@ -0,0 +1,361 @@
1
+ import { ChevronRight, MessageCircle, X } from "lucide-react";
2
+ import { type RefObject, useEffect, useId, useRef, useState } from "react";
3
+ import { useDismiss } from "../hooks/useDismiss";
4
+ import { newTabProps } from "../lib/newTabProps";
5
+ import { holdPhoneNumbers, isTel } from "../lib/phoneText";
6
+ import type { ContactDockConfig } from "../types";
7
+ import { dockIcons } from "./icons";
8
+
9
+ export interface ContactDockProps extends ContactDockConfig {
10
+ /**
11
+ * The element the dock never covers: as it scrolls into view the dock
12
+ * rides up to sit just above its top edge. A ref to it, or a selector;
13
+ * defaults to the page's `footer`, and `null` avoids nothing.
14
+ */
15
+ avoid?: string | RefObject<Element | null> | null;
16
+ /**
17
+ * A selector for the bar the dock lifts over while that bar shows. The
18
+ * bar says it is showing with `data-showing="true"`, or, for a bar that
19
+ * sets no `data-showing`, with the `show` class the sticky bar wore before
20
+ * 8.0.0. `StickyCTABar` wears `data-dock-lift` and keeps `data-showing`
21
+ * current; the default finds it, or failing that a site's own
22
+ * `.sticky-cta`. `null` lifts over nothing.
23
+ */
24
+ lift?: string | null;
25
+ /**
26
+ * A selector for the fixed header the launcher never rises into: as the
27
+ * dock lifts over a tall footer it stops just under the header's bottom
28
+ * edge. Defaults to the package's own header (`header.nav`); `null`
29
+ * reads the screen's top edge alone.
30
+ */
31
+ header?: string | null;
32
+ /**
33
+ * Whether the dock tracks the page: it lifts over the phone's sticky bar
34
+ * once that bar shows, and rises above the footer. Off holds it at its
35
+ * corner inset (a preview frame). Defaults on.
36
+ */
37
+ track?: boolean;
38
+ /** The launcher's words while the panel is open. Defaults to "Close". */
39
+ closeLabel?: string;
40
+ /**
41
+ * The accessible name of the close button in the panel's head, kept apart
42
+ * from the launcher's so the two controls never share a name. Defaults to
43
+ * "Close panel".
44
+ */
45
+ panelCloseLabel?: string;
46
+ /** Start with the panel open (a preview of the open state). */
47
+ defaultOpen?: boolean;
48
+ }
49
+
50
+ /** The default header: the package's own fixed bar. */
51
+ const DEFAULT_HEADER = "header.nav";
52
+
53
+ /** The default lift: the package's own bar, or a site's bar of the old class. */
54
+ const DEFAULT_LIFT = "[data-dock-lift], .sticky-cta";
55
+
56
+ /**
57
+ * Whether the bar the dock lifts over is showing: its `data-showing` when it
58
+ * keeps one, else the `show` class, and never while the stylesheet hides it
59
+ * (a desktop). Exported for the tests; a site never calls it.
60
+ */
61
+ export function barShowing(bar: HTMLElement | null): boolean {
62
+ if (!bar) return false;
63
+ const flag = bar.dataset.showing;
64
+ const shown = flag === undefined ? bar.classList.contains("show") : flag === "true";
65
+ return shown && getComputedStyle(bar).display !== "none";
66
+ }
67
+
68
+ /** Where the phone layout starts, the sticky bar's own breakpoint. */
69
+ const PHONE_MAX = 899;
70
+
71
+ /** The launcher's height, matching `.cd-launch`. */
72
+ const LAUNCHER_HEIGHT = 52;
73
+
74
+ /**
75
+ * The corner the dock sits in: the same inset from the right and the bottom
76
+ * edge (16 on a phone, 24 above), lifted over the phone's sticky bar once
77
+ * that bar is showing, and never over the footer: as the footer's top edge
78
+ * comes up the viewport, the dock rides up to stay just above it, until it
79
+ * reaches the fixed header: it never rises into the header, and a footer
80
+ * taller than the room left holds it there rather than chasing the footer.
81
+ * Exported for the tests; a site never calls it.
82
+ */
83
+ export function dockPlacement({
84
+ viewportWidth,
85
+ viewportHeight,
86
+ barHeight,
87
+ avoidTop,
88
+ headerBottom = 0,
89
+ }: {
90
+ viewportWidth: number;
91
+ viewportHeight: number;
92
+ /** The sticky bar's height when it is showing, else 0. */
93
+ barHeight: number;
94
+ /** The avoided element's top edge in the viewport, or null when there is none. */
95
+ avoidTop: number | null;
96
+ /** The fixed header's bottom edge in the viewport, or 0 with no header. */
97
+ headerBottom?: number;
98
+ }): { inset: number; bottom: number } {
99
+ const phone = viewportWidth <= PHONE_MAX;
100
+ const inset = phone ? 16 : 24;
101
+ const overBar = phone && barHeight > 0 ? barHeight + inset : inset;
102
+ const covered = avoidTop === null ? 0 : Math.max(0, viewportHeight - avoidTop);
103
+ const overFooter = covered > 0 ? covered + inset : 0;
104
+ // Never into the header, nor past the top of the screen: a footer taller
105
+ // than the room left holds the launcher just under the header (the
106
+ // burger's row on a phone), still reachable and covering nothing of it.
107
+ const top = Math.max(0, headerBottom);
108
+ const ceiling = Math.max(inset, viewportHeight - top - LAUNCHER_HEIGHT - inset);
109
+ return { inset, bottom: Math.round(Math.min(ceiling, Math.max(overBar, overFooter))) };
110
+ }
111
+
112
+ /**
113
+ * A floating launcher in the page's corner that opens a small panel of the
114
+ * ways to reach the business: a chat, a call, a form, each an item passed as
115
+ * data. The open state lives in React state; every measurement runs in an
116
+ * effect, so it prerenders closed and at its default inset. The panel stays
117
+ * in the HTML while closed, `inert`. Escape and a click outside close it.
118
+ * On a phone the launcher is its icon alone and the panel is a sheet across
119
+ * the bottom of the screen.
120
+ */
121
+ export function ContactDock({
122
+ label,
123
+ title,
124
+ subtitle,
125
+ items,
126
+ footnote,
127
+ avoid = "footer",
128
+ lift = DEFAULT_LIFT,
129
+ header = DEFAULT_HEADER,
130
+ track = true,
131
+ closeLabel = "Close",
132
+ panelCloseLabel = "Close panel",
133
+ defaultOpen = false,
134
+ }: ContactDockProps) {
135
+ const [open, setOpen] = useState(defaultOpen);
136
+ // Unmeasured, the dock sits at the corner chrome.css gives it for the
137
+ // viewport; tracking sets its place inline once it has measured.
138
+ const [place, setPlace] = useState<{ inset: number; bottom: number } | null>(null);
139
+ const rootRef = useRef<HTMLDivElement>(null);
140
+ const launchRef = useRef<HTMLButtonElement>(null);
141
+ const panelRef = useRef<HTMLElement>(null);
142
+ const opened = useRef(defaultOpen);
143
+ const panelId = useId();
144
+ const headingId = `${panelId}h`;
145
+
146
+ useEffect(() => {
147
+ if (!track) {
148
+ setPlace(null);
149
+ return;
150
+ }
151
+ let frame = 0;
152
+ let bound = 0;
153
+ // The bar and the avoided element are found once and again only when
154
+ // the page's elements change, never on a scroll frame.
155
+ let bar: HTMLElement | null = null;
156
+ let footer: Element | null = null;
157
+ let head: Element | null = null;
158
+ const measure = () => {
159
+ const showing = barShowing(bar);
160
+ const next = dockPlacement({
161
+ viewportWidth: window.innerWidth,
162
+ viewportHeight: window.innerHeight,
163
+ barHeight: showing && bar ? bar.getBoundingClientRect().height : 0,
164
+ avoidTop: footer ? footer.getBoundingClientRect().top : null,
165
+ headerBottom: head ? head.getBoundingClientRect().bottom : 0,
166
+ });
167
+ setPlace((current) =>
168
+ current && current.inset === next.inset && current.bottom === next.bottom ? current : next,
169
+ );
170
+ };
171
+ // Read after the frame, so the sticky bar's own scroll handler has rendered.
172
+ const schedule = () => {
173
+ cancelAnimationFrame(frame);
174
+ frame = requestAnimationFrame(measure);
175
+ };
176
+ const sizes = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(schedule);
177
+ // The bar slides in on an attribute change no scroll may follow (a bar
178
+ // shown from the top), so its own element is watched as well.
179
+ const shows =
180
+ typeof MutationObserver === "undefined" ? undefined : new MutationObserver(schedule);
181
+ const findBar = () => (lift ? document.querySelector<HTMLElement>(lift) : null);
182
+ const findHeader = () => (header ? document.querySelector(header) : null);
183
+ const findFooter = () =>
184
+ avoid === null
185
+ ? null
186
+ : typeof avoid === "string"
187
+ ? document.querySelector(avoid)
188
+ : avoid.current;
189
+ const bind = () => {
190
+ bar = findBar();
191
+ footer = findFooter();
192
+ head = findHeader();
193
+ sizes?.disconnect();
194
+ shows?.disconnect();
195
+ // The page's own height moves the footer (a late image, an opened
196
+ // fold), and the bar and the footer can change size themselves.
197
+ sizes?.observe(document.body);
198
+ if (bar) {
199
+ sizes?.observe(bar);
200
+ shows?.observe(bar, { attributes: true, attributeFilter: ["data-showing", "class"] });
201
+ }
202
+ if (footer) sizes?.observe(footer);
203
+ measure();
204
+ };
205
+ // A route change swaps the footer, and a bar can mount after the dock:
206
+ // either is an element added or removed. The page's other changes (a
207
+ // carousel stepping, a form's message) add elements too, so a frame's
208
+ // worth of them is gathered into one look, and that look only asks the
209
+ // two selectors again: the dock rebinds, observing and measuring anew,
210
+ // only when the bar or the footer it finds is not the one it holds.
211
+ const check = () => {
212
+ if (findBar() !== bar || findFooter() !== footer || findHeader() !== head) bind();
213
+ };
214
+ // The dock's own changes (its icon swapping as it opens) never move the bar
215
+ // or the footer, so they are not looked at.
216
+ const rebind = (records: MutationRecord[]) => {
217
+ const own = rootRef.current;
218
+ if (own && records.every((record) => own.contains(record.target))) return;
219
+ cancelAnimationFrame(bound);
220
+ bound = requestAnimationFrame(check);
221
+ };
222
+ const added =
223
+ typeof MutationObserver === "undefined" ? undefined : new MutationObserver(rebind);
224
+ added?.observe(document.body, { childList: true, subtree: true });
225
+ window.addEventListener("scroll", schedule, { passive: true });
226
+ window.addEventListener("resize", schedule);
227
+ bind();
228
+ return () => {
229
+ cancelAnimationFrame(frame);
230
+ cancelAnimationFrame(bound);
231
+ window.removeEventListener("scroll", schedule);
232
+ window.removeEventListener("resize", schedule);
233
+ sizes?.disconnect();
234
+ shows?.disconnect();
235
+ added?.disconnect();
236
+ };
237
+ }, [avoid, lift, header, track]);
238
+
239
+ useDismiss(open, rootRef, (reason) => {
240
+ setOpen(false);
241
+ if (reason === "escape") launchRef.current?.focus();
242
+ });
243
+
244
+ // The panel sits before the launcher in the DOM (it opens upward), so Tab
245
+ // from the launcher would skip it: opening by hand moves focus in.
246
+ useEffect(() => {
247
+ if (!open) return;
248
+ if (!opened.current) panelRef.current?.querySelector<HTMLElement>(".cd-close")?.focus();
249
+ opened.current = true;
250
+ return () => {
251
+ opened.current = false;
252
+ };
253
+ }, [open]);
254
+
255
+ const heading = title ?? label;
256
+
257
+ return (
258
+ <div
259
+ ref={rootRef}
260
+ className={["contact-dock", open && "is-open"].filter(Boolean).join(" ")}
261
+ // While open the dock sits in the corner: the phone's panel is a sheet that
262
+ // reserves room for the launcher there, and a desktop panel opens upward
263
+ // and would run off the top if the dock were riding above the footer.
264
+ style={place ? { right: place.inset, bottom: open ? place.inset : place.bottom } : undefined}
265
+ >
266
+ <section
267
+ ref={panelRef}
268
+ id={panelId}
269
+ className="cd-panel"
270
+ aria-labelledby={headingId}
271
+ inert={!open}
272
+ hidden={!open}
273
+ >
274
+ <div className="cd-head">
275
+ <div className="cd-head-text">
276
+ {/* A heading by role, never an h2 element: a site's heading rules
277
+ and the brand's heading tokens are for its page titles, not
278
+ this small label (Component Rules 21). */}
279
+ {/* biome-ignore lint/a11y/useSemanticElements: an h2 element would take a site's heading rules and tokens, see above */}
280
+ <div className="cd-title" id={headingId} role="heading" aria-level={2}>
281
+ {heading}
282
+ </div>
283
+ {subtitle && <p className="cd-sub">{subtitle}</p>}
284
+ </div>
285
+ <button
286
+ type="button"
287
+ className="cd-close"
288
+ aria-label={panelCloseLabel}
289
+ onClick={() => {
290
+ setOpen(false);
291
+ launchRef.current?.focus();
292
+ }}
293
+ >
294
+ <X size={20} aria-hidden="true" />
295
+ </button>
296
+ </div>
297
+ <ul className="cd-items">
298
+ {items.map((item, at) => {
299
+ const Icon = dockIcons[item.icon ?? "chat"];
300
+ // A call row holds its number whole and wraps its words.
301
+ const words = (text: string) => (isTel(item.href) ? holdPhoneNumbers(text) : text);
302
+ const inner = (
303
+ <>
304
+ <span className="cd-item-icon">
305
+ <Icon size={20} aria-hidden="true" />
306
+ </span>
307
+ <span className="cd-item-text">
308
+ <span className="cd-item-label">{words(item.label)}</span>
309
+ {item.description && (
310
+ <span className="cd-item-desc">{words(item.description)}</span>
311
+ )}
312
+ </span>
313
+ <ChevronRight className="cd-item-go" size={18} aria-hidden="true" />
314
+ </>
315
+ );
316
+ const className = ["cd-item", item.lead && "is-lead"].filter(Boolean).join(" ");
317
+ return (
318
+ // biome-ignore lint/suspicious/noArrayIndexKey: two items may share a label or a link, so the place keeps the key unique; items never reorder
319
+ <li key={at}>
320
+ {item.href !== undefined ? (
321
+ <a
322
+ className={className}
323
+ href={item.href}
324
+ onClick={() => setOpen(false)}
325
+ {...newTabProps(item.href, item.external)}
326
+ >
327
+ {inner}
328
+ </a>
329
+ ) : (
330
+ <button
331
+ type="button"
332
+ className={className}
333
+ onClick={() => {
334
+ setOpen(false);
335
+ item.onSelect?.();
336
+ }}
337
+ >
338
+ {inner}
339
+ </button>
340
+ )}
341
+ </li>
342
+ );
343
+ })}
344
+ </ul>
345
+ {footnote && <p className="cd-foot">{footnote}</p>}
346
+ </section>
347
+ <button
348
+ ref={launchRef}
349
+ type="button"
350
+ className="cd-launch"
351
+ aria-expanded={open}
352
+ aria-controls={panelId}
353
+ onClick={() => setOpen((current) => !current)}
354
+ >
355
+ {open ? <X size={22} aria-hidden="true" /> : <MessageCircle size={22} aria-hidden="true" />}
356
+ {/* Visually hidden on a phone, where the launcher is its icon, and still its name. */}
357
+ <span className="cd-launch-text">{open ? closeLabel : label}</span>
358
+ </button>
359
+ </div>
360
+ );
361
+ }