@slipstream-ui/core 0.8.0 → 0.9.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 (325) hide show
  1. package/dist/index.d.mts +184 -8
  2. package/dist/index.d.ts +184 -8
  3. package/dist/index.js +1609 -887
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1651 -933
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/manifests/accordion.manifest.json +2 -2
  8. package/dist/manifests/alert.manifest.json +1 -1
  9. package/dist/manifests/announcement-bar.manifest.json +1 -1
  10. package/dist/manifests/app-shell.manifest.json +1 -1
  11. package/dist/manifests/applied-filters.manifest.json +1 -1
  12. package/dist/manifests/article-card.manifest.json +1 -1
  13. package/dist/manifests/auth-layout.manifest.json +1 -1
  14. package/dist/manifests/autocomplete.manifest.json +1 -1
  15. package/dist/manifests/avatar.manifest.json +1 -1
  16. package/dist/manifests/badge.manifest.json +1 -1
  17. package/dist/manifests/block.manifest.json +1 -1
  18. package/dist/manifests/bottom-nav.manifest.json +1 -1
  19. package/dist/manifests/breadcrumb.manifest.json +1 -1
  20. package/dist/manifests/button-group.manifest.json +1 -1
  21. package/dist/manifests/button.manifest.json +1 -1
  22. package/dist/manifests/calendar.manifest.json +175 -0
  23. package/dist/manifests/card.manifest.json +1 -1
  24. package/dist/manifests/checkbox.manifest.json +1 -1
  25. package/dist/manifests/comparison-table.manifest.json +1 -1
  26. package/dist/manifests/confirm-dialog.manifest.json +1 -1
  27. package/dist/manifests/contact-strip.manifest.json +1 -1
  28. package/dist/manifests/container.manifest.json +1 -1
  29. package/dist/manifests/cta-section.manifest.json +1 -1
  30. package/dist/manifests/data-table.manifest.json +8 -1
  31. package/dist/manifests/date-picker-popover.manifest.json +202 -0
  32. package/dist/manifests/date-picker.manifest.json +1 -1
  33. package/dist/manifests/date-range-picker.manifest.json +1 -1
  34. package/dist/manifests/deal-card.manifest.json +1 -1
  35. package/dist/manifests/dialog.manifest.json +1 -1
  36. package/dist/manifests/document-card.manifest.json +1 -1
  37. package/dist/manifests/drawer.manifest.json +1 -1
  38. package/dist/manifests/empty-state.manifest.json +1 -1
  39. package/dist/manifests/entity-card.manifest.json +1 -1
  40. package/dist/manifests/feature-grid.manifest.json +1 -1
  41. package/dist/manifests/feature-row.manifest.json +1 -1
  42. package/dist/manifests/fieldset.manifest.json +1 -1
  43. package/dist/manifests/file-upload.manifest.json +1 -1
  44. package/dist/manifests/filter-bar.manifest.json +1 -1
  45. package/dist/manifests/filter-chips.manifest.json +1 -1
  46. package/dist/manifests/filter-panel.manifest.json +1 -1
  47. package/dist/manifests/flex.manifest.json +1 -1
  48. package/dist/manifests/form-field.manifest.json +1 -1
  49. package/dist/manifests/form-layout.manifest.json +1 -1
  50. package/dist/manifests/form.manifest.json +1 -1
  51. package/dist/manifests/grid.manifest.json +1 -1
  52. package/dist/manifests/heading.manifest.json +1 -1
  53. package/dist/manifests/hero.manifest.json +1 -1
  54. package/dist/manifests/image.manifest.json +142 -0
  55. package/dist/manifests/input-group.manifest.json +1 -1
  56. package/dist/manifests/input.manifest.json +1 -1
  57. package/dist/manifests/label.manifest.json +1 -1
  58. package/dist/manifests/link-tabs.manifest.json +1 -1
  59. package/dist/manifests/link.manifest.json +1 -1
  60. package/dist/manifests/list.manifest.json +1 -1
  61. package/dist/manifests/load-more.manifest.json +1 -1
  62. package/dist/manifests/logo-cloud.manifest.json +1 -1
  63. package/dist/manifests/menu.manifest.json +1 -1
  64. package/dist/manifests/metric-card.manifest.json +1 -1
  65. package/dist/manifests/multi-select.manifest.json +1 -1
  66. package/dist/manifests/newsletter.manifest.json +1 -1
  67. package/dist/manifests/page-header.manifest.json +1 -1
  68. package/dist/manifests/pagination.manifest.json +1 -1
  69. package/dist/manifests/password-input.manifest.json +1 -1
  70. package/dist/manifests/popover.manifest.json +86 -4
  71. package/dist/manifests/process-steps.manifest.json +1 -1
  72. package/dist/manifests/progress.manifest.json +1 -1
  73. package/dist/manifests/prose.manifest.json +1 -1
  74. package/dist/manifests/radio.manifest.json +1 -1
  75. package/dist/manifests/range-slider.manifest.json +1 -1
  76. package/dist/manifests/search.manifest.json +1 -1
  77. package/dist/manifests/section-heading.manifest.json +1 -1
  78. package/dist/manifests/section.manifest.json +1 -1
  79. package/dist/manifests/segmented-control.manifest.json +1 -1
  80. package/dist/manifests/select-menu.manifest.json +1 -1
  81. package/dist/manifests/select.manifest.json +1 -1
  82. package/dist/manifests/separator.manifest.json +1 -1
  83. package/dist/manifests/site-footer.manifest.json +1 -1
  84. package/dist/manifests/site-header.manifest.json +13 -3
  85. package/dist/manifests/skeleton.manifest.json +1 -1
  86. package/dist/manifests/spinner.manifest.json +1 -1
  87. package/dist/manifests/stat-band.manifest.json +1 -1
  88. package/dist/manifests/stepper.manifest.json +7 -1
  89. package/dist/manifests/switch.manifest.json +1 -1
  90. package/dist/manifests/table-card.manifest.json +1 -1
  91. package/dist/manifests/table-of-contents.manifest.json +1 -1
  92. package/dist/manifests/table.manifest.json +1 -1
  93. package/dist/manifests/tabs.manifest.json +1 -1
  94. package/dist/manifests/testimonial.manifest.json +1 -1
  95. package/dist/manifests/text.manifest.json +1 -1
  96. package/dist/manifests/textarea.manifest.json +1 -1
  97. package/dist/manifests/theme-toggle.manifest.json +1 -1
  98. package/dist/manifests/time-picker.manifest.json +1 -1
  99. package/dist/manifests/timeline.manifest.json +1 -1
  100. package/dist/manifests/toast.manifest.json +1 -1
  101. package/dist/manifests/tombstone-card.manifest.json +1 -1
  102. package/dist/manifests/tooltip.manifest.json +1 -1
  103. package/dist/src/components/alert/Alert.js +1 -1
  104. package/dist/src/components/alert/Alert.js.map +1 -1
  105. package/dist/src/components/alert/Alert.mjs +1 -1
  106. package/dist/src/components/alert/Alert.mjs.map +1 -1
  107. package/dist/src/components/app-shell/AppShell.js +1 -1
  108. package/dist/src/components/app-shell/AppShell.js.map +1 -1
  109. package/dist/src/components/app-shell/AppShell.mjs +1 -1
  110. package/dist/src/components/app-shell/AppShell.mjs.map +1 -1
  111. package/dist/src/components/article-card/ArticleCard.js +2 -2
  112. package/dist/src/components/article-card/ArticleCard.js.map +1 -1
  113. package/dist/src/components/article-card/ArticleCard.mjs +2 -2
  114. package/dist/src/components/article-card/ArticleCard.mjs.map +1 -1
  115. package/dist/src/components/calendar/Calendar.d.ts +34 -0
  116. package/dist/src/components/calendar/Calendar.js +233 -0
  117. package/dist/src/components/calendar/Calendar.js.map +1 -0
  118. package/dist/src/components/calendar/Calendar.mjs +208 -0
  119. package/dist/src/components/calendar/Calendar.mjs.map +1 -0
  120. package/dist/src/components/calendar/index.d.ts +1 -0
  121. package/dist/src/components/calendar/index.js +23 -0
  122. package/dist/src/components/calendar/index.js.map +1 -0
  123. package/dist/src/components/calendar/index.mjs +2 -0
  124. package/dist/src/components/calendar/index.mjs.map +1 -0
  125. package/dist/src/components/comparison-table/ComparisonTable.js +1 -1
  126. package/dist/src/components/comparison-table/ComparisonTable.js.map +1 -1
  127. package/dist/src/components/comparison-table/ComparisonTable.mjs +1 -1
  128. package/dist/src/components/comparison-table/ComparisonTable.mjs.map +1 -1
  129. package/dist/src/components/cta-section/CTASection.js +1 -1
  130. package/dist/src/components/cta-section/CTASection.js.map +1 -1
  131. package/dist/src/components/cta-section/CTASection.mjs +1 -1
  132. package/dist/src/components/cta-section/CTASection.mjs.map +1 -1
  133. package/dist/src/components/data-table/DataTable.d.ts +3 -1
  134. package/dist/src/components/data-table/DataTable.js +2 -4
  135. package/dist/src/components/data-table/DataTable.js.map +1 -1
  136. package/dist/src/components/data-table/DataTable.mjs +2 -4
  137. package/dist/src/components/data-table/DataTable.mjs.map +1 -1
  138. package/dist/src/components/date-picker-popover/DatePickerPopover.d.ts +33 -0
  139. package/dist/src/components/date-picker-popover/DatePickerPopover.js +117 -0
  140. package/dist/src/components/date-picker-popover/DatePickerPopover.js.map +1 -0
  141. package/dist/src/components/date-picker-popover/DatePickerPopover.mjs +83 -0
  142. package/dist/src/components/date-picker-popover/DatePickerPopover.mjs.map +1 -0
  143. package/dist/src/components/date-picker-popover/index.d.ts +1 -0
  144. package/dist/src/components/date-picker-popover/index.js +23 -0
  145. package/dist/src/components/date-picker-popover/index.js.map +1 -0
  146. package/dist/src/components/date-picker-popover/index.mjs +2 -0
  147. package/dist/src/components/date-picker-popover/index.mjs.map +1 -0
  148. package/dist/src/components/image/Image.d.ts +34 -0
  149. package/dist/src/components/image/Image.js +75 -0
  150. package/dist/src/components/image/Image.js.map +1 -0
  151. package/dist/src/components/image/Image.mjs +41 -0
  152. package/dist/src/components/image/Image.mjs.map +1 -0
  153. package/dist/src/components/image/index.d.ts +1 -0
  154. package/dist/src/components/image/index.js +29 -0
  155. package/dist/src/components/image/index.js.map +1 -0
  156. package/dist/src/components/image/index.mjs +5 -0
  157. package/dist/src/components/image/index.mjs.map +1 -0
  158. package/dist/src/components/link/Link.js +4 -4
  159. package/dist/src/components/link/Link.js.map +1 -1
  160. package/dist/src/components/link/Link.mjs +4 -4
  161. package/dist/src/components/link/Link.mjs.map +1 -1
  162. package/dist/src/components/page-header/PageHeader.js +1 -1
  163. package/dist/src/components/page-header/PageHeader.js.map +1 -1
  164. package/dist/src/components/page-header/PageHeader.mjs +1 -1
  165. package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
  166. package/dist/src/components/popover/Popover.d.ts +36 -3
  167. package/dist/src/components/popover/Popover.js +118 -22
  168. package/dist/src/components/popover/Popover.js.map +1 -1
  169. package/dist/src/components/popover/Popover.mjs +117 -22
  170. package/dist/src/components/popover/Popover.mjs.map +1 -1
  171. package/dist/src/components/section-heading/SectionHeading.js +1 -1
  172. package/dist/src/components/section-heading/SectionHeading.js.map +1 -1
  173. package/dist/src/components/section-heading/SectionHeading.mjs +1 -1
  174. package/dist/src/components/section-heading/SectionHeading.mjs.map +1 -1
  175. package/dist/src/components/site-header/SiteHeader.d.ts +25 -3
  176. package/dist/src/components/site-header/SiteHeader.js +141 -6
  177. package/dist/src/components/site-header/SiteHeader.js.map +1 -1
  178. package/dist/src/components/site-header/SiteHeader.mjs +141 -6
  179. package/dist/src/components/site-header/SiteHeader.mjs.map +1 -1
  180. package/dist/src/components/stepper/Stepper.d.ts +18 -0
  181. package/dist/src/components/stepper/Stepper.js +2 -1
  182. package/dist/src/components/stepper/Stepper.js.map +1 -1
  183. package/dist/src/components/stepper/Stepper.mjs +2 -1
  184. package/dist/src/components/stepper/Stepper.mjs.map +1 -1
  185. package/dist/src/index.d.ts +3 -0
  186. package/dist/src/utils/date.d.ts +32 -0
  187. package/dist/src/utils/date.js +171 -0
  188. package/dist/src/utils/date.js.map +1 -0
  189. package/dist/src/utils/date.mjs +134 -0
  190. package/dist/src/utils/date.mjs.map +1 -0
  191. package/dist/src/utils/position.d.ts +42 -0
  192. package/dist/src/utils/position.js +91 -0
  193. package/dist/src/utils/position.js.map +1 -0
  194. package/dist/src/utils/position.mjs +67 -0
  195. package/dist/src/utils/position.mjs.map +1 -0
  196. package/dist/styles-full.css +1 -1
  197. package/dist/styles.css +1 -1
  198. package/package.json +1 -1
  199. package/src/components/alert/Alert.tsx +1 -1
  200. package/src/components/app-shell/AppShell.tsx +1 -1
  201. package/src/components/article-card/ArticleCard.tsx +2 -2
  202. package/src/components/calendar/Calendar.test.tsx +277 -0
  203. package/src/components/calendar/Calendar.tsx +273 -0
  204. package/src/components/calendar/index.ts +1 -0
  205. package/src/components/comparison-table/ComparisonTable.tsx +1 -1
  206. package/src/components/cta-section/CTASection.tsx +1 -1
  207. package/src/components/data-table/DataTable.test.tsx +21 -0
  208. package/src/components/data-table/DataTable.tsx +4 -1
  209. package/src/components/date-picker-popover/DatePickerPopover.test.tsx +223 -0
  210. package/src/components/date-picker-popover/DatePickerPopover.tsx +117 -0
  211. package/src/components/date-picker-popover/index.ts +1 -0
  212. package/src/components/image/Image.test.tsx +94 -0
  213. package/src/components/image/Image.tsx +71 -0
  214. package/src/components/image/index.ts +1 -0
  215. package/src/components/link/Link.test.tsx +2 -1
  216. package/src/components/link/Link.tsx +4 -4
  217. package/src/components/page-header/PageHeader.tsx +1 -1
  218. package/src/components/popover/Popover.test.tsx +307 -3
  219. package/src/components/popover/Popover.tsx +228 -91
  220. package/src/components/section-heading/SectionHeading.tsx +1 -1
  221. package/src/components/site-header/SiteHeader.test.tsx +103 -1
  222. package/src/components/site-header/SiteHeader.tsx +220 -16
  223. package/src/components/stepper/Stepper.test.tsx +12 -0
  224. package/src/components/stepper/Stepper.tsx +15 -1
  225. package/src/index.ts +3 -0
  226. package/src/manifests/accordion.manifest.json +2 -2
  227. package/src/manifests/alert.manifest.json +1 -1
  228. package/src/manifests/announcement-bar.manifest.json +1 -1
  229. package/src/manifests/app-shell.manifest.json +1 -1
  230. package/src/manifests/applied-filters.manifest.json +1 -1
  231. package/src/manifests/article-card.manifest.json +1 -1
  232. package/src/manifests/auth-layout.manifest.json +1 -1
  233. package/src/manifests/autocomplete.manifest.json +1 -1
  234. package/src/manifests/avatar.manifest.json +1 -1
  235. package/src/manifests/badge.manifest.json +1 -1
  236. package/src/manifests/block.manifest.json +1 -1
  237. package/src/manifests/bottom-nav.manifest.json +1 -1
  238. package/src/manifests/breadcrumb.manifest.json +1 -1
  239. package/src/manifests/button-group.manifest.json +1 -1
  240. package/src/manifests/button.manifest.json +1 -1
  241. package/src/manifests/calendar.manifest.json +175 -0
  242. package/src/manifests/card.manifest.json +1 -1
  243. package/src/manifests/checkbox.manifest.json +1 -1
  244. package/src/manifests/comparison-table.manifest.json +1 -1
  245. package/src/manifests/confirm-dialog.manifest.json +1 -1
  246. package/src/manifests/contact-strip.manifest.json +1 -1
  247. package/src/manifests/container.manifest.json +1 -1
  248. package/src/manifests/cta-section.manifest.json +1 -1
  249. package/src/manifests/data-table.manifest.json +8 -1
  250. package/src/manifests/date-picker-popover.manifest.json +202 -0
  251. package/src/manifests/date-picker.manifest.json +1 -1
  252. package/src/manifests/date-range-picker.manifest.json +1 -1
  253. package/src/manifests/deal-card.manifest.json +1 -1
  254. package/src/manifests/dialog.manifest.json +1 -1
  255. package/src/manifests/document-card.manifest.json +1 -1
  256. package/src/manifests/drawer.manifest.json +1 -1
  257. package/src/manifests/empty-state.manifest.json +1 -1
  258. package/src/manifests/entity-card.manifest.json +1 -1
  259. package/src/manifests/feature-grid.manifest.json +1 -1
  260. package/src/manifests/feature-row.manifest.json +1 -1
  261. package/src/manifests/fieldset.manifest.json +1 -1
  262. package/src/manifests/file-upload.manifest.json +1 -1
  263. package/src/manifests/filter-bar.manifest.json +1 -1
  264. package/src/manifests/filter-chips.manifest.json +1 -1
  265. package/src/manifests/filter-panel.manifest.json +1 -1
  266. package/src/manifests/flex.manifest.json +1 -1
  267. package/src/manifests/form-field.manifest.json +1 -1
  268. package/src/manifests/form-layout.manifest.json +1 -1
  269. package/src/manifests/form.manifest.json +1 -1
  270. package/src/manifests/grid.manifest.json +1 -1
  271. package/src/manifests/heading.manifest.json +1 -1
  272. package/src/manifests/hero.manifest.json +1 -1
  273. package/src/manifests/image.manifest.json +142 -0
  274. package/src/manifests/input-group.manifest.json +1 -1
  275. package/src/manifests/input.manifest.json +1 -1
  276. package/src/manifests/label.manifest.json +1 -1
  277. package/src/manifests/link-tabs.manifest.json +1 -1
  278. package/src/manifests/link.manifest.json +1 -1
  279. package/src/manifests/list.manifest.json +1 -1
  280. package/src/manifests/load-more.manifest.json +1 -1
  281. package/src/manifests/logo-cloud.manifest.json +1 -1
  282. package/src/manifests/menu.manifest.json +1 -1
  283. package/src/manifests/metric-card.manifest.json +1 -1
  284. package/src/manifests/multi-select.manifest.json +1 -1
  285. package/src/manifests/newsletter.manifest.json +1 -1
  286. package/src/manifests/page-header.manifest.json +1 -1
  287. package/src/manifests/pagination.manifest.json +1 -1
  288. package/src/manifests/password-input.manifest.json +1 -1
  289. package/src/manifests/popover.manifest.json +86 -4
  290. package/src/manifests/process-steps.manifest.json +1 -1
  291. package/src/manifests/progress.manifest.json +1 -1
  292. package/src/manifests/prose.manifest.json +1 -1
  293. package/src/manifests/radio.manifest.json +1 -1
  294. package/src/manifests/range-slider.manifest.json +1 -1
  295. package/src/manifests/search.manifest.json +1 -1
  296. package/src/manifests/section-heading.manifest.json +1 -1
  297. package/src/manifests/section.manifest.json +1 -1
  298. package/src/manifests/segmented-control.manifest.json +1 -1
  299. package/src/manifests/select-menu.manifest.json +1 -1
  300. package/src/manifests/select.manifest.json +1 -1
  301. package/src/manifests/separator.manifest.json +1 -1
  302. package/src/manifests/site-footer.manifest.json +1 -1
  303. package/src/manifests/site-header.manifest.json +13 -3
  304. package/src/manifests/skeleton.manifest.json +1 -1
  305. package/src/manifests/spinner.manifest.json +1 -1
  306. package/src/manifests/stat-band.manifest.json +1 -1
  307. package/src/manifests/stepper.manifest.json +7 -1
  308. package/src/manifests/switch.manifest.json +1 -1
  309. package/src/manifests/table-card.manifest.json +1 -1
  310. package/src/manifests/table-of-contents.manifest.json +1 -1
  311. package/src/manifests/table.manifest.json +1 -1
  312. package/src/manifests/tabs.manifest.json +1 -1
  313. package/src/manifests/testimonial.manifest.json +1 -1
  314. package/src/manifests/text.manifest.json +1 -1
  315. package/src/manifests/textarea.manifest.json +1 -1
  316. package/src/manifests/theme-toggle.manifest.json +1 -1
  317. package/src/manifests/time-picker.manifest.json +1 -1
  318. package/src/manifests/timeline.manifest.json +1 -1
  319. package/src/manifests/toast.manifest.json +1 -1
  320. package/src/manifests/tombstone-card.manifest.json +1 -1
  321. package/src/manifests/tooltip.manifest.json +1 -1
  322. package/src/utils/date.test.ts +190 -0
  323. package/src/utils/date.ts +162 -0
  324. package/src/utils/position.test.ts +227 -0
  325. package/src/utils/position.ts +129 -0
