oneslash-design-system 2.18.0 → 2.20.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 (227) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +54 -5
  3. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  4. package/dist/cases/app-shell/sidebar.jsx +124 -0
  5. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  6. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  7. package/dist/cases/app-shell.md +364 -0
  8. package/dist/cases/artifact-card/card.jsx +32 -6
  9. package/dist/cases/artifact-card.md +55 -7
  10. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  11. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  12. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  13. package/dist/cases/billing-page/self-serve.jsx +134 -0
  14. package/dist/cases/billing-page.md +247 -0
  15. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  16. package/dist/cases/breakdown-list/bars.jsx +47 -0
  17. package/dist/cases/breakdown-list/table.d.ts +1 -0
  18. package/dist/cases/breakdown-list/table.jsx +69 -0
  19. package/dist/cases/breakdown-list.md +158 -0
  20. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  21. package/dist/cases/composer-limit/notice.jsx +3 -3
  22. package/dist/cases/composer-limit.md +8 -8
  23. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  24. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  25. package/dist/cases/dashboard/work-first.d.ts +1 -0
  26. package/dist/cases/dashboard/work-first.jsx +165 -0
  27. package/dist/cases/dashboard.md +507 -0
  28. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  29. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  30. package/dist/cases/data-table-page/paged.d.ts +1 -0
  31. package/dist/cases/data-table-page/paged.jsx +284 -0
  32. package/dist/cases/data-table-page.md +771 -0
  33. package/dist/cases/error-page/in-shell.jsx +26 -17
  34. package/dist/cases/error-page.md +42 -21
  35. package/dist/cases/invoice-list/table.d.ts +1 -0
  36. package/dist/cases/invoice-list/table.jsx +64 -0
  37. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  38. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  39. package/dist/cases/invoice-list.md +237 -0
  40. package/dist/cases/load-failure/inline.jsx +2 -2
  41. package/dist/cases/load-failure.md +2 -2
  42. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  43. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  44. package/dist/cases/master-detail/split.d.ts +1 -0
  45. package/dist/cases/master-detail/split.jsx +49 -0
  46. package/dist/cases/master-detail.md +213 -0
  47. package/dist/cases/members-list/rows.jsx +2 -1
  48. package/dist/cases/members-list/table.jsx +8 -9
  49. package/dist/cases/members-list.md +12 -13
  50. package/dist/cases/mobile-menu/links.d.ts +1 -0
  51. package/dist/cases/mobile-menu/links.jsx +24 -0
  52. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  53. package/dist/cases/mobile-menu/sections.jsx +61 -0
  54. package/dist/cases/mobile-menu.md +170 -0
  55. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  56. package/dist/cases/not-found-page.md +41 -20
  57. package/dist/cases/number-format.md +36 -0
  58. package/dist/cases/on-this-page/aside.d.ts +1 -0
  59. package/dist/cases/on-this-page/aside.jsx +39 -0
  60. package/dist/cases/on-this-page.md +80 -0
  61. package/dist/cases/page-header/actions.d.ts +1 -0
  62. package/dist/cases/page-header/actions.jsx +65 -0
  63. package/dist/cases/page-header/sub-page.d.ts +1 -0
  64. package/dist/cases/page-header/sub-page.jsx +37 -0
  65. package/dist/cases/page-header.md +195 -0
  66. package/dist/cases/paged-card/pager.d.ts +1 -0
  67. package/dist/cases/paged-card/pager.jsx +41 -0
  68. package/dist/cases/paged-card/see-all.d.ts +1 -0
  69. package/dist/cases/paged-card/see-all.jsx +34 -0
  70. package/dist/cases/paged-card.md +147 -0
  71. package/dist/cases/payment-method/none.d.ts +1 -0
  72. package/dist/cases/payment-method/none.jsx +17 -0
  73. package/dist/cases/payment-method/on-file.d.ts +1 -0
  74. package/dist/cases/payment-method/on-file.jsx +92 -0
  75. package/dist/cases/payment-method.md +182 -0
  76. package/dist/cases/phone-navigation.md +32 -0
  77. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  78. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  79. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  80. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  81. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  82. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  83. package/dist/cases/plan-change-confirm.md +261 -0
  84. package/dist/cases/plan-picker/cards.d.ts +1 -0
  85. package/dist/cases/plan-picker/cards.jsx +97 -0
  86. package/dist/cases/plan-picker/list.d.ts +1 -0
  87. package/dist/cases/plan-picker/list.jsx +103 -0
  88. package/dist/cases/plan-picker.md +297 -0
  89. package/dist/cases/range-switch/segmented.jsx +11 -7
  90. package/dist/cases/range-switch.md +16 -11
  91. package/dist/cases/route-loading/region.jsx +27 -18
  92. package/dist/cases/route-loading.md +42 -21
  93. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  94. package/dist/cases/settings-page.md +5 -4
  95. package/dist/cases/side-pane/beside.d.ts +1 -0
  96. package/dist/cases/side-pane/beside.jsx +79 -0
  97. package/dist/cases/side-pane/over.d.ts +1 -0
  98. package/dist/cases/side-pane/over.jsx +58 -0
  99. package/dist/cases/side-pane.md +238 -0
  100. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  101. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  102. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  103. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  104. package/dist/cases/sidebar-nav.md +261 -0
  105. package/dist/cases/site-footer/columns.d.ts +1 -0
  106. package/dist/cases/site-footer/columns.jsx +51 -0
  107. package/dist/cases/site-footer/simple.d.ts +1 -0
  108. package/dist/cases/site-footer/simple.jsx +24 -0
  109. package/dist/cases/site-footer.md +133 -0
  110. package/dist/cases/site-header/links.d.ts +1 -0
  111. package/dist/cases/site-header/links.jsx +26 -0
  112. package/dist/cases/site-header/sections.d.ts +1 -0
  113. package/dist/cases/site-header/sections.jsx +64 -0
  114. package/dist/cases/site-header.md +183 -0
  115. package/dist/cases/stat-row/featured.d.ts +1 -0
  116. package/dist/cases/stat-row/featured.jsx +17 -0
  117. package/dist/cases/stat-row/tiles.d.ts +1 -0
  118. package/dist/cases/stat-row/tiles.jsx +34 -0
  119. package/dist/cases/stat-row.md +104 -0
  120. package/dist/cases/status-label/dot.d.ts +1 -0
  121. package/dist/cases/status-label/dot.jsx +39 -0
  122. package/dist/cases/status-label/text.d.ts +1 -0
  123. package/dist/cases/status-label/text.jsx +44 -0
  124. package/dist/cases/status-label.md +143 -0
  125. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  126. package/dist/cases/theme-switcher/menu.jsx +47 -0
  127. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  128. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  129. package/dist/cases/theme-switcher.md +149 -0
  130. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  131. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  132. package/dist/cases/upgrade-prompt.md +10 -6
  133. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  134. package/dist/cases/usage-meters/by-person.jsx +72 -0
  135. package/dist/cases/usage-meters/meters.d.ts +1 -0
  136. package/dist/cases/usage-meters/meters.jsx +49 -0
  137. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  138. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  139. package/dist/cases/usage-meters.md +303 -0
  140. package/dist/cases.json +1756 -172
  141. package/dist/components/appShell.d.ts +44 -0
  142. package/dist/components/appShell.jsx +121 -0
  143. package/dist/components/button.d.ts +1 -1
  144. package/dist/components/button.jsx +11 -5
  145. package/dist/components/drawer.d.ts +31 -0
  146. package/dist/components/drawer.jsx +121 -0
  147. package/dist/components/formatNumber.d.ts +25 -0
  148. package/dist/components/formatNumber.js +125 -0
  149. package/dist/components/heading.d.ts +3 -1
  150. package/dist/components/heading.jsx +2 -2
  151. package/dist/components/iconButton.jsx +12 -7
  152. package/dist/components/link.d.ts +6 -1
  153. package/dist/components/link.jsx +11 -3
  154. package/dist/components/menuItem.d.ts +7 -1
  155. package/dist/components/menuItem.jsx +4 -3
  156. package/dist/components/modal.jsx +12 -23
  157. package/dist/components/onThisPage.d.ts +29 -0
  158. package/dist/components/onThisPage.jsx +151 -0
  159. package/dist/components/pageShell.d.ts +7 -1
  160. package/dist/components/pageShell.jsx +14 -1
  161. package/dist/components/pagination.d.ts +28 -0
  162. package/dist/components/pagination.jsx +89 -0
  163. package/dist/components/popover.jsx +4 -0
  164. package/dist/components/progress.d.ts +33 -0
  165. package/dist/components/progress.jsx +50 -0
  166. package/dist/components/settingsSection.d.ts +6 -1
  167. package/dist/components/settingsSection.jsx +10 -3
  168. package/dist/components/sidePane.d.ts +32 -0
  169. package/dist/components/sidePane.jsx +128 -0
  170. package/dist/components/siteFooter.d.ts +24 -0
  171. package/dist/components/siteFooter.jsx +48 -0
  172. package/dist/components/siteHeader.d.ts +55 -0
  173. package/dist/components/siteHeader.jsx +125 -0
  174. package/dist/components/skeleton.d.ts +21 -0
  175. package/dist/components/skeleton.jsx +41 -0
  176. package/dist/components/statTile.d.ts +32 -0
  177. package/dist/components/statTile.jsx +61 -0
  178. package/dist/components/tableContainer.d.ts +5 -1
  179. package/dist/components/tableContainer.jsx +9 -1
  180. package/dist/components/tableHeaderCell.d.ts +3 -1
  181. package/dist/components/tableHeaderCell.jsx +2 -2
  182. package/dist/components/titleBar.d.ts +19 -0
  183. package/dist/components/titleBar.jsx +18 -0
  184. package/dist/index.d.ts +12 -0
  185. package/dist/index.js +12 -0
  186. package/dist/internal/overlayStack.d.ts +24 -0
  187. package/dist/internal/overlayStack.js +71 -0
  188. package/dist/internal/resize.d.ts +9 -0
  189. package/dist/internal/resize.js +31 -0
  190. package/dist/internal/scrollSpy.d.ts +24 -0
  191. package/dist/internal/scrollSpy.js +53 -0
  192. package/dist/internal/siteBrand.d.ts +6 -0
  193. package/dist/internal/siteBrand.jsx +11 -0
  194. package/dist/native-mapping.json +69 -3
  195. package/dist/stories/AppShell.stories.d.ts +15 -0
  196. package/dist/stories/AppShell.stories.jsx +137 -0
  197. package/dist/stories/Button.stories.d.ts +1 -0
  198. package/dist/stories/Button.stories.jsx +19 -1
  199. package/dist/stories/Cases.generated.stories.d.ts +45 -0
  200. package/dist/stories/Cases.generated.stories.jsx +90 -0
  201. package/dist/stories/Drawer.stories.d.ts +10 -0
  202. package/dist/stories/Drawer.stories.jsx +123 -0
  203. package/dist/stories/Link.stories.d.ts +1 -0
  204. package/dist/stories/Link.stories.jsx +8 -0
  205. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  206. package/dist/stories/OnThisPage.stories.jsx +105 -0
  207. package/dist/stories/Pagination.stories.d.ts +9 -0
  208. package/dist/stories/Pagination.stories.jsx +75 -0
  209. package/dist/stories/Progress.stories.d.ts +9 -0
  210. package/dist/stories/Progress.stories.jsx +43 -0
  211. package/dist/stories/SettingsSection.stories.d.ts +1 -0
  212. package/dist/stories/SettingsSection.stories.jsx +27 -0
  213. package/dist/stories/SidePane.stories.d.ts +6 -0
  214. package/dist/stories/SidePane.stories.jsx +37 -0
  215. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  216. package/dist/stories/SiteFooter.stories.jsx +63 -0
  217. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  218. package/dist/stories/SiteHeader.stories.jsx +94 -0
  219. package/dist/stories/Skeleton.stories.d.ts +7 -0
  220. package/dist/stories/Skeleton.stories.jsx +27 -0
  221. package/dist/stories/StatTile.stories.d.ts +10 -0
  222. package/dist/stories/StatTile.stories.jsx +55 -0
  223. package/dist/stories/Table.stories.d.ts +1 -0
  224. package/dist/stories/Table.stories.jsx +49 -1
  225. package/dist/stories/TitleBar.stories.d.ts +7 -0
  226. package/dist/stories/TitleBar.stories.jsx +41 -0
  227. package/package.json +5 -1
@@ -12,9 +12,10 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  import React from 'react';
14
14
  import NextLink from 'next/link';
15
+ import { ExternalLink } from 'lucide-react';
15
16
  import { focusRing } from './sharedStyles';
16
17
  export default function Link(_a) {
17
- var href = _a.href, children = _a.children, _b = _a.color, color = _b === void 0 ? 'info' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.openInNewTab, openInNewTab = _d === void 0 ? false : _d, _e = _a.className, className = _e === void 0 ? '' : _e;
18
+ var href = _a.href, children = _a.children, _b = _a.color, color = _b === void 0 ? 'info' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.openInNewTab, openInNewTab = _d === void 0 ? false : _d, _e = _a.announceNewTab, announceNewTab = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? '' : _f;
18
19
  // Color classes based on the color prop
19
20
  // Light mode uses the -dark shade so link text keeps 4.5:1 on light backgrounds
20
21
  var colorClasses = {
@@ -63,13 +64,20 @@ export default function Link(_a) {
63
64
  target: '_blank',
64
65
  rel: 'noopener noreferrer',
65
66
  }));
67
+ var content = (<>
68
+ {children}
69
+ {announceNewTab && shouldOpenInNewTab && (<>
70
+ <ExternalLink aria-hidden="true" className="ml-1 inline size-[1em] align-[-0.125em]"/>
71
+ <span className="sr-only"> (opens in a new tab)</span>
72
+ </>)}
73
+ </>);
66
74
  // Use NextLink for internal links, regular <a> for external