@@ -3,14 +3,19 @@
3
3
  import * as React from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { cn } from '../../utils/cn';
6
+ import { computePosition, type Align, type PositionResult, type Side } from '../../utils/position';
6
7
 
7
8
  type PopoverContextValue = {
8
9
  open: boolean;
9
10
  setOpen: (open: boolean) => void;
10
11
  triggerId: string;
11
12
  contentId: string;
12
- /** The relative wrapper the popover is anchored to (measured for portal positioning). */
13
+ /** The relative wrapper the popover is anchored to by default. */
13
14
  wrapperRef: React.MutableRefObject<HTMLDivElement | null>;
15
+ /** Optional explicit anchor, rendered by PopoverAnchor. */
16
+ anchorRef: React.MutableRefObject<HTMLElement | null>;
17
+ /** The rendered trigger, so Escape can restore focus and labels stay valid. */
18
+ triggerRef: React.MutableRefObject<HTMLButtonElement | null>;
14
19
  };
15
20
 
16
21
  const PopoverContext = React.createContext<PopoverContextValue>({
@@ -19,6 +24,8 @@ const PopoverContext = React.createContext<PopoverContextValue>({
19
24
  triggerId: '',
20
25
  contentId: '',
21
26
  wrapperRef: { current: null },
27
+ anchorRef: { current: null },
28
+ triggerRef: { current: null },
22
29
  });
23
30
 
24
31
  export type PopoverProps = {
@@ -42,6 +49,8 @@ const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
42
49
  const triggerId = React.useId();
43
50
  const contentId = React.useId();
44
51
  const wrapperRef = React.useRef<HTMLDivElement | null>(null);
52
+ const anchorRef = React.useRef<HTMLElement | null>(null);
53
+ const triggerRef = React.useRef<HTMLButtonElement | null>(null);
45
54
  const setRefs = React.useCallback(
46
55
  (node: HTMLDivElement | null) => {
47
56
  wrapperRef.current = node;
@@ -62,7 +71,7 @@ const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
62
71
  return (
63
72
  <div ref={setRefs} className={cn('relative inline-block', className)}>
64
73
  <PopoverContext.Provider
65
- value={{ open: current, setOpen, triggerId, contentId, wrapperRef }}
74
+ value={{ open: current, setOpen, triggerId, contentId, wrapperRef, anchorRef, triggerRef }}
66
75
  >
67
76
  {children}
68
77
  </PopoverContext.Provider>
@@ -76,12 +85,20 @@ export type PopoverTriggerProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
76
85
 
77
86
  /** The button that toggles the popover. */
78
87
  const PopoverTrigger = React.forwardRef<HTMLButtonElement, PopoverTriggerProps>(
79
- ({ className, children, onClick, ...props }, ref) => {
80
- const { open, setOpen, triggerId, contentId } = React.useContext(PopoverContext);
88
+ ({ className, children, onClick, id, ...props }, ref) => {
89
+ const { open, setOpen, triggerId, contentId, triggerRef } = React.useContext(PopoverContext);
90
+ const setRefs = React.useCallback(
91
+ (node: HTMLButtonElement | null) => {
92
+ triggerRef.current = node;
93
+ if (typeof ref === 'function') ref(node);
94
+ else if (ref) ref.current = node;
95
+ },
96
+ [ref, triggerRef]
97
+ );
81
98
  return (
82
99
  <button
83
- ref={ref}
84
- id={triggerId}
100
+ ref={setRefs}
101
+ id={id ?? triggerId}
85
102
  type="button"
86
103
  aria-haspopup="dialog"
87
104
  aria-expanded={open}
@@ -104,91 +121,211 @@ const PopoverTrigger = React.forwardRef<HTMLButtonElement, PopoverTriggerProps>(
104
121
  );
105
122
  PopoverTrigger.displayName = 'PopoverTrigger';
106
123
 
107
- export type PopoverContentProps = React.HTMLAttributes<HTMLDivElement>;
108
-
109
- /** The floating panel with interactive content. */
110
- const PopoverContent = React.forwardRef<HTMLDivElement, PopoverContentProps>(
111
- ({ className, children, onKeyDown, ...props }, ref) => {
112
- const { open, setOpen, triggerId, contentId, wrapperRef } =
113
- React.useContext(PopoverContext);
114
- const contentRef = React.useRef<HTMLDivElement | null>(null);
115
- // Viewport coordinates measured from the wrapper; the panel portals to
116
- // document.body with position:fixed so ancestor overflow (scrollable
117
- // demo frames, clipped containers) can never cut it off.
118
- const [pos, setPos] = React.useState<{ top: number; right: number } | null>(null);
119
-
120
- React.useLayoutEffect(() => {
121
- if (!open) {
122
- setPos(null);
123
- return;
124
- }
125
- const GAP = 8; // matches the previous mt-2 spacing
126
- const measure = () => {
127
- const rect = wrapperRef.current?.getBoundingClientRect();
128
- if (!rect) return;
129
- setPos({ top: rect.bottom + GAP, right: Math.max(8, window.innerWidth - rect.right) });
130
- };
131
- measure();
132
- const onScroll = () => setOpen(false);
133
- window.addEventListener('scroll', onScroll, true);
134
- window.addEventListener('resize', measure);
135
- return () => {
136
- window.removeEventListener('scroll', onScroll, true);
137
- window.removeEventListener('resize', measure);
138
- };
139
- }, [open, setOpen, wrapperRef]);
140
-
141
- // Close on outside click.
142
- React.useEffect(() => {
143
- if (!open) return;
144
- function onPointerDown(event: PointerEvent) {
145
- if (!contentRef.current?.contains(event.target as Node)) setOpen(false);
146
- }
147
- document.addEventListener('pointerdown', onPointerDown);
148
- return () => document.removeEventListener('pointerdown', onPointerDown);
149
- }, [open, setOpen]);
150
-
151
- // Focus the content when it opens so Escape reaches it. Depends on
152
- // `pos` because the panel only mounts once measured.
153
- React.useEffect(() => {
154
- if (open && pos && contentRef.current) {
155
- contentRef.current.focus();
156
- }
157
- }, [open, pos]);
158
-
159
- if (!open || !pos || typeof document === 'undefined') return null;
160
-
161
- return createPortal(
162
- <div
163
- ref={(node) => {
164
- contentRef.current = node;
165
- if (typeof ref === 'function') ref(node);
166
- else if (ref) ref.current = node;
167
- }}
168
- id={contentId}
169
- role="dialog"
170
- aria-labelledby={triggerId}
171
- tabIndex={-1}
172
- onKeyDown={(event) => {
173
- onKeyDown?.(event);
174
- if (event.key === 'Escape') {
175
- event.stopPropagation();
176
- setOpen(false);
177
- }
178
- }}
179
- style={{ position: 'fixed', top: pos.top, right: pos.right, zIndex: 50 }}
180
- className={cn(
181
- 'w-72 rounded-md border border-border bg-popover p-4 text-popover-foreground shadow-md outline-none',
182
- className
183
- )}
184
- {...props}
185
- >
186
- {children}
187
- </div>,
188
- document.body
124
+ export type PopoverAnchorProps = React.HTMLAttributes<HTMLSpanElement>;
125
+
126
+ /**
127
+ * Anchors the panel to this element instead of the trigger. Useful when the
128
+ * panel belongs to a field that is not itself the button opening it.
129
+ */
130
+ const PopoverAnchor = React.forwardRef<HTMLSpanElement, PopoverAnchorProps>(
131
+ ({ className, children, ...props }, ref) => {
132
+ const { anchorRef } = React.useContext(PopoverContext);
133
+ const setRefs = React.useCallback(
134
+ (node: HTMLSpanElement | null) => {
135
+ anchorRef.current = node;
136
+ if (typeof ref === 'function') ref(node);
137
+ else if (ref) ref.current = node;
138
+ },
139
+ [anchorRef, ref]
140
+ );
141
+ return (
142
+ <span ref={setRefs} className={cn('inline-block', className)} {...props}>
143
+ {children}
144
+ </span>
145
+ );
146
+ }
147
+ );
148
+ PopoverAnchor.displayName = 'PopoverAnchor';
149
+
150
+ export type PopoverContentProps = React.HTMLAttributes<HTMLDivElement> & {
151
+ /** Preferred side of the anchor. Flips when it cannot fit. */
152
+ side?: Side;
153
+ /** Cross-axis alignment against the anchor. */
154
+ align?: Align;
155
+ /** Gap between anchor and panel. */
156
+ sideOffset?: number;
157
+ /** Nudge along the cross axis. */
158
+ alignOffset?: number;
159
+ /** Minimum distance kept from the viewport edges. */
160
+ collisionPadding?: number;
161
+ /** Match the panel width to the anchor width (select-like panels). */
162
+ matchTriggerWidth?: boolean;
163
+ };
164
+
165
+ function rectOf(element: Element) {
166
+ const rect = element.getBoundingClientRect();
167
+ return {
168
+ top: rect.top,
169
+ left: rect.left,
170
+ width: rect.width || (element as HTMLElement).offsetWidth || 0,
171
+ height: rect.height || (element as HTMLElement).offsetHeight || 0,
172
+ };
173
+ }
174
+
175
+ /** The floating panel with interactive content. */
176
+ const PopoverContent = React.forwardRef<HTMLDivElement, PopoverContentProps>(
177
+ (
178
+ {
179
+ className,
180
+ children,
181
+ onKeyDown,
182
+ style,
183
+ side = 'bottom',
184
+ align = 'start',
185
+ sideOffset = 8,
186
+ alignOffset = 0,
187
+ collisionPadding = 8,
188
+ matchTriggerWidth = false,
189
+ ...props
190
+ },
191
+ ref
192
+ ) => {
193
+ const { open, setOpen, contentId, wrapperRef, anchorRef, triggerRef } =
194
+ React.useContext(PopoverContext);
195
+ // The trigger may carry a consumer `id`; read the rendered element so the
196
+ // dialog's label always points at something that exists.
197
+ const labelledBy = triggerRef.current?.id || undefined;
198
+ const contentRef = React.useRef<HTMLDivElement | null>(null);
199
+ // Viewport coordinates measured from the anchor; the panel portals to
200
+ // document.body with position:fixed so ancestor overflow can never clip it.
201
+ const [pos, setPos] = React.useState<PositionResult | null>(null);
202
+ const [width, setWidth] = React.useState<number | undefined>(undefined);
203
+
204
+ const updatePosition = React.useCallback(() => {
205
+ const anchorEl = anchorRef.current ?? wrapperRef.current;
206
+ const panel = contentRef.current;
207
+ if (!anchorEl || !panel) return;
208
+ const anchor = rectOf(anchorEl);
209
+ const measured = rectOf(panel);
210
+ setWidth(matchTriggerWidth ? anchor.width : undefined);
211
+ setPos(
212
+ computePosition({
213
+ anchor,
214
+ content: { width: measured.width, height: measured.height },
215
+ viewport: { width: window.innerWidth, height: window.innerHeight },
216
+ side,
217
+ align,
218
+ sideOffset,
219
+ alignOffset,
220
+ collisionPadding,
221
+ })
189
222
  );
190
- }
191
- );
223
+ }, [
224
+ align,
225
+ alignOffset,
226
+ anchorRef,
227
+ collisionPadding,
228
+ matchTriggerWidth,
229
+ side,
230
+ sideOffset,
231
+ wrapperRef,
232
+ ]);
233
+
234
+ React.useLayoutEffect(() => {
235
+ if (!open) {
236
+ setPos(null);
237
+ return;
238
+ }
239
+ updatePosition();
240
+ }, [open, updatePosition]);
241
+
242
+ // A panel that is already open on first mount measures before the wrapper's
243
+ // ref is attached (child layout effects run first), so measure once more
244
+ // when the refs exist.
245
+ React.useEffect(() => {
246
+ if (open && !pos) updatePosition();
247
+ }, [open, pos, updatePosition]);
248
+
249
+ // Keep the panel anchored while the page moves: reposition on scroll and
250
+ // resize, and re-measure when the content itself changes size.
251
+ React.useEffect(() => {
252
+ if (!open) return;
253
+ const onScroll = () => updatePosition();
254
+ window.addEventListener('scroll', onScroll, true);
255
+ window.addEventListener('resize', onScroll);
256
+ const panel = contentRef.current;
257
+ const observer =
258
+ typeof ResizeObserver === 'undefined' || !panel ? null : new ResizeObserver(onScroll);
259
+ if (panel && observer) observer.observe(panel);
260
+ return () => {
261
+ window.removeEventListener('scroll', onScroll, true);
262
+ window.removeEventListener('resize', onScroll);
263
+ observer?.disconnect();
264
+ };
265
+ }, [open, updatePosition]);
266
+
267
+ // Close on outside click.
268
+ React.useEffect(() => {
269
+ if (!open) return;
270
+ function onPointerDown(event: PointerEvent) {
271
+ if (!contentRef.current?.contains(event.target as Node)) setOpen(false);
272
+ }
273
+ document.addEventListener('pointerdown', onPointerDown);
274
+ return () => document.removeEventListener('pointerdown', onPointerDown);
275
+ }, [open, setOpen]);
276
+
277
+ // Focus the content when it opens so Escape reaches it. Depends on `pos`
278
+ // because the panel only mounts once measured.
279
+ React.useEffect(() => {
280
+ if (open && pos && contentRef.current) {
281
+ contentRef.current.focus();
282
+ }
283
+ }, [open, pos]);
284
+
285
+ if (!open || typeof document === 'undefined') return null;
286
+
287
+ return createPortal(
288
+ <div
289
+ ref={(node) => {
290
+ contentRef.current = node;
291
+ if (typeof ref === 'function') ref(node);
292
+ else if (ref) ref.current = node;
293
+ }}
294
+ id={contentId}
295
+ role="dialog"
296
+ aria-labelledby={labelledBy}
297
+ tabIndex={-1}
298
+ data-side={pos?.side ?? side}
299
+ onKeyDown={(event) => {
300
+ onKeyDown?.(event);
301
+ if (event.key === 'Escape') {
302
+ event.stopPropagation();
303
+ setOpen(false);
304
+ // Escape must hand focus back, or it lands on <body>.
305
+ (triggerRef.current ?? anchorRef.current)?.focus();
306
+ }
307
+ }}
308
+ style={{
309
+ position: 'fixed',
310
+ top: pos?.top ?? 0,
311
+ left: pos?.left ?? 0,
312
+ width,
313
+ visibility: pos ? 'visible' : 'hidden',
314
+ zIndex: 50,
315
+ ...style,
316
+ }}
317
+ className={cn(
318
+ 'w-72 rounded-md border border-border bg-popover p-4 text-popover-foreground shadow-md outline-none',
319
+ className
320
+ )}
321
+ {...props}
322
+ >
323
+ {children}
324
+ </div>,
325
+ document.body
326
+ );
327
+ }
328
+ );
192
329
  PopoverContent.displayName = 'PopoverContent';
193
330
 
194
- export { Popover, PopoverTrigger, PopoverContent };
331
+ export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger };
@@ -48,7 +48,7 @@ export const SectionHeading = React.forwardRef<HTMLDivElement, SectionHeadingPro
48
48
  {...props}
49
49
  >
50
50
  <div className={cn('min-w-0', align === 'center' && 'flex flex-col items-center')}>
51
- {eyebrow && <div className={cn('mb-1 text-xs font-medium uppercase tracking-wide text-primary', eyebrowClassName)}>{eyebrow}</div>}
51
+ {eyebrow && <div className={cn('mb-1 text-xs font-medium uppercase tracking-wide text-primary-ink', eyebrowClassName)}>{eyebrow}</div>}
52
52
  <Heading className={cn('font-semibold tracking-tight', sizeClasses[size], titleClassName)}>{title}</Heading>
53
53
  {description && (
54
54
  <p className={cn('mt-2 max-w-2xl text-muted-foreground', align === 'center' ? 'mx-auto' : '', descriptionClassName)}>{description}</p>
@@ -2,7 +2,7 @@ import { render, screen, within } from '@testing-library/react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import { axe } from 'jest-axe';
4
4
  import { describe, expect, it } from 'vitest';
5
- import { SiteHeader } from './SiteHeader';
5
+ import { SiteHeader, type SiteNavItem } from './SiteHeader';
6
6
 
7
7
  const items = [
8
8
  { href: '/docs', label: 'Docs' },
@@ -84,3 +84,105 @@ describe('SiteHeader', () => {
84
84
  expect(await axe(container)).toHaveNoViolations();
85
85
  });
86
86
  });
87
+
88
+ const megaItems: SiteNavItem[] = [
89
+ {
90
+ label: 'Dancers',
91
+ columns: [
92
+ {
93
+ heading: 'Plan',
94
+ items: [
95
+ { href: '/events', label: 'All events', description: 'Every genre in Utah' },
96
+ { href: '/deadlines', label: 'Deadlines' },
97
+ ],
98
+ },
99
+ {
100
+ heading: 'Follow',
101
+ items: [{ href: '/brief', label: 'Deadline Brief' }],
102
+ },
103
+ ],
104
+ },
105
+ { href: '/directory', label: 'Directory' },
106
+ ];
107
+
108
+ describe('SiteHeader mega menu', () => {
109
+ it('renders a disclosure trigger instead of a link for nested items', () => {
110
+ render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
111
+ const trigger = screen.getByRole('button', { name: /Dancers/ });
112
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
113
+ expect(screen.getByRole('link', { name: 'Directory' })).toBeInTheDocument();
114
+ });
115
+
116
+ it('opens on hover and exposes the panel links', async () => {
117
+ const user = userEvent.setup();
118
+ render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
119
+ await user.hover(screen.getByRole('button', { name: /Dancers/ }));
120
+ expect(screen.getByRole('button', { name: /Dancers/ })).toHaveAttribute(
121
+ 'aria-expanded',
122
+ 'true'
123
+ );
124
+ expect(screen.getByRole('link', { name: /All events/ })).toBeInTheDocument();
125
+ expect(screen.getByText('Plan')).toBeInTheDocument();
126
+ expect(screen.getByText('Every genre in Utah')).toBeInTheDocument();
127
+ });
128
+
129
+ it('closes on Escape and on an outside pointer', async () => {
130
+ const user = userEvent.setup();
131
+ render(
132
+ <div>
133
+ <SiteHeader brand={<span>Acme</span>} items={megaItems} />
134
+ <button type="button">Outside</button>
135
+ </div>
136
+ );
137
+ const trigger = screen.getByRole('button', { name: /Dancers/ });
138
+ await user.click(trigger);
139
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
140
+ await user.keyboard('{Escape}');
141
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
142
+ await user.click(trigger);
143
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
144
+ await user.click(screen.getByRole('button', { name: 'Outside' }));
145
+ expect(screen.getByRole('button', { name: /Dancers/ })).toHaveAttribute(
146
+ 'aria-expanded',
147
+ 'false'
148
+ );
149
+ });
150
+
151
+ it('moves focus into the panel with ArrowDown', async () => {
152
+ const user = userEvent.setup();
153
+ render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
154
+ const trigger = screen.getByRole('button', { name: /Dancers/ });
155
+ trigger.focus();
156
+ await user.keyboard('{ArrowDown}');
157
+ expect(screen.getByRole('link', { name: /All events/ })).toHaveFocus();
158
+ });
159
+
160
+ it('keeps the panel open while tabbing through its links', async () => {
161
+ const user = userEvent.setup();
162
+ render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
163
+ const trigger = screen.getByRole('button', { name: /Dancers/ });
164
+ trigger.focus();
165
+ await user.keyboard('{ArrowDown}');
166
+ await user.tab();
167
+ expect(screen.getByRole('link', { name: /Deadlines/ })).toHaveFocus();
168
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
169
+ });
170
+
171
+ it('renders nested groups in the mobile drawer', async () => {
172
+ const user = userEvent.setup();
173
+ render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
174
+ await user.click(screen.getByRole('button', { name: 'Open menu' }));
175
+ const drawer = screen.getByRole('dialog', { name: 'Menu' });
176
+ expect(within(drawer).getByText('Dancers')).toBeInTheDocument();
177
+ expect(within(drawer).getByRole('link', { name: /All events/ })).toBeInTheDocument();
178
+ });
179
+
180
+ it('has no accessibility violations with a panel open', async () => {
181
+ const user = userEvent.setup();
182
+ const { container } = render(
183
+ <SiteHeader brand={<span>Acme</span>} items={megaItems} activeHref="/events" />
184
+ );
185
+ await user.hover(screen.getByRole('button', { name: /Dancers/ }));
186
+ expect(await axe(container)).toHaveNoViolations();
187
+ });
188
+ });