67
75
  if (isExternal || shouldOpenInNewTab) {
68
76
  return (<a href={href} {...commonProps}>
69
- {children}
77
+ {announceNewTab ? content : children}
70
78
  </a>);
71
79
  }
72
80
  return (<NextLink href={href} {...commonProps}>
73
- {children}
81
+ {announceNewTab ? content : children}
74
82
  </NextLink>);
75
83
  }
@@ -36,6 +36,12 @@ interface MenuItemProps {
36
36
  color?: 'default' | 'danger';
37
37
  /** Marks the current page in a side nav so a screen reader announces it. On a link it goes on the `<a>`, otherwise on the row. */
38
38
  'aria-current'?: 'page' | boolean;
39
+ /** The row's name when the label and tag alone do not say it, e.g. a count: 'Inbox, 3 unread'. On a link it goes on the `<a>`. */
40
+ 'aria-label'?: string;
41
+ /** For a row that shows or hides others (a group of places): whether they are shown. Use with `role="button"`. On a link it goes on the `<a>`. */
42
+ 'aria-expanded'?: boolean;
43
+ /** `2` indents the row one step, for a place inside another place. Default 1. */
44
+ level?: 1 | 2;
39
45
  }
40
- export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, 'aria-current': ariaCurrent, }: MenuItemProps): React.JSX.Element;
46
+ export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, 'aria-current': ariaCurrent, 'aria-label': ariaLabel, 'aria-expanded': ariaExpanded, level, }: MenuItemProps): React.JSX.Element;
41
47
  export {};
@@ -7,7 +7,7 @@ import Tag from './tag';
7
7
  import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
8
8
  export default function MenuItem(_a) {
9
9
  var _b;
10
- var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h, ariaCurrent = _a["aria-current"];
10
+ var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h, ariaCurrent = _a["aria-current"], ariaLabel = _a["aria-label"], ariaExpanded = _a["aria-expanded"], _j = _a.level, level = _j === void 0 ? 1 : _j;
11
11
  // Size-based icon and text classes
12
12
  var iconSize = { tiny: 'w-4 h-4', small: 'w-5 h-5', medium: 'w-6 h-6' }[size];
13
13
  var labelClass = { tiny: 'text-caption', small: 'text-body2', medium: 'text-body1' }[size];
@@ -18,7 +18,7 @@ export default function MenuItem(_a) {
18
18
  var danger = color === 'danger' && !isSelected;
19
19
  var content = (<div id={id} role={href ? undefined : role}
20
20
  // A link wrapper is already focusable; otherwise the row itself takes focus
21
- tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
21
+ tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} aria-label={href ? undefined : ariaLabel} aria-expanded={href ? undefined : ariaExpanded} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
22
22
  ? 'bg-primary-dark text-primary-contrast'
23
23
  : "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
24
24
  if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
@@ -50,5 +50,6 @@ export default function MenuItem(_a) {
50
50
  </div>)}
51
51
  </div>
52
52
  </div>);
53
- return href ? <NextLink href={href} aria-current={ariaCurrent} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
53
+ var row = href ? <NextLink href={href} aria-label={ariaLabel} aria-current={ariaCurrent} aria-expanded={ariaExpanded} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
54
+ return level === 2 ? <div className="pl-6">{row}</div> : row;
54
55
  }
@@ -3,9 +3,7 @@ import React, { useEffect, useId, useRef } from 'react';
3
3
  import { overlayHidden, overlayTransition, overlayVisible } from './sharedStyles';
4
4
  import { useOverlayTransition } from './useOverlayTransition';
5
5
  import { initialFocusCandidates } from '../internal/modal';
6
- var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
7
- // For the first focus and the Tab trap: the same, minus a hidden input, which matches but cannot take focus
8
- var PICKABLE = FOCUSABLE.replace('input:not([disabled])', 'input:not([disabled]):not([type="hidden"])');
6
+ import { PICKABLE, claimEvent, isTopOverlay, lockScroll, popOverlay, pushOverlay, trapTab, unlockScroll } from '../internal/overlayStack';
9
7
  export default function Modal(_a) {
10
8
  var isOpen = _a.isOpen, title = _a.title, secondTitle = _a.secondTitle, children = _a.children, onClose = _a.onClose, actions = _a.actions, _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.initialFocus, initialFocus = _c === void 0 ? 'first' : _c;
11
9
  var panelRef = useRef(null);
@@ -16,7 +14,8 @@ export default function Modal(_a) {
16
14
  var onCloseRef = useRef(onClose);
17
15
  onCloseRef.current = onClose;
18
16
  // Move focus into the panel, trap Tab inside it, close on Escape,
19
- // lock page scroll, and give focus back to the trigger on close
17
+ // lock page scroll, and give focus back to the trigger on close.
18
+ // Escape and Tab act only while this Modal is the top overlay (see internal/overlayStack).
20
19
  useEffect(function () {
21
20
  var _a, _b, _c;
22
21
  // Wait for the panel to mount before moving focus into it
@@ -34,36 +33,26 @@ export default function Modal(_a) {
34
33
  }
35
34
  if (panel && !panel.contains(document.activeElement))
36
35
  panel.focus();
37
- var previousOverflow = document.body.style.overflow;
38
- document.body.style.overflow = 'hidden';
36
+ pushOverlay(titleId, panel);
37
+ lockScroll();
39
38
  var handleKeyDown = function (e) {
39
+ if (!isTopOverlay(titleId))
40
+ return;
40
41
  if (e.key === 'Escape') {
41
- onCloseRef.current();
42
+ if (claimEvent(e))
43
+ onCloseRef.current();
42
44
  return;
43
45
  }
44
46
  if (e.key !== 'Tab' || !panel)
45
47
  return;
46
- var focusable = Array.from(panel.querySelectorAll(PICKABLE));
47
- if (focusable.length === 0) {
48
- e.preventDefault();
49
- return;
50
- }
51
- var first = focusable[0];
52
- var last = focusable[focusable.length - 1];
53
- if (e.shiftKey && document.activeElement === first) {
54
- e.preventDefault();
55
- last.focus();
56
- }
57
- else if (!e.shiftKey && document.activeElement === last) {
58
- e.preventDefault();
59
- first.focus();
60
- }
48
+ trapTab(panel, e);
61
49
  };
62
50
  window.addEventListener('keydown', handleKeyDown);
63
51
  return function () {
64
52
  var _a;
65
53
  window.removeEventListener('keydown', handleKeyDown);
66
- document.body.style.overflow = previousOverflow;
54
+ popOverlay(titleId);
55
+ unlockScroll();
67
56
  (_a = previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocused);
68
57
  };
69
58
  }, [isOpen, mounted]);
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ export interface OnThisPageItem {
3
+ /** The id of the heading on the page; the link goes to `#id` */
4
+ id: string;
5
+ label: string;
6
+ /** 3 is indented under the 2 above it. Default 2. */
7
+ level?: 2 | 3;
8
+ }
9
+ interface OnThisPageProps {
10
+ /** The page's headings, in page order. Fewer than two render nothing. */
11
+ items: OnThisPageItem[];
12
+ /** Names the nav. Default 'On this page'. */
13
+ 'aria-label'?: string;
14
+ /** The id of the element that scrolls, when it is not the window */
15
+ root?: string;
16
+ /**
17
+ * How far below the top of the scroll area a heading counts as reached, in px. Default 40, plus the height of a
18
+ * `SiteHeader` above the page (`--os-header-offset`) when the window scrolls. A click scrolls the heading to just
19
+ * under that header.
20
+ */
21
+ offset?: number;
22
+ }
23
+ /**
24
+ * Links to a long page's headings, with the one the reader is at marked. The current heading is the last one
25
+ * above `offset`; the last item at the end of the scroll; the one in the `#hash` on load. A click keeps its item
26
+ * current until the scroll ends. Reduced motion jumps instead of scrolling.
27
+ */
28
+ export default function OnThisPage({ items, 'aria-label': ariaLabel, root, offset }: OnThisPageProps): React.JSX.Element | null;
29
+ export { OnThisPage };
@@ -0,0 +1,151 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { useSlidingIndicator } from './slidingIndicator';
4
+ import { focusRing } from './sharedStyles';
5
+ import { hashId, isAtBottom, pickCurrent } from '../internal/scrollSpy';
6
+ // A click or a #hash pins its item as current while the page scrolls there, so the items in between don't flash past
7
+ var PIN_LIMIT = 1000;
8
+ var headerOffset = function () { return parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--os-header-offset')) || 0; };
9
+ var INPUT_EVENTS = ['wheel', 'touchstart', 'keydown', 'pointerdown'];
10
+ /**
11
+ * Links to a long page's headings, with the one the reader is at marked. The current heading is the last one
12
+ * above `offset`; the last item at the end of the scroll; the one in the `#hash` on load. A click keeps its item
13
+ * current until the scroll ends. Reduced motion jumps instead of scrolling.
14
+ */
15
+ export default function OnThisPage(_a) {
16
+ var _b, _c;
17
+ var items = _a.items, _d = _a["aria-label"], ariaLabel = _d === void 0 ? 'On this page' : _d, root = _a.root, offset = _a.offset;
18
+ var ids = items.map(function (item) { return item.id; });
19
+ var key = ids.join('\n');
20
+ var _e = useState((_c = (_b = items[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null), current = _e[0], setCurrent = _e[1];
21
+ var _f = useSlidingIndicator("".concat(key, "|").concat(current)), containerRef = _f.containerRef, indicator = _f.indicator;
22
+ var pin = useRef(null);
23
+ var pinTimer = useRef(undefined);
24
+ // The effect below puts its recompute here, for the click handler
25
+ var refresh = useRef(function () { });
26
+ var setPin = function (id, until) {
27
+ clearTimeout(pinTimer.current);
28
+ pin.current = { id: id, until: until };
29
+ setCurrent(id);
30
+ // Where scrollend exists it ends the pin; the timer is for a browser without it
31
+ if (until === 'scrollend' && !('onscrollend' in window)) {
32
+ pinTimer.current = setTimeout(function () {
33
+ pin.current = null;
34
+ refresh.current();
35
+ }, PIN_LIMIT);
36
+ }
37
+ };
38
+ useEffect(function () {
39
+ if (ids.length < 2)
40
+ return;
41
+ var rootEl = root ? document.getElementById(root) : null;
42
+ var target = rootEl !== null && rootEl !== void 0 ? rootEl : window;
43
+ var frame = 0;
44
+ var compute = function () {
45
+ frame = 0;
46
+ if (pin.current)
47
+ return;
48
+ var base = rootEl ? rootEl.getBoundingClientRect().top : 0;
49
+ var tops = ids.map(function (id) {
50
+ var el = document.getElementById(id);
51
+ return el ? el.getBoundingClientRect().top - base : null;
52
+ });
53
+ var metrics = rootEl
54
+ ? { scrollTop: rootEl.scrollTop, clientHeight: rootEl.clientHeight, scrollHeight: rootEl.scrollHeight }
55
+ : {
56
+ scrollTop: window.scrollY,
57
+ clientHeight: window.innerHeight,
58
+ scrollHeight: document.documentElement.scrollHeight,
59
+ };
60
+ var i = pickCurrent(tops, offset !== null && offset !== void 0 ? offset : 40 + (rootEl ? 0 : headerOffset()), isAtBottom(metrics));
61
+ if (i >= 0)
62
+ setCurrent(ids[i]);
63
+ };
64
+ var schedule = function () {
65
+ if (!frame)
66
+ frame = requestAnimationFrame(compute);
67
+ };
68
+ refresh.current = compute;
69
+ var release = function (only) {
70
+ if (!pin.current || (only && pin.current.until !== only))
71
+ return;
72
+ clearTimeout(pinTimer.current);
73
+ pin.current = null;
74
+ schedule();
75
+ };
76
+ var onInput = function () { return release(); };
77
+ var onScrollEnd = function () { return release('scrollend'); };
78
+ var onHashChange = function () {
79
+ var id = hashId(window.location.hash, ids);
80
+ if (id)
81
+ setPin(id, 'scrollend');
82
+ };
83
+ // Opened with a #hash: that item is current until the reader scrolls
84
+ var initial = hashId(window.location.hash, ids);
85
+ if (initial)
86
+ setPin(initial, 'input');
87
+ else
88
+ compute();
89
+ target.addEventListener('scroll', schedule, { passive: true });
90
+ target.addEventListener('scrollend', onScrollEnd);
91
+ window.addEventListener('resize', schedule);
92
+ window.addEventListener('hashchange', onHashChange);
93
+ INPUT_EVENTS.forEach(function (type) { return target.addEventListener(type, onInput, { passive: true }); });
94
+ return function () {
95
+ cancelAnimationFrame(frame);
96
+ clearTimeout(pinTimer.current);
97
+ pin.current = null;
98
+ refresh.current = function () { };
99
+ target.removeEventListener('scroll', schedule);
100
+ target.removeEventListener('scrollend', onScrollEnd);
101
+ window.removeEventListener('resize', schedule);
102
+ window.removeEventListener('hashchange', onHashChange);
103
+ INPUT_EVENTS.forEach(function (type) { return target.removeEventListener(type, onInput); });
104
+ };
105
+ }, [key, root, offset]); // eslint-disable-line react-hooks/exhaustive-deps
106
+ var onLinkClick = function (e, id) {
107
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
108
+ return;
109
+ var heading = document.getElementById(id);
110
+ if (!heading)
111
+ return;
112
+ e.preventDefault();
113
+ var rootEl = root ? document.getElementById(root) : null;
114
+ var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
115
+ // The heading ends just under a header above the page; 'instant' ignores a page's own `scroll-behavior: smooth`
116
+ var behavior = reduced ? 'instant' : 'smooth';
117
+ var gap = rootEl ? 0 : headerOffset();
118
+ var delta = heading.getBoundingClientRect().top - (rootEl ? rootEl.getBoundingClientRect().top : 0) - gap;
119
+ window.history.pushState(window.history.state, '', "#".concat(encodeURIComponent(id)));
120
+ var top = rootEl ? rootEl.scrollTop : window.scrollY;
121
+ var room = rootEl
122
+ ? rootEl.scrollHeight - rootEl.clientHeight - top
123
+ : document.documentElement.scrollHeight - window.innerHeight - top;
124
+ if (Math.abs(delta > 0 ? Math.min(delta, room) : Math.max(delta, -top)) < 1) {
125
+ // Nowhere to scroll (already there, or at an end): no scrollend to wait for
126
+ setCurrent(id);
127
+ return;
128
+ }
129
+ setPin(id, 'scrollend');
130
+ if (rootEl)
131
+ rootEl.scrollBy({ top: delta, behavior: behavior });
132
+ else
133
+ window.scrollBy({ top: delta, behavior: behavior });
134
+ };
135
+ if (items.length < 2)
136
+ return null;
137
+ return (<nav ref={containerRef} aria-label={ariaLabel} className="relative border-l border-misc-divider">
138
+ {indicator && (<span aria-hidden className={"pointer-events-none absolute -left-px top-0 w-0.5 rounded-full bg-primary-dark ".concat(indicator.animate ? 'transition-[transform,height] duration-[var(--os-duration-slide)] ease-emphasized motion-reduce:transition-none' : '')} style={{ transform: "translateY(".concat(indicator.y, "px)"), height: indicator.height }}/>)}
139
+ <ul className="m-0 flex list-none flex-col p-0">
140
+ {items.map(function (item) {
141
+ var isCurrent = item.id === current;
142
+ return (<li key={item.id}>
143
+ <a href={"#".concat(item.id)} aria-current={isCurrent ? 'location' : undefined} data-tab-selected={isCurrent ? 'true' : undefined} onClick={function (e) { return onLinkClick(e, item.id); }} className={"block rounded-control py-1 pr-2 text-body2 hover:text-fg-primary ".concat(item.level === 3 ? 'pl-6' : 'pl-3', " ").concat(isCurrent ? 'text-fg-primary' : 'text-fg-secondary', " ").concat(focusRing)}>
144
+ {item.label}
145
+ </a>
146
+ </li>);
147
+ })}
148
+ </ul>
149
+ </nav>);
150
+ }
151
+ export { OnThisPage };
@@ -5,6 +5,12 @@ interface PageShellProps extends React.ComponentPropsWithoutRef<'main'> {
5
5
  wide?: boolean;
6
6
  /** Let the column run the full width of the window, for a page that is a feed of images. Keeps the side space. */
7
7
  fluid?: boolean;
8
+ /**
9
+ * A column beside the page, for an `OnThisPage`: 220px and sticky from the xl breakpoint, hidden below it. It sticks below a `SiteHeader` (`--os-header-offset`).
10
+ * The page also gives each level 2 and 3 heading with an `id` a scroll margin the height of that header, so a `#hash` link lands below it.
11
+ * Not for content a phone needs.
12
+ */
13
+ aside?: React.ReactNode;
8
14
  }
9
- export default function PageShell({ children, wide, fluid, className, ...rest }: PageShellProps): React.JSX.Element;
15
+ export default function PageShell({ children, wide, fluid, aside, className, ...rest }: PageShellProps): React.JSX.Element;
10
16
  export {};
@@ -13,7 +13,20 @@ import React from 'react';
13
13
  // The frame of a page: the column, its side space, and the space between sections.
14
14
  // Anything else given (data-* attributes, an id) goes to the <main>.
15
15
  export default function PageShell(_a) {
16
- var children = _a.children, _b = _a.wide, wide = _b === void 0 ? false : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, _d = _a.className, className = _d === void 0 ? '' : _d, rest = __rest(_a, ["children", "wide", "fluid", "className"]);
16
+ var children = _a.children, _b = _a.wide, wide = _b === void 0 ? false : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, aside = _a.aside, _d = _a.className, className = _d === void 0 ? '' : _d, rest = __rest(_a, ["children", "wide", "fluid", "aside", "className"]);
17
+ if (aside) {
18
+ // The page column and the aside sit side by side from xl, centered together
19
+ return (<main className={"min-h-screen [&_:is(h2,h3)[id]]:scroll-mt-[var(--os-header-offset,0px)] ".concat(className)} {...rest}>
20
+ <div className="mx-auto flex w-full items-start justify-center">
21
+ <div className={"flex min-w-0 w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
22
+ {children}
23
+ </div>
24
+ <div className="sticky top-[calc(var(--os-header-offset,0px)+1.5rem)] mr-xxlarge mt-giant hidden max-h-[calc(100dvh-var(--os-header-offset,0px)-3rem)] w-[220px] shrink-0 overflow-y-auto xl:block">
25
+ {aside}
26
+ </div>
27
+ </div>
28
+ </main>);
29
+ }
17
30
  return (<main className={"min-h-screen ".concat(className)} {...rest}>
18
31
  <div className={"mx-auto flex w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
19
32
  {children}
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ interface PaginationProps {
3
+ /** The page being shown, counted from 1. */
4
+ page: number;
5
+ /** How many pages there are. With 1 or fewer, nothing renders. */
6
+ pageCount: number;
7
+ /** Called with the page asked for. Also called with the last page when `page` is past `pageCount` (a filter left fewer pages). */
8
+ onPageChange?: (page: number) => void;
9
+ /** Names the navigation. Defaults to 'Pages'. */
10
+ 'aria-label'?: string;
11
+ /** `default` is 'Previous', 'Page 3 of 12' and 'Next'. `compact` is two small arrows and '2 of 5', for a card. */
12
+ variant?: 'default' | 'compact';
13
+ /** Makes Previous and Next links to the address of that page, with `rel="prev"` and `rel="next"`. `onPageChange` is still called. */
14
+ getHref?: (page: number) => string;
15
+ /**
16
+ * The id of the element (the table) to scroll to the top of the view after a press of Previous or Next. Instant under
17
+ * reduced motion. Focus stays on Next so a keyboard user keeps paging, and the live region announces the page.
18
+ * A page set from outside (a filter reset) does not scroll.
19
+ */
20
+ scrollTargetId?: string;
21
+ }
22
+ /**
23
+ * Previous and Next with the page named in words. There are no numbered buttons: they do not fit a phone or 500 pages.
24
+ * The page text is a polite live region. When the press that reaches the first or last page leaves focus on a
25
+ * disabled button, focus moves to the other one.
26
+ */
27
+ export default function Pagination({ page, pageCount, onPageChange, 'aria-label': ariaLabel, variant, getHref, scrollTargetId, }: PaginationProps): React.JSX.Element | null;
28
+ export {};
@@ -0,0 +1,89 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef } from 'react';
3
+ import Button from './button';
4
+ import IconButton from './iconButton';
5
+ import { formatCount } from './formatNumber';
6
+ /**
7
+ * Previous and Next with the page named in words. There are no numbered buttons: they do not fit a phone or 500 pages.
8
+ * The page text is a polite live region. When the press that reaches the first or last page leaves focus on a
9
+ * disabled button, focus moves to the other one.
10
+ */
11
+ export default function Pagination(_a) {
12
+ var page = _a.page, pageCount = _a.pageCount, onPageChange = _a.onPageChange, _b = _a["aria-label"], ariaLabel = _b === void 0 ? 'Pages' : _b, _c = _a.variant, variant = _c === void 0 ? 'default' : _c, getHref = _a.getHref, scrollTargetId = _a.scrollTargetId;
13
+ var navRef = useRef(null);
14
+ var prevRef = useRef(null);
15
+ var nextRef = useRef(null);
16
+ var pending = useRef(null);
17
+ var onChange = useRef(onPageChange);
18
+ onChange.current = onPageChange;
19
+ var lastPage = useRef(page);
20
+ // The page a press of Previous or Next asked for, so only reaching it scrolls: a parent resetting the page, the clamp and the first render do not
21
+ var pressed = useRef(null);
22
+ var last = Math.max(1, pageCount);
23
+ var shown = Math.max(1, Math.min(page, last));
24
+ // A filter that leaves fewer pages than the one being shown
25
+ useEffect(function () {
26
+ var _a;
27
+ if (page > pageCount)
28
+ (_a = onChange.current) === null || _a === void 0 ? void 0 : _a.call(onChange, last);
29
+ }, [page, pageCount, last]);
30
+ // Focus must not drop to the page when the Button it was on turns disabled
31
+ useEffect(function () {
32
+ var _a, _b;
33
+ var p = pending.current;
34
+ if (!p || p.to !== shown)
35
+ return;
36
+ pending.current = null;
37
+ var active = document.activeElement;
38
+ if (active && active !== document.body && !((_a = navRef.current) === null || _a === void 0 ? void 0 : _a.contains(active)))
39
+ return;
40
+ (_b = (p.focus === 'prev' ? prevRef : nextRef).current) === null || _b === void 0 ? void 0 : _b.focus();
41
+ }, [shown]);
42
+ useEffect(function () {
43
+ var _a;
44
+ if (lastPage.current === shown)
45
+ return;
46
+ lastPage.current = shown;
47
+ var byPress = pressed.current === shown;
48
+ pressed.current = null;
49
+ if (!scrollTargetId || !byPress)
50
+ return;
51
+ var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
52
+ (_a = document.getElementById(scrollTargetId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'start', behavior: reduced ? 'instant' : 'smooth' });
53
+ }, [shown, scrollTargetId]);
54
+ if (pageCount <= 1)
55
+ return null;
56
+ var atFirst = shown <= 1;
57
+ var atLast = shown >= last;
58
+ var go = function (to, from) {
59
+ var _a;
60
+ if (to < 1 || to > last || to === shown)
61
+ return;
62
+ if (to === 1 || to === last)
63
+ pending.current = { to: to, focus: from === 'prev' ? 'next' : 'prev' };
64
+ pressed.current = to;
65
+ (_a = onChange.current) === null || _a === void 0 ? void 0 : _a.call(onChange, to);
66
+ };
67
+ var prevHref = getHref && !atFirst ? getHref(shown - 1) : undefined;
68
+ var nextHref = getHref && !atLast ? getHref(shown + 1) : undefined;
69
+ // `rel` is not a Button prop; it lands on the anchor with the rest
70
+ var prevRel = prevHref ? { rel: 'prev' } : {};
71
+ var nextRel = nextHref ? { rel: 'next' } : {};
72
+ var of = "".concat(formatCount(shown), " of ").concat(formatCount(pageCount));
73
+ var text = variant === 'compact' ? of : "Page ".concat(of);
74
+ var live = (<span aria-live="polite" aria-atomic="true" className={"tabular-nums text-fg-secondary ".concat(variant === 'compact' ? 'text-caption' : 'text-body2')}>
75
+ {text}
76
+ </span>);
77
+ if (variant === 'compact') {
78
+ return (<nav ref={navRef} aria-label={ariaLabel} className="flex items-center gap-1">
79
+ <IconButton ref={prevRef} color="iconOnly" size="tiny" state={atFirst ? 'disabled' : 'enabled'} iconName="ChevronLeft" ariaLabel="Previous page" href={prevHref} onClick={function () { return go(shown - 1, 'prev'); }} {...prevRel}/>
80
+ {live}
81
+ <IconButton ref={nextRef} color="iconOnly" size="tiny" state={atLast ? 'disabled' : 'enabled'} iconName="ChevronRight" ariaLabel="Next page" href={nextHref} onClick={function () { return go(shown + 1, 'next'); }} {...nextRel}/>
82
+ </nav>);
83
+ }
84
+ return (<nav ref={navRef} aria-label={ariaLabel} className="flex items-center justify-between gap-2">
85
+ <Button ref={prevRef} size="small" type="tertiary" state={atFirst ? 'disabled' : 'enabled'} label="Previous" decoIcon="ChevronLeft" aria-label="Previous page" href={prevHref} onClickButton={function () { return go(shown - 1, 'prev'); }} {...prevRel}/>
86
+ {live}
87
+ <Button ref={nextRef} size="small" type="tertiary" state={atLast ? 'disabled' : 'enabled'} label="Next" actionIcon="ChevronRight" aria-label="Next page" href={nextHref} onClickButton={function () { return go(shown + 1, 'next'); }} {...nextRel}/>
88
+ </nav>);
89
+ }
@@ -5,6 +5,7 @@ import { usePopper } from 'react-popper';
5
5
  import { overlayHidden, overlayTransition, overlayVisible } from './sharedStyles';
6
6
  import { useOverlayTransition } from './useOverlayTransition';
7
7
  import Menu from './menu';
8
+ import { isInTopOverlay } from '../internal/overlayStack';
8
9
  export default function Popover(_a) {
9
10
  var id = _a.id, anchorEl = _a.anchorEl, open = _a.open, onClose = _a.onClose, children = _a.children, _b = _a.returnFocus, returnFocus = _b === void 0 ? false : _b;
10
11
  var _c = useState(null), popoverElement = _c[0], setPopoverElement = _c[1];
@@ -28,6 +29,9 @@ export default function Popover(_a) {
28
29
  };
29
30
  var handleKeyDown = function (event) {
30
31
  if (event.key === 'Escape') {
32
+ // Under a Modal or Drawer opened after it, the Escape belongs to that overlay
33
+ if (!isInTopOverlay(anchorEl))
34
+ return;
31
35
  // Close only the Popover: keep this Escape from reaching a Modal's window listener
32
36
  event.stopPropagation();
33
37
  onClose();
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ interface ProgressProps {
3
+ /** What is measured, e.g. "Responses". Always the meter's name, even with `hideLabel`. */
4
+ label: string;
5
+ /** The amount used. */
6
+ value: number;
7
+ /** The limit. `null` means there is no limit: the label and the text show, with no bar and no `meter` role. */
8
+ max: number | null;
9
+ /** The words for the amount, in place of '<value> of <max> <unit>'. */
10
+ valueText?: string;
11
+ /** What is counted, e.g. "responses". Goes after the numbers in the default text. */
12
+ unit?: string;
13
+ /**
14
+ * `limit` (default) is how much of a limit is used: the bar turns to a warning near it and to an error at it.
15
+ * `share` is one part of a total (`max` is the total): always the main color, no status words, and the text is
16
+ * '42%, 1,240 responses'. A share is not a limit.
17
+ */
18
+ kind?: 'limit' | 'share';
19
+ /** The share of `max` where the bar turns to a warning. Defaults to 0.8. */
20
+ warnAt?: number;
21
+ /** Keeps the name for a screen reader and hides the row of words, for a bar in a table cell. */
22
+ hideLabel?: boolean;
23
+ /** Bar thickness: 4px or 6px. */
24
+ size?: 'small' | 'medium';
25
+ id?: string;
26
+ 'aria-describedby'?: string;
27
+ }
28
+ /**
29
+ * A meter: how much of a limit is used. It is not a task progress bar and not a spinner. The bar turns to a
30
+ * warning near the limit and to an error at it, and says so in words, never by color alone.
31
+ */
32
+ export default function Progress({ label, value, max, valueText, unit, kind, warnAt, hideLabel, size, id, 'aria-describedby': describedBy, }: ProgressProps): React.JSX.Element;
33
+ export {};
@@ -0,0 +1,50 @@
1
+ 'use client';
2
+ import React, { useId } from 'react';
3
+ import { formatCount, formatPercent } from './formatNumber';
4
+ /**
5
+ * A meter: how much of a limit is used. It is not a task progress bar and not a spinner. The bar turns to a
6
+ * warning near the limit and to an error at it, and says so in words, never by color alone.
7
+ */
8
+ export default function Progress(_a) {
9
+ var label = _a.label, value = _a.value, max = _a.max, valueText = _a.valueText, unit = _a.unit, _b = _a.kind, kind = _b === void 0 ? 'limit' : _b, _c = _a.warnAt, warnAt = _c === void 0 ? 0.8 : _c, _d = _a.hideLabel, hideLabel = _d === void 0 ? false : _d, _e = _a.size, size = _e === void 0 ? 'medium' : _e, id = _a.id, describedBy = _a["aria-describedby"];
10
+ var autoId = useId();
11
+ var labelId = "".concat(id !== null && id !== void 0 ? id : autoId, "-label");
12
+ var withUnit = function (text) { return (unit ? "".concat(text, " ").concat(unit) : text); };
13
+ var rowClasses = "flex items-baseline justify-between gap-2 text-body2".concat(hideLabel ? ' sr-only' : '');
14
+ if (max === null) {
15
+ var text_1 = valueText !== null && valueText !== void 0 ? valueText : "".concat(withUnit(formatCount(value)), ", no limit");
16
+ return (
17
+ // No meter here, so there is nothing for aria-describedby to describe: it is ignored
18
+ <div id={id} className="w-full">
19
+ <div className={rowClasses}>
20
+ <span className="text-fg-primary">{label}</span>
21
+ <span className="text-fg-secondary">{text_1}</span>
22
+ </div>
23
+ </div>);
24
+ }
25
+ var fraction = max > 0 ? value / max : value > 0 ? 1 : 0;
26
+ var now = Math.min(max, Math.max(0, value));
27
+ var status = kind === 'share' ? 'primary' : fraction >= 1 ? 'error' : fraction >= warnAt ? 'warning' : 'primary';
28
+ var share = kind === 'share';
29
+ var text = valueText !== null && valueText !== void 0 ? valueText : (share ? withUnit("".concat(formatPercent(max > 0 ? value / max : 0), ", ").concat(formatCount(value))) : withUnit("".concat(formatCount(value), " of ").concat(formatCount(max))));
30
+ var suffix = share ? '' : status === 'error' ? (value > max ? ', over the limit' : ', at the limit') : status === 'warning' ? ', almost at the limit' : '';
31
+ var statusWords = { error: 'Limit reached', warning: 'Almost at the limit', primary: '' }[status];
32
+ var bar = { error: 'bg-error-main', warning: 'bg-warning-main', primary: 'bg-accent-main' }[status];
33
+ var wordColor = { error: 'text-error-text', warning: 'text-warning-text', primary: '' }[status];
34
+ var percent = Math.min(100, Math.max(0, fraction * 100));
35
+ return (
36
+ // The wrapper is the meter: a meter's children are presentational, so a reader that supports the role says the
37
+ // name and value text once, and one that does not reads the visible words
38
+ <div id={id} role="meter" aria-labelledby={labelId} aria-valuemin={0} aria-valuenow={now} aria-valuemax={max} aria-valuetext={"".concat(text).concat(suffix)} aria-describedby={describedBy} className="w-full">
39
+ <div className={rowClasses}>
40
+ <span id={labelId} className="text-fg-primary">{label}</span>
41
+ <span className="text-fg-secondary">
42
+ {text}
43
+ {statusWords && <span className={"ml-1 ".concat(wordColor)}>{statusWords}</span>}
44
+ </span>
45
+ </div>
46
+ <div className={"".concat(hideLabel ? '' : 'mt-1 ', "w-full overflow-hidden rounded-full bg-fg-primary/10 ").concat(size === 'small' ? 'h-1' : 'h-[6px]')}>
47
+ <div className={"h-full rounded-full ".concat(bar, " transition-[width] duration-[var(--os-duration-fast)] ease-out motion-reduce:transition-none")} style={{ width: "".concat(percent, "%") }}/>
48
+ </div>
49
+ </div>);
50
+ }
@@ -26,6 +26,11 @@ interface SettingsLayoutProps {
26
26
  showContent: boolean;
27
27
  /** A Button that goes back to the nav. Shown only below md, above the content. */
28
28
  back?: React.ReactNode;
29
+ /**
30
+ * The nav column from md up: `narrow` (16rem, default) for a settings nav, `wide` (22rem) for a list of rows beside its detail.
31
+ * Below md a `wide` list is the whole screen: it drops its divider, and its open row (the one with `aria-current`) does not look selected.
32
+ */
33
+ navWidth?: 'narrow' | 'wide';
29
34
  }
30
- export declare function SettingsLayout({ nav, children, showContent, back }: SettingsLayoutProps): React.JSX.Element;
35
+ export declare function SettingsLayout({ nav, children, showContent, back, navWidth }: SettingsLayoutProps): React.JSX.Element;
31
36
  export { SettingsSection };
@@ -25,8 +25,15 @@ export function SettingsColumns(_a) {
25
25
  // A side nav beside its content from md up. On a phone the nav is the page and an item opens its content, so only one shows at a time.
26
26
  var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
27
27
  var isHidden = function (el) { return !el || getComputedStyle(el).display === 'none'; };
28
+ // Written out whole so the app's Tailwind finds them
29
+ var navColumns = {
30
+ narrow: 'md:grid-cols-[16rem_minmax(0,1fr)]',
31
+ wide: 'md:grid-cols-[22rem_minmax(0,1fr)]',
32
+ };
33
+ // Below md a list of rows is the screen on its own: no divider beside nothing, and no row marked open while nothing is open
34
+ var listOnPhone = 'max-md:[&>nav]:border-r-0 max-md:[&_[aria-current]:not([aria-current=false])]:bg-transparent max-md:[&_[aria-current]:not([aria-current=false])_*]:bg-transparent max-md:[&_[aria-current]:not([aria-current=false])_*]:text-fg-primary';
28
35
  export function SettingsLayout(_a) {
29
- var nav = _a.nav, children = _a.children, showContent = _a.showContent, back = _a.back;
36
+ var nav = _a.nav, children = _a.children, showContent = _a.showContent, back = _a.back, _b = _a.navWidth, navWidth = _b === void 0 ? 'narrow' : _b;
30
37
  var navRef = useRef(null);
31
38
  var contentRef = useRef(null);
32
39
  var prev = useRef(showContent);
@@ -47,8 +54,8 @@ export function SettingsLayout(_a) {
47
54
  (_d = ((_c = items === null || items === void 0 ? void 0 : items.querySelector('[aria-current]')) !== null && _c !== void 0 ? _c : items === null || items === void 0 ? void 0 : items.querySelector(FOCUSABLE))) === null || _d === void 0 ? void 0 : _d.focus();
48
55
  }
49
56
  }, [showContent]);
50
- return (<div className="grid grid-cols-1 items-start gap-xlarge md:grid-cols-[16rem_minmax(0,1fr)]">
51
- <div ref={navRef} className={showContent ? 'hidden md:block' : 'block'}>{nav}</div>
57
+ return (<div className={"grid grid-cols-1 items-start gap-xlarge ".concat(navColumns[navWidth])}>
58
+ <div ref={navRef} className={"".concat(showContent ? 'hidden md:block' : 'block').concat(navWidth === 'wide' ? " ".concat(listOnPhone) : '')}>{nav}</div>
52
59
  <div ref={contentRef} className={"flex-col gap-large ".concat(showContent ? 'flex' : 'hidden md:flex')}>
53
60
  {back && <div className="md:hidden">{back}</div>}
54
61
  {children}