oneslash-design-system 2.16.0 → 2.18.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 (301) hide show
  1. package/README.md +2 -2
  2. package/dist/DESIGN.md +56 -17
  3. package/dist/cases/accept-invite/signed-in.jsx +1 -1
  4. package/dist/cases/accept-invite/signed-out.jsx +1 -1
  5. package/dist/cases/accept-invite.md +3 -7
  6. package/dist/cases/account-menu/menu.d.ts +1 -0
  7. package/dist/cases/account-menu/menu.jsx +99 -0
  8. package/dist/cases/account-menu.md +164 -0
  9. package/dist/cases/agent-asks-before-risky-action.md +0 -4
  10. package/dist/cases/agent-cancels-when-unanswered.md +0 -4
  11. package/dist/cases/agent-options/cards.d.ts +1 -0
  12. package/dist/cases/agent-options/cards.jsx +91 -0
  13. package/dist/cases/agent-options.md +164 -0
  14. package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
  15. package/dist/cases/agent-pending-reply/steps.jsx +149 -0
  16. package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
  17. package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
  18. package/dist/cases/agent-pending-reply.md +428 -0
  19. package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
  20. package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
  21. package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
  22. package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
  23. package/dist/cases/agent-plan-proposal.md +652 -0
  24. package/dist/cases/agent-question/choices.d.ts +1 -0
  25. package/dist/cases/agent-question/choices.jsx +132 -0
  26. package/dist/cases/agent-question/free-text.d.ts +1 -0
  27. package/dist/cases/agent-question/free-text.jsx +81 -0
  28. package/dist/cases/agent-question.md +334 -0
  29. package/dist/cases/agent-refuses-clearly.md +0 -4
  30. package/dist/cases/agent-says-what-it-is.md +0 -2
  31. package/dist/cases/agent-settings/form.d.ts +1 -0
  32. package/dist/cases/agent-settings/form.jsx +164 -0
  33. package/dist/cases/agent-settings.md +259 -0
  34. package/dist/cases/agent-shows-progress.md +0 -2
  35. package/dist/cases/agent-shows-sources.md +2 -4
  36. package/dist/cases/api-keys/list.d.ts +1 -0
  37. package/dist/cases/api-keys/list.jsx +162 -0
  38. package/dist/cases/api-keys.md +229 -0
  39. package/dist/cases/artifact-card/card.d.ts +1 -0
  40. package/dist/cases/artifact-card/card.jsx +45 -0
  41. package/dist/cases/artifact-card.md +99 -0
  42. package/dist/cases/auth-gate-loading.md +0 -4
  43. package/dist/cases/check-your-email.md +0 -4
  44. package/dist/cases/collapsible-search/popover.d.ts +1 -0
  45. package/dist/cases/collapsible-search/popover.jsx +74 -0
  46. package/dist/cases/collapsible-search.md +143 -0
  47. package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
  48. package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
  49. package/dist/cases/composer-limit/notice.d.ts +1 -0
  50. package/dist/cases/composer-limit/notice.jsx +84 -0
  51. package/dist/cases/composer-limit.md +282 -0
  52. package/dist/cases/confirm-destructive-action.md +0 -4
  53. package/dist/cases/confirm-dialogs.md +0 -4
  54. package/dist/cases/conversation-starters/chips.d.ts +1 -0
  55. package/dist/cases/conversation-starters/chips.jsx +69 -0
  56. package/dist/cases/conversation-starters/none.d.ts +1 -0
  57. package/dist/cases/conversation-starters/none.jsx +45 -0
  58. package/dist/cases/conversation-starters.md +204 -0
  59. package/dist/cases/create-modal.md +0 -4
  60. package/dist/cases/danger-zone/collapsed.d.ts +1 -0
  61. package/dist/cases/danger-zone/collapsed.jsx +75 -0
  62. package/dist/cases/danger-zone/shown.d.ts +1 -0
  63. package/dist/cases/danger-zone/shown.jsx +95 -0
  64. package/dist/cases/danger-zone.md +263 -0
  65. package/dist/cases/device-login.md +0 -4
  66. package/dist/cases/email-confirmed.md +0 -4
  67. package/dist/cases/empty-list.md +0 -4
  68. package/dist/cases/empty-lists.md +0 -4
  69. package/dist/cases/empty-not-set-up.md +0 -4
  70. package/dist/cases/empty-search.md +0 -4
  71. package/dist/cases/error-page.md +0 -4
  72. package/dist/cases/feedback-form.md +0 -4
  73. package/dist/cases/filter-menu/presets.d.ts +1 -0
  74. package/dist/cases/filter-menu/presets.jsx +53 -0
  75. package/dist/cases/filter-menu/with-clear.d.ts +1 -0
  76. package/dist/cases/filter-menu/with-clear.jsx +56 -0
  77. package/dist/cases/filter-menu.md +204 -0
  78. package/dist/cases/forgot-password.md +0 -4
  79. package/dist/cases/form-errors.md +0 -4
  80. package/dist/cases/import-checklist.md +0 -4
  81. package/dist/cases/inline-form-feedback.md +0 -4
  82. package/dist/cases/integrations-list/nested.d.ts +1 -0
  83. package/dist/cases/integrations-list/nested.jsx +164 -0
  84. package/dist/cases/integrations-list/rows.d.ts +1 -0
  85. package/dist/cases/integrations-list/rows.jsx +134 -0
  86. package/dist/cases/integrations-list.md +379 -0
  87. package/dist/cases/invite-member.md +0 -4
  88. package/dist/cases/load-failure.md +0 -4
  89. package/dist/cases/log-out-confirm.md +0 -4
  90. package/dist/cases/login-page.md +0 -4
  91. package/dist/cases/members-list/rows.d.ts +1 -0
  92. package/dist/cases/members-list/rows.jsx +318 -0
  93. package/dist/cases/members-list/table.d.ts +1 -0
  94. package/dist/cases/members-list/table.jsx +351 -0
  95. package/dist/cases/members-list.md +799 -0
  96. package/dist/cases/mention-list/in-composer.d.ts +1 -0
  97. package/dist/cases/mention-list/in-composer.jsx +169 -0
  98. package/dist/cases/mention-list.md +248 -0
  99. package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
  100. package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
  101. package/dist/cases/message-actions/menu.d.ts +1 -0
  102. package/dist/cases/message-actions/menu.jsx +258 -0
  103. package/dist/cases/message-actions.md +647 -0
  104. package/dist/cases/message-attachments/in-composer.d.ts +1 -0
  105. package/dist/cases/message-attachments/in-composer.jsx +134 -0
  106. package/dist/cases/message-attachments/in-message.d.ts +1 -0
  107. package/dist/cases/message-attachments/in-message.jsx +46 -0
  108. package/dist/cases/message-attachments.md +306 -0
  109. package/dist/cases/message-composer/plain.d.ts +1 -0
  110. package/dist/cases/message-composer/plain.jsx +57 -0
  111. package/dist/cases/message-composer/with-tools.d.ts +1 -0
  112. package/dist/cases/message-composer/with-tools.jsx +182 -0
  113. package/dist/cases/message-composer.md +352 -0
  114. package/dist/cases/message-edit/in-place.d.ts +1 -0
  115. package/dist/cases/message-edit/in-place.jsx +99 -0
  116. package/dist/cases/message-edit.md +175 -0
  117. package/dist/cases/message-reactions/chips.d.ts +1 -0
  118. package/dist/cases/message-reactions/chips.jsx +118 -0
  119. package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
  120. package/dist/cases/message-reactions/quick-pick.jsx +155 -0
  121. package/dist/cases/message-reactions.md +367 -0
  122. package/dist/cases/message-row/grouped.d.ts +1 -0
  123. package/dist/cases/message-row/grouped.jsx +56 -0
  124. package/dist/cases/message-row/person-and-agent.d.ts +1 -0
  125. package/dist/cases/message-row/person-and-agent.jsx +41 -0
  126. package/dist/cases/message-row.md +185 -0
  127. package/dist/cases/not-found-page.md +0 -4
  128. package/dist/cases/notification-menu/menu.d.ts +1 -0
  129. package/dist/cases/notification-menu/menu.jsx +74 -0
  130. package/dist/cases/notification-menu.md +135 -0
  131. package/dist/cases/oauth-consent.md +0 -4
  132. package/dist/cases/on-off-settings/list.d.ts +1 -0
  133. package/dist/cases/on-off-settings/list.jsx +97 -0
  134. package/dist/cases/on-off-settings.md +116 -0
  135. package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
  136. package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
  137. package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
  138. package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
  139. package/dist/cases/overflow-menu.md +410 -0
  140. package/dist/cases/profile-form/form.d.ts +1 -0
  141. package/dist/cases/profile-form/form.jsx +153 -0
  142. package/dist/cases/profile-form.md +236 -0
  143. package/dist/cases/quick-switcher/modal.d.ts +1 -0
  144. package/dist/cases/quick-switcher/modal.jsx +114 -0
  145. package/dist/cases/quick-switcher.md +205 -0
  146. package/dist/cases/range-switch/segmented.d.ts +1 -0
  147. package/dist/cases/range-switch/segmented.jsx +30 -0
  148. package/dist/cases/range-switch.md +67 -0
  149. package/dist/cases/rename.md +0 -4
  150. package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
  151. package/dist/cases/reply-feedback/thumbs.jsx +191 -0
  152. package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
  153. package/dist/cases/reply-feedback/with-reason.jsx +221 -0
  154. package/dist/cases/reply-feedback.md +548 -0
  155. package/dist/cases/reply-sources/cards.d.ts +1 -0
  156. package/dist/cases/reply-sources/cards.jsx +83 -0
  157. package/dist/cases/reply-sources/tag-only.d.ts +1 -0
  158. package/dist/cases/reply-sources/tag-only.jsx +45 -0
  159. package/dist/cases/reply-sources.md +243 -0
  160. package/dist/cases/route-loading.md +0 -2
  161. package/dist/cases/scope-picker/menu.d.ts +1 -0
  162. package/dist/cases/scope-picker/menu.jsx +47 -0
  163. package/dist/cases/scope-picker.md +97 -0
  164. package/dist/cases/set-new-password.md +0 -4
  165. package/dist/cases/settings-page/side-nav.d.ts +1 -0
  166. package/dist/cases/settings-page/side-nav.jsx +171 -0
  167. package/dist/cases/settings-page/top-tabs.d.ts +1 -0
  168. package/dist/cases/settings-page/top-tabs.jsx +129 -0
  169. package/dist/cases/settings-page.md +378 -0
  170. package/dist/cases/settings-save.md +35 -0
  171. package/dist/cases/sign-up-page.md +1 -5
  172. package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
  173. package/dist/cases/slash-command-list/in-composer.jsx +162 -0
  174. package/dist/cases/slash-command-list.md +243 -0
  175. package/dist/cases/success-feedback.md +1 -5
  176. package/dist/cases/tag-filter/tags.d.ts +1 -0
  177. package/dist/cases/tag-filter/tags.jsx +226 -0
  178. package/dist/cases/tag-filter.md +298 -0
  179. package/dist/cases/type-to-confirm.md +0 -4
  180. package/dist/cases/typing-and-status/line.d.ts +1 -0
  181. package/dist/cases/typing-and-status/line.jsx +50 -0
  182. package/dist/cases/typing-and-status.md +92 -0
  183. package/dist/cases/unsaved-changes-guard.md +0 -4
  184. package/dist/cases/upgrade-prompt.md +0 -4
  185. package/dist/cases.json +2331 -294
  186. package/dist/components/alert.d.ts +3 -1
  187. package/dist/components/alert.jsx +2 -2
  188. package/dist/components/button.d.ts +3 -2
  189. package/dist/components/button.jsx +14 -9
  190. package/dist/components/checkBox.d.ts +5 -1
  191. package/dist/components/checkBox.jsx +2 -2
  192. package/dist/components/composer.d.ts +74 -0
  193. package/dist/components/composer.jsx +122 -0
  194. package/dist/components/copyField.d.ts +20 -0
  195. package/dist/components/copyField.jsx +99 -0
  196. package/dist/components/fileChip.d.ts +33 -0
  197. package/dist/components/fileChip.jsx +61 -0
  198. package/dist/components/formField.d.ts +34 -0
  199. package/dist/components/formField.jsx +28 -0
  200. package/dist/components/heading.d.ts +3 -1
  201. package/dist/components/heading.jsx +2 -2
  202. package/dist/components/iconButton.d.ts +3 -3
  203. package/dist/components/iconButton.jsx +9 -7
  204. package/dist/components/layout.d.ts +7 -1
  205. package/dist/components/layout.jsx +5 -2
  206. package/dist/components/menu.d.ts +21 -0
  207. package/dist/components/menu.jsx +27 -3
  208. package/dist/components/menuItem.d.ts +12 -2
  209. package/dist/components/menuItem.jsx +6 -5
  210. package/dist/components/message.d.ts +28 -0
  211. package/dist/components/message.jsx +25 -0
  212. package/dist/components/navigation.d.ts +9 -1
  213. package/dist/components/navigation.jsx +15 -3
  214. package/dist/components/paragraph.d.ts +3 -1
  215. package/dist/components/paragraph.jsx +2 -2
  216. package/dist/components/popover.d.ts +7 -1
  217. package/dist/components/popover.jsx +35 -9
  218. package/dist/components/radioGroup.d.ts +12 -1
  219. package/dist/components/radioGroup.jsx +20 -9
  220. package/dist/components/segmentedControl.d.ts +22 -0
  221. package/dist/components/segmentedControl.jsx +54 -0
  222. package/dist/components/select.d.ts +5 -1
  223. package/dist/components/select.jsx +2 -2
  224. package/dist/components/settingsSection.d.ts +31 -0
  225. package/dist/components/settingsSection.jsx +58 -0
  226. package/dist/components/slidingIndicator.d.ts +50 -0
  227. package/dist/components/slidingIndicator.jsx +102 -0
  228. package/dist/components/sourceCard.d.ts +23 -0
  229. package/dist/components/sourceCard.jsx +56 -0
  230. package/dist/components/stepList.d.ts +17 -0
  231. package/dist/components/stepList.jsx +79 -0
  232. package/dist/components/switch.d.ts +25 -0
  233. package/dist/components/switch.jsx +55 -0
  234. package/dist/components/tab.jsx +5 -11
  235. package/dist/components/tabsContainer.jsx +5 -67
  236. package/dist/components/tag.d.ts +9 -1
  237. package/dist/components/tag.jsx +6 -4
  238. package/dist/components/textField.d.ts +12 -2
  239. package/dist/components/textField.jsx +11 -4
  240. package/dist/components/textarea.d.ts +5 -1
  241. package/dist/components/textarea.jsx +6 -21
  242. package/dist/components/useHotkey.d.ts +7 -0
  243. package/dist/components/useHotkey.js +24 -0
  244. package/dist/components/userImage.d.ts +9 -1
  245. package/dist/components/userImage.jsx +10 -3
  246. package/dist/index.d.ts +6 -0
  247. package/dist/index.js +6 -0
  248. package/dist/internal/autoGrow.d.ts +11 -0
  249. package/dist/internal/autoGrow.js +28 -0
  250. package/dist/internal/composer.d.ts +16 -0
  251. package/dist/internal/composer.js +18 -0
  252. package/dist/internal/copyField.d.ts +5 -0
  253. package/dist/internal/copyField.js +61 -0
  254. package/dist/internal/hotkey.d.ts +16 -0
  255. package/dist/internal/hotkey.js +20 -0
  256. package/dist/internal/menu.d.ts +6 -0
  257. package/dist/internal/menu.js +31 -0
  258. package/dist/internal/switch.d.ts +5 -0
  259. package/dist/internal/switch.js +9 -0
  260. package/dist/native-mapping.json +62 -1
  261. package/dist/stories/Button.stories.d.ts +1 -0
  262. package/dist/stories/Button.stories.jsx +17 -1
  263. package/dist/stories/Cases.generated.stories.d.ts +53 -0
  264. package/dist/stories/Cases.generated.stories.jsx +106 -0
  265. package/dist/stories/Composer.stories.d.ts +23 -0
  266. package/dist/stories/Composer.stories.jsx +121 -0
  267. package/dist/stories/CopyField.stories.d.ts +11 -0
  268. package/dist/stories/CopyField.stories.jsx +65 -0
  269. package/dist/stories/FileChip.stories.d.ts +7 -0
  270. package/dist/stories/FileChip.stories.jsx +35 -0
  271. package/dist/stories/FormField.stories.d.ts +6 -0
  272. package/dist/stories/FormField.stories.jsx +44 -0
  273. package/dist/stories/IconButton.stories.d.ts +1 -0
  274. package/dist/stories/IconButton.stories.jsx +18 -1
  275. package/dist/stories/Menu.stories.d.ts +4 -0
  276. package/dist/stories/Menu.stories.jsx +46 -1
  277. package/dist/stories/MenuItem.stories.d.ts +1 -0
  278. package/dist/stories/MenuItem.stories.jsx +8 -0
  279. package/dist/stories/Message.stories.d.ts +10 -0
  280. package/dist/stories/Message.stories.jsx +77 -0
  281. package/dist/stories/Navigation.stories.d.ts +1 -0
  282. package/dist/stories/Navigation.stories.jsx +17 -1
  283. package/dist/stories/PageComponents.stories.d.ts +1 -0
  284. package/dist/stories/PageComponents.stories.jsx +21 -0
  285. package/dist/stories/RadioGroup.stories.d.ts +2 -0
  286. package/dist/stories/RadioGroup.stories.jsx +40 -1
  287. package/dist/stories/SegmentedControl.stories.d.ts +8 -0
  288. package/dist/stories/SegmentedControl.stories.jsx +33 -0
  289. package/dist/stories/SettingsSection.stories.d.ts +11 -0
  290. package/dist/stories/SettingsSection.stories.jsx +64 -0
  291. package/dist/stories/SourceCard.stories.d.ts +8 -0
  292. package/dist/stories/SourceCard.stories.jsx +33 -0
  293. package/dist/stories/StepList.stories.d.ts +8 -0
  294. package/dist/stories/StepList.stories.jsx +35 -0
  295. package/dist/stories/Switch.stories.d.ts +14 -0
  296. package/dist/stories/Switch.stories.jsx +87 -0
  297. package/dist/stories/TextField.stories.d.ts +1 -0
  298. package/dist/stories/TextField.stories.jsx +13 -0
  299. package/dist/stories/UserImage.stories.d.ts +2 -0
  300. package/dist/stories/UserImage.stories.jsx +19 -0
  301. package/package.json +8 -3
@@ -6,9 +6,9 @@ var sizes = {
6
6
  subtitle1: 'text-subtitle1',
7
7
  };
8
8
  export default function Heading(_a) {
9
- var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, id = _a.id, _d = _a.className, className = _d === void 0 ? '' : _d;
9
+ var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, _d = _a.color, color = _d === void 0 ? 'default' : _d, id = _a.id, _e = _a.className, className = _e === void 0 ? '' : _e;
10
10
  var Tag = "h".concat(level);
11
- return (<Tag id={id} className={"".concat(sizes[size], " text-fg-primary ").concat(className)}>
11
+ return (<Tag id={id} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
12
12
  {children}
13
13
  </Tag>);
14
14
  }
@@ -24,6 +24,6 @@ interface IconButtonProps extends React.AriaAttributes {
24
24
  /** With `href` to a path: replace the current history entry instead of adding one */
25
25
  replace?: boolean;
26
26
  }
27
- export default function IconButton({ color, state, size, iconName, icon, onClick, loading, // Default to false
28
- ariaLabel, href, openInNewTab, replace, ...rest }: IconButtonProps): React.JSX.Element;
29
- export {};
27
+ /** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
28
+ declare const IconButton: React.ForwardRefExoticComponent<IconButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
29
+ export default IconButton;
@@ -21,12 +21,13 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
- import React from 'react';
24
+ import React, { forwardRef } from 'react';
25
25
  import NextLink from 'next/link';
26
26
  import IconSlot from './iconSlot';
27
27
  import { LoadingSmall } from './loadingScreen';
28
28
  import { focusRing, pressFeedback, pressFeedbackAny, stateTransition } from './sharedStyles';
29
- export default function IconButton(_a) {
29
+ /** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
30
+ var IconButton = forwardRef(function IconButton(_a, ref) {
30
31
  var color = _a.color, state = _a.state, size = _a.size, iconName = _a.iconName, icon = _a.icon, onClick = _a.onClick, _b = _a.loading, loading = _b === void 0 ? false : _b, // Default to false
31
32
  ariaLabel = _a.ariaLabel, href = _a.href, _c = _a.openInNewTab, openInNewTab = _c === void 0 ? false : _c, replace = _a.replace, rest = __rest(_a, ["color", "state", "size", "iconName", "icon", "onClick", "loading", "ariaLabel", "href", "openInNewTab", "replace"]);
32
33
  var isLink = href !== undefined;
@@ -108,19 +109,20 @@ export default function IconButton(_a) {
108
109
  if (isLink) {
109
110
  // A link cannot be disabled: without an href it is not focusable and does nothing
110
111
  if (isDisabled || loading) {
111
- return (<a {...rest} role="link" aria-disabled="true" className={className} aria-label={loading ? 'Loading' : label}>
112
+ return (<a {...rest} ref={ref} role="link" aria-disabled="true" className={className} aria-label={loading ? 'Loading' : label}>
112
113
  {content}
113
114
  </a>);
114
115
  }
115
116
  var linkProps = __assign(__assign(__assign({}, rest), { className: className, onClick: onClick, 'aria-label': label }), (openInNewTab && { target: '_blank', rel: 'noopener noreferrer' }));
116
117
  // Same rule as Link: next/link for paths, a plain <a> for another site
117
118
  if (href.startsWith('http://') || href.startsWith('https://')) {
118
- return <a href={href} {...linkProps}>{content}</a>;
119
+ return <a href={href} {...linkProps} ref={ref}>{content}</a>;
119
120
  }
120
- return <NextLink href={href} replace={replace} {...linkProps}>{content}</NextLink>;
121
+ return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
121
122
  }
122
- return (<button {...rest} type="button" className={className} disabled={isDisabled || loading} // Disable button during loading
123
+ return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled || loading} // Disable button during loading
123
124
  onClick={onClick} aria-label={loading ? 'Loading' : label}>
124
125
  {content}
125
126
  </button>);
126
- }
127
+ });
128
+ export default IconButton;
@@ -10,7 +10,13 @@ interface StackProps extends LayoutProps {
10
10
  align?: 'stretch' | 'start';
11
11
  }
12
12
  export declare function Stack({ children, gap, align, className }: StackProps): React.JSX.Element;
13
- export declare function Cluster({ children, gap, className }: LayoutProps): React.JSX.Element;
13
+ interface ClusterProps extends LayoutProps {
14
+ /** `between` pushes the first and last child to the ends; `end` packs the row to the right. */
15
+ justify?: 'start' | 'between' | 'end';
16
+ /** `start` lines the children up along the top edge; `center` along the middle. */
17
+ align?: 'center' | 'start';
18
+ }
19
+ export declare function Cluster({ children, gap, justify, align, className }: ClusterProps): React.JSX.Element;
14
20
  interface GridProps extends LayoutProps {
15
21
  /** How many columns from the medium breakpoint up. Below it: two for `compact`, otherwise one. */
16
22
  columns?: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
@@ -13,10 +13,13 @@ export function Stack(_a) {
13
13
  var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'large' : _b, _c = _a.align, align = _c === void 0 ? 'stretch' : _c, _d = _a.className, className = _d === void 0 ? '' : _d;
14
14
  return <div className={"flex flex-col ".concat(align === 'start' ? 'items-start' : '', " ").concat(gaps[gap], " ").concat(className)}>{children}</div>;
15
15
  }
16
+ var clusterJustify = { start: '', between: ' justify-between', end: ' justify-end' };
16
17
  // Things that sit in a row and wrap, a spacing token apart.
17
18
  export function Cluster(_a) {
18
- var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'medium' : _b, _c = _a.className, className = _c === void 0 ? '' : _c;
19
- return <div className={"flex flex-wrap items-center ".concat(gaps[gap], " ").concat(className)}>{children}</div>;
19
+ var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'medium' : _b, _c = _a.justify, justify = _c === void 0 ? 'start' : _c, _d = _a.align, align = _d === void 0 ? 'center' : _d, _e = _a.className, className = _e === void 0 ? '' : _e;
20
+ return (<div className={"flex flex-wrap ".concat(align === 'start' ? 'items-start' : 'items-center', " ").concat(gaps[gap]).concat(clusterJustify[justify], " ").concat(className)}>
21
+ {children}
22
+ </div>);
20
23
  }
21
24
  var mdColumns = {
22
25
  2: 'md:grid-cols-2',
@@ -3,6 +3,27 @@ interface MenuProps {
3
3
  children: React.ReactNode;
4
4
  width?: number | string;
5
5
  className?: string;
6
+ /**
7
+ * Makes the list a keyboard menu (`role="menu"`): on mount it focuses its first item; ArrowDown and
8
+ * ArrowUp move to the next and previous item and wrap, Home and End go to the first and last, and a
9
+ * letter moves to the next item whose label starts with it. The items are the `role="menuitem"`
10
+ * descendants (MenuItem's default role), skipping any with `aria-disabled="true"`. Keys move real
11
+ * focus and leave each item's tabIndex as it is. Open it in a `Popover` with `returnFocus` so Escape,
12
+ * Tab, Shift+Tab and a chosen item close it and give focus back to the trigger. Items with `href` are
13
+ * links without the menuitem role, so the keys skip them: use `onClick` items in a navigable Menu.
14
+ */
15
+ navigable?: boolean;
16
+ /**
17
+ * The list element's role; wins over the `role="menu"` that `navigable` sets. For a suggestion list
18
+ * (mentions, commands) pass `role="listbox"` and an `id` that the text area's `aria-controls` points at,
19
+ * without `navigable`: the Menu then adds no focus or key handling, and the caller drives
20
+ * `MenuItem role="option" isActive` and `aria-activedescendant` itself, as Select does.
21
+ */
22
+ role?: string;
23
+ /** On the list element, for `aria-controls` */
24
+ id?: string;
25
+ /** The list's name, such as 'Message actions'. Set only when the list has a role (`role` or `navigable`). */
26
+ 'aria-label'?: string;
6
27
  }
7
28
  declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLDivElement>>;
8
29
  export default Menu;
@@ -1,11 +1,35 @@
1
1
  'use client';
2
- import React, { forwardRef } from 'react';
2
+ import React, { forwardRef, useEffect, useRef } from 'react';
3
+ import { nextIndex } from '../internal/menu';
4
+ var ITEMS = '[role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"])';
3
5
  var Menu = forwardRef(function (_a, ref) {
4
- var children = _a.children, width = _a.width, _b = _a.className, className = _b === void 0 ? '' : _b;
6
+ var children = _a.children, width = _a.width, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.navigable, navigable = _c === void 0 ? false : _c, role = _a.role, id = _a.id, ariaLabel = _a["aria-label"];
7
+ var listRole = role !== null && role !== void 0 ? role : (navigable ? 'menu' : undefined);
8
+ var listRef = useRef(null);
9
+ var items = function () { var _a, _b; return Array.from((_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(ITEMS)) !== null && _b !== void 0 ? _b : []); };
10
+ // Inside a Popover the Menu mounts once the anchor is set, so this runs as the menu opens
11
+ useEffect(function () {
12
+ var _a;
13
+ if (navigable)
14
+ (_a = items()[0]) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
15
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
16
+ var handleKeyDown = function (e) {
17
+ if (e.altKey || e.ctrlKey || e.metaKey)
18
+ return;
19
+ var list = items();
20
+ var item = e.target.closest('[role="menuitem"], [role="menuitemradio"]');
21
+ var current = item ? list.indexOf(item) : -1;
22
+ var labels = list.map(function (el) { var _a; return (_a = el.textContent) !== null && _a !== void 0 ? _a : ''; });
23
+ var next = nextIndex({ key: e.key, current: current, count: list.length, labels: labels });
24
+ if (next === current || next < 0)
25
+ return;
26
+ e.preventDefault();
27
+ list[next].focus();
28
+ };
5
29
  // dark-only edge: a ring only in dark mode, so it keeps a dark: variant (it follows whatever dark variant the app's preset/@theme defines, class-only or OS-aware)
6
30
  return (<div ref={ref} className={"\n bg-background-overlay\n rounded-container\n shadow-overlay\n dark:ring-1 dark:ring-misc-divider\n overflow-hidden\n ".concat(className, "\n ")} style={{ width: width || 'auto' }}>
7
31
  {/* 4px padding keeps the 8px item corners concentric with the 12px menu corners */}
8
- <div className="p-1 flex flex-col gap-0.5">
32
+ <div ref={listRef} id={id} role={listRole} aria-label={listRole ? ariaLabel : undefined} onKeyDown={navigable ? handleKeyDown : undefined} className="p-1 flex flex-col gap-0.5">
9
33
  {children}
10
34
  </div>
11
35
  </div>);
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  interface MenuItemProps {
3
+ /** Renders the row as a link. The link has no `role`, so a navigable Menu's arrow keys skip it: use `onClick` items there. */
3
4
  href?: string;
4
5
  iconName?: string;
5
6
  icon?: React.ReactNode;
@@ -19,13 +20,22 @@ interface MenuItemProps {
19
20
  };
20
21
  iconRight?: string;
21
22
  rightAction?: React.ReactNode;
22
- /** ARIA role; Select passes 'option'. Defaults to 'menuitem'. */
23
+ /** ARIA role; Select passes 'option'. Defaults to 'menuitem'. Pass 'menuitemradio' for one current choice among several: `isSelected` then sets `aria-checked`. */
23
24
  role?: string;
24
25
  id?: string;
25
26
  /** Keyboard highlight used by Select's listbox */
26
27
  isActive?: boolean;
28
+ /**
29
+ * Only with `role="option"`: wins over the `aria-selected` computed from `isSelected`. In a suggestion
30
+ * list (mentions, commands) pass `aria-selected={isActive}` so it follows the highlighted row.
31
+ */
32
+ 'aria-selected'?: boolean;
27
33
  /** Select keeps focus on its trigger and passes -1 */
28
34
  tabIndex?: number;
35
+ /** `danger` gives the label and the left icon the error text color, for Delete and the like. `isSelected` wins over it. */
36
+ color?: 'default' | 'danger';
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
+ 'aria-current'?: 'page' | boolean;
29
39
  }
30
- export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, tabIndex, }: MenuItemProps): React.JSX.Element;
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;
31
41
  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, _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g;
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"];
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];
@@ -15,9 +15,10 @@ export default function MenuItem(_a) {
15
15
  // One step smaller than the row so a tag never makes its row taller
16
16
  var tagSize = { tiny: 'tiny', small: 'tiny', medium: 'small' }[size];
17
17
  var paddingClass = size === 'tiny' ? 'p-1' : 'p-2';
18
+ var danger = color === 'danger' && !isSelected;
18
19
  var content = (<div id={id} role={href ? undefined : role}
19
20
  // A link wrapper is already focusable; otherwise the row itself takes focus
20
- tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? !!isSelected : undefined} 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} 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
22
  ? 'bg-primary-dark text-primary-contrast'
22
23
  : "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
23
24
  if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
@@ -27,9 +28,9 @@ export default function MenuItem(_a) {
27
28
  }}>
28
29
  {/* Left group: icon/userImg + label with 8px gap */}
29
30
  <div className="flex items-center gap-2 min-w-0">
30
- {userImgUrl ? (<UserImage userHandle={userHandle || ''} userImgUrl={userImgUrl}/>) : icon ? (<span className={"".concat(iconSize, " flex-shrink-0 flex items-center justify-center")}>{icon}</span>) : (<IconSlot icon={iconName} className={"".concat(iconSize, " flex-shrink-0 ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-secondary')}/>)}
31
+ {userImgUrl ? (<UserImage userHandle={userHandle || ''} userImgUrl={userImgUrl}/>) : icon ? (<span className={"".concat(iconSize, " flex-shrink-0 flex items-center justify-center").concat(danger ? ' text-error-text' : '')}>{icon}</span>) : (<IconSlot icon={iconName} className={"".concat(iconSize, " flex-shrink-0 ").concat(isSelected ? 'text-primary-contrast' : danger ? 'text-error-text' : 'text-fg-secondary')}/>)}
31
32
  <div className="flex flex-col min-w-0">
32
- <span className={"truncate ".concat(labelClass, " ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-primary')}>
33
+ <span className={"truncate ".concat(labelClass, " ").concat(isSelected ? 'text-primary-contrast' : danger ? 'text-error-text' : 'text-fg-primary')}>
33
34
  {label}
34
35
  </span>
35
36
  {secondLabel && (<span className={"truncate ".concat(secondLabelClass, " opacity-70 ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-primary')}>
@@ -49,5 +50,5 @@ export default function MenuItem(_a) {
49
50
  </div>)}
50
51
  </div>
51
52
  </div>);
52
- return href ? <NextLink href={href} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
53
+ return href ? <NextLink href={href} aria-current={ariaCurrent} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
53
54
  }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ interface MessageProps {
3
+ /** A `UserImage`, in a 24px slot on the left. Not shown when `compact`. */
4
+ avatar?: React.ReactNode;
5
+ /** The sender, at the start of the header line */
6
+ name?: string;
7
+ /** Shown after the name on the header line: a `Tag`, a model line, a `TimeStamp` */
8
+ meta?: React.ReactNode;
9
+ /** The body */
10
+ children: React.ReactNode;
11
+ /** Under the body: sources, attachments, reactions */
12
+ footer?: React.ReactNode;
13
+ /** A row of `IconButton`s at the top right. Shown while the pointer is on the row or focus is inside it, and always on a device without hover.
14
+ * Keep them to quick actions; a control that must always be visible, such as Stop, belongs in `footer`. */
15
+ actions?: React.ReactNode;
16
+ /** Shows the actions at all times, for example while a menu opened from one of them is open, so its button stays on screen */
17
+ actionsVisible?: boolean;
18
+ /** A follow-on message from the same sender: no avatar and no header; the body lines up with the one above */
19
+ compact?: boolean;
20
+ /** `highlight` gives the row the accent100 background, for a search hit or a mention */
21
+ tone?: 'default' | 'highlight';
22
+ /** Pass it on every row, compact ones too, with the sender and the time: a compact row shows neither. */
23
+ 'aria-label'?: string;
24
+ /** On the row, so a search hit can scroll to it */
25
+ id?: string;
26
+ }
27
+ export default function Message({ avatar, name, meta, children, footer, actions, actionsVisible, compact, tone, 'aria-label': ariaLabel, id, }: MessageProps): React.JSX.Element;
28
+ export {};
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { stateTransition } from './sharedStyles';
3
+ var tones = { default: '', highlight: ' bg-background-accent100' };
4
+ // Opacity only: the actions stay in the tab order, so focus inside the row can reveal them,
5
+ // and they take their space at all times, so showing them moves nothing.
6
+ var actionsReveal = 'opacity-0 group-hover/message:opacity-100 group-focus-within/message:opacity-100 [@media(hover:none)]:opacity-100';
7
+ // One message in a chat list. The list that holds the rows owns `role="log"` (or `feed`), not the row.
8
+ // A named group, so `group-hover:` marks inside the body (RadioGroup, Checkbox) ignore the row,
9
+ // and an outer `.group` does not reveal the actions.
10
+ export default function Message(_a) {
11
+ var avatar = _a.avatar, name = _a.name, meta = _a.meta, children = _a.children, footer = _a.footer, actions = _a.actions, _b = _a.actionsVisible, actionsVisible = _b === void 0 ? false : _b, _c = _a.compact, compact = _c === void 0 ? false : _c, _d = _a.tone, tone = _d === void 0 ? 'default' : _d, ariaLabel = _a["aria-label"], id = _a.id;
12
+ var header = !compact && (name || meta);
13
+ return (<article id={id} aria-label={ariaLabel} className={"group/message flex items-start gap-medium px-2 py-1 rounded-control".concat(tones[tone])}>
14
+ <div className="flex-shrink-0 w-6">{compact ? null : avatar}</div>
15
+ <div className="flex flex-col flex-1 min-w-0 gap-small">
16
+ {header && (<div className="flex flex-wrap items-center gap-medium">
17
+ {name && <span className="min-w-0 break-words text-body1 font-medium text-fg-primary">{name}</span>}
18
+ {meta}
19
+ </div>)}
20
+ <div className="break-words">{children}</div>
21
+ {footer && <div>{footer}</div>}
22
+ </div>
23
+ {actions && <div className={"flex flex-shrink-0 items-center gap-small ".concat(actionsVisible ? '' : "".concat(actionsReveal, " ")).concat(stateTransition)}>{actions}</div>}
24
+ </article>);
25
+ }
@@ -2,6 +2,14 @@ import React from 'react';
2
2
  interface NavigationProps {
3
3
  children: React.ReactNode;
4
4
  className?: string;
5
+ /** Names the landmark when a page has more than one nav, e.g. "Settings". */
6
+ 'aria-label'?: string;
5
7
  }
6
- export default function Navigation({ children, className, }: NavigationProps): React.JSX.Element;
8
+ export default function Navigation({ children, className, 'aria-label': ariaLabel, }: NavigationProps): React.JSX.Element;
9
+ interface NavigationGroupProps {
10
+ /** The small label above the items. It names the group for a screen reader. */
11
+ label: string;
12
+ children: React.ReactNode;
13
+ }
14
+ export declare function NavigationGroup({ label, children }: NavigationGroupProps): React.JSX.Element;
7
15
  export { Navigation };
@@ -1,9 +1,21 @@
1
1
  'use client';
2
- import React from 'react';
2
+ import React, { useId } from 'react';
3
3
  export default function Navigation(_a) {
4
- var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b;
5
- return (<nav className={"\n bg-background-default\n border-r border-misc-divider\n p-2 flex flex-col gap-0.5\n ".concat(className, "\n ")}>
4
+ var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, ariaLabel = _a["aria-label"];
5
+ return (<nav aria-label={ariaLabel} className={"\n bg-background-default\n border-r border-misc-divider\n p-2 flex flex-col gap-0.5\n ".concat(className, "\n ")}>
6
6
  {children}
7
7
  </nav>);
8
8
  }
9
+ // A labelled set of items inside a Navigation. A `role="group"` suits it because Navigation's
10
+ // items are rows, not a list: the group needs no list markup, and it keeps the label tied to them.
11
+ export function NavigationGroup(_a) {
12
+ var label = _a.label, children = _a.children;
13
+ var labelId = useId();
14
+ return (<div role="group" aria-labelledby={labelId} className="flex flex-col gap-0.5 mt-3 first:mt-0">
15
+ <div id={labelId} className="px-2 pb-1 text-caption text-fg-secondary">
16
+ {label}
17
+ </div>
18
+ {children}
19
+ </div>);
20
+ }
9
21
  export { Navigation };
@@ -8,6 +8,8 @@ interface ParagraphProps {
8
8
  /** Set in the mono face, for labels, numbers and dates. */
9
9
  mono?: boolean;
10
10
  className?: string;
11
+ /** On the `<p>`, so a field can point at this line with `aria-describedby` */
12
+ id?: string;
11
13
  }
12
- export default function Paragraph({ children, tone, size, measure, mono, className, }: ParagraphProps): React.JSX.Element;
14
+ export default function Paragraph({ children, tone, size, measure, mono, className, id, }: ParagraphProps): React.JSX.Element;
13
15
  export {};
@@ -9,8 +9,8 @@ var measures = {
9
9
  none: '',
10
10
  };
11
11
  export default function Paragraph(_a) {
12
- var children = _a.children, _b = _a.tone, tone = _b === void 0 ? 'primary' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.measure, measure = _d === void 0 ? 'body' : _d, _e = _a.mono, mono = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? '' : _f;
13
- return (<p className={"".concat(sizes[size], " ").concat(tones[tone], " ").concat(measures[measure], " ").concat(mono ? 'font-mono' : '', " ").concat(className)}>
12
+ var children = _a.children, _b = _a.tone, tone = _b === void 0 ? 'primary' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.measure, measure = _d === void 0 ? 'body' : _d, _e = _a.mono, mono = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? '' : _f, id = _a.id;
13
+ return (<p id={id} className={"".concat(sizes[size], " ").concat(tones[tone], " ").concat(measures[measure], " ").concat(mono ? 'font-mono' : '', " ").concat(className)}>
14
14
  {children}
15
15
  </p>);
16
16
  }
@@ -5,6 +5,12 @@ interface PopoverProps {
5
5
  open: boolean;
6
6
  onClose: () => void;
7
7
  children: React.ReactNode;
8
+ /**
9
+ * When the Popover closes (Escape, a click outside, or `open` going false), focus goes back to
10
+ * `anchorEl` if it was inside the Popover or nowhere (on the body). Tab or Shift+Tab pressed inside the
11
+ * Popover also closes it (`onClose`) and focuses `anchorEl`. Pass the focusable trigger as `anchorEl`.
12
+ */
13
+ returnFocus?: boolean;
8
14
  }
9
- export default function Popover({ id, anchorEl, open, onClose, children, }: PopoverProps): React.ReactPortal | null;
15
+ export default function Popover({ id, anchorEl, open, onClose, children, returnFocus, }: PopoverProps): React.ReactPortal | null;
10
16
  export {};
@@ -1,22 +1,22 @@
1
1
  'use client';
2
- import React, { useState, useEffect, isValidElement } from 'react';
2
+ import React, { useState, useEffect, useRef, isValidElement } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  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
8
  export default function Popover(_a) {
9
- var id = _a.id, anchorEl = _a.anchorEl, open = _a.open, onClose = _a.onClose, children = _a.children;
10
- var _b = useState(null), popoverElement = _b[0], setPopoverElement = _b[1];
11
- var _c = useState(false), hasMounted = _c[0], setHasMounted = _c[1];
12
- var _d = useOverlayTransition(open), mounted = _d.mounted, visible = _d.visible;
9
+ 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
+ var _c = useState(null), popoverElement = _c[0], setPopoverElement = _c[1];
11
+ var _d = useState(false), hasMounted = _d[0], setHasMounted = _d[1];
12
+ var _e = useOverlayTransition(open), mounted = _e.mounted, visible = _e.visible;
13
13
  // Initialize Popper.js
14
- var _e = usePopper(anchorEl, popoverElement, {
14
+ var _f = usePopper(anchorEl, popoverElement, {
15
15
  placement: 'bottom-start', // Default placement, can be customized
16
16
  modifiers: [
17
17
  { name: 'offset', options: { offset: [0, 4] } }, // Same 4px gap as the Select menu and Tooltip
18
18
  ],
19
- }), styles = _e.styles, attributes = _e.attributes;
19
+ }), styles = _f.styles, attributes = _f.attributes;
20
20
  // Close on outside clicks and Escape. Clicks on the anchor are left to the
21
21
  // anchor's own toggle, otherwise the popover would close and reopen.
22
22
  useEffect(function () {
@@ -27,8 +27,19 @@ export default function Popover(_a) {
27
27
  }
28
28
  };
29
29
  var handleKeyDown = function (event) {
30
- if (event.key === 'Escape')
30
+ if (event.key === 'Escape') {
31
+ // Close only the Popover: keep this Escape from reaching a Modal's window listener
32
+ event.stopPropagation();
31
33
  onClose();
34
+ }
35
+ else if (event.key === 'Tab' && returnFocus && anchorEl && (popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(event.target))) {
36
+ // Tab or Shift+Tab leaves the Popover: close it and give focus back to the anchor, before a Modal's
37
+ // Tab trap or the browser moves it somewhere else (the Popover is portaled to the end of the body)
38
+ event.preventDefault();
39
+ event.stopPropagation();
40
+ anchorEl.focus();
41
+ onClose();
42
+ }
32
43
  };
33
44
  if (open) {
34
45
  document.addEventListener('mousedown', handleClickOutside);
@@ -38,7 +49,22 @@ export default function Popover(_a) {
38
49
  document.removeEventListener('mousedown', handleClickOutside);
39
50
  document.removeEventListener('keydown', handleKeyDown);
40
51
  };
41
- }, [open, anchorEl, popoverElement, onClose]);
52
+ }, [open, anchorEl, popoverElement, onClose, returnFocus]);
53
+ // On close, wait one task so a click outside has moved focus first: a click on something
54
+ // focusable keeps it there; a click on nothing leaves it on the body, and then the anchor takes it.
55
+ var wasOpen = useRef(open);
56
+ useEffect(function () {
57
+ var closed = wasOpen.current && !open;
58
+ wasOpen.current = open;
59
+ if (!closed || !returnFocus || !anchorEl)
60
+ return;
61
+ var timer = setTimeout(function () {
62
+ var active = document.activeElement;
63
+ if (!active || active === document.body || (popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(active)))
64
+ anchorEl.focus();
65
+ }, 0);
66
+ return function () { return clearTimeout(timer); };
67
+ }, [open]); // eslint-disable-line react-hooks/exhaustive-deps
42
68
  // Ensure popover is only rendered after the component mounts
43
69
  useEffect(function () {
44
70
  setHasMounted(true);
@@ -3,13 +3,24 @@ interface RadioOption {
3
3
  label: string;
4
4
  secondLabel?: string;
5
5
  value: string;
6
+ /** In the `card` variant, a small info tag beside the label, e.g. "Recommended" */
7
+ badge?: string;
8
+ disabled?: boolean;
6
9
  }
7
10
  interface RadioGroupProps {
8
11
  options: RadioOption[];
9
12
  selectedValue: string;
10
13
  onChange: (value: string) => void;
11
14
  direction?: 'horizontal' | 'vertical';
15
+ /** On the `radiogroup` element, so a `FormField` label and help text can point at it */
16
+ id?: string;
12
17
  'aria-label'?: string;
18
+ /** Id of the element that describes the group, e.g. help or error text */
19
+ 'aria-describedby'?: string;
20
+ /** `card` draws each option as a bordered card that is the radio's label, with the selected one in the accent border */
21
+ variant?: 'default' | 'card';
22
+ /** Disables every option */
23
+ disabled?: boolean;
13
24
  }
14
- export default function RadioGroup({ options, selectedValue, onChange, direction, 'aria-label': ariaLabel, }: RadioGroupProps): React.JSX.Element;
25
+ export default function RadioGroup({ options, selectedValue, onChange, direction, id, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, variant, disabled, }: RadioGroupProps): React.JSX.Element;
15
26
  export {};
@@ -1,17 +1,22 @@
1
1
  'use client';
2
2
  import React, { useId } from 'react';
3
3
  import { popTransition, stateTransition } from './sharedStyles';
4
+ import Tag from './tag';
4
5
  export default function RadioGroup(_a) {
5
- var options = _a.options, selectedValue = _a.selectedValue, onChange = _a.onChange, _b = _a.direction, direction = _b === void 0 ? 'vertical' : _b, ariaLabel = _a["aria-label"];
6
+ var options = _a.options, selectedValue = _a.selectedValue, onChange = _a.onChange, _b = _a.direction, direction = _b === void 0 ? 'vertical' : _b, id = _a.id, ariaLabel = _a["aria-label"], ariaDescribedBy = _a["aria-describedby"], _c = _a.variant, variant = _c === void 0 ? 'default' : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d;
6
7
  // One shared name gives native arrow-key movement between the options
7
8
  var groupName = useId();
8
- return (<div role="radiogroup" aria-label={ariaLabel} className={"flex ".concat(direction === 'horizontal' ? 'gap-4' : 'flex-col gap-2')}>
9
+ return (<div role="radiogroup" id={id} aria-label={ariaLabel} aria-describedby={ariaDescribedBy} className={"flex ".concat(direction === 'horizontal' ? 'gap-4' : 'flex-col gap-2')}>
9
10
  {options.map(function (option) {
10
11
  var isSelected = selectedValue === option.value;
11
- return (<label key={option.value} className="group relative flex items-start cursor-pointer">
12
- <input type="radio" name={groupName} value={option.value} checked={isSelected} onChange={function () { return onChange(option.value); }} className="peer sr-only"/>
12
+ var isDisabled = disabled || !!option.disabled;
13
+ var isCard = variant === 'card';
14
+ return (<label key={option.value} className={"group relative flex items-start ".concat(isCard ? "gap-2 rounded-control border-2 p-3 ".concat(isSelected ? 'border-accent-main' : 'border-fg-disabled', " ") : '').concat(isDisabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer')}>
15
+ <input type="radio" name={groupName} value={option.value} checked={isSelected} disabled={isDisabled || undefined} onChange={function () { return onChange(option.value); }} className="peer sr-only"/>
16
+ {/* Keyboard focus rings the card just outside its border, so a selected card keeps its accent border */}
17
+ {isCard && (<span aria-hidden="true" className="pointer-events-none absolute inset-0 rounded-control peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-fg-primary"/>)}
13
18
  {/* Hover halo and hit area, same as Checkbox */}
14
- <span className={"relative flex flex-shrink-0 items-center justify-center w-6 h-6 rounded-full ".concat(stateTransition, "\n group-hover:bg-action-selected\n peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-0 peer-focus-visible:outline-fg-primary")}>
19
+ <span className={"relative flex flex-shrink-0 items-center justify-center w-6 h-6 rounded-full ".concat(stateTransition, "\n ").concat(isDisabled ? '' : 'group-hover:bg-action-selected', "\n peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-0 peer-focus-visible:outline-fg-primary")}>
15
20
  {/* outer circle */}
16
21
  <span className={"relative flex justify-center items-center w-4 h-4 rounded-full border-2 ".concat(stateTransition, "\n ").concat(isSelected
17
22
  ? 'border-fg-primary'
@@ -20,10 +25,16 @@ export default function RadioGroup(_a) {
20
25
  <span className={"absolute w-2 h-2 rounded-full bg-fg-primary ".concat(popTransition, " ").concat(isSelected ? 'scale-100' : 'scale-0')}/>
21
26
  </span>
22
27
  </span>
23
- <span className="flex flex-col ml-2">
24
- <span className="text-body1 text-fg-primary">{option.label}</span>
25
- {option.secondLabel && (<span className="text-body2 opacity-70 text-fg-primary">{option.secondLabel}</span>)}
26
- </span>
28
+ {isCard ? (<span className="flex flex-col flex-1">
29
+ <span className="flex flex-wrap items-center gap-2">
30
+ <span className="text-body1 font-medium text-fg-primary">{option.label}</span>
31
+ {option.badge && <Tag variant="contained" size="small" color="info" label={option.badge}/>}
32
+ </span>
33
+ {option.secondLabel && (<span className="text-body2 opacity-70 text-fg-primary">{option.secondLabel}</span>)}
34
+ </span>) : (<span className="flex flex-col ml-2">
35
+ <span className="text-body1 text-fg-primary">{option.label}</span>
36
+ {option.secondLabel && (<span className="text-body2 opacity-70 text-fg-primary">{option.secondLabel}</span>)}
37
+ </span>)}
27
38
  </label>);
28
39
  })}
29
40
  </div>);
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ interface SegmentedControlProps {
3
+ options: {
4
+ value: string;
5
+ label: string;
6
+ }[];
7
+ /** The selected option's value. The control stays controlled: it shows `value` until the parent changes it. */
8
+ value: string;
9
+ onChange: (value: string) => void;
10
+ /** Names the group, e.g. "Range". Required: the options alone do not say what they choose. */
11
+ 'aria-label': string;
12
+ size?: 'medium' | 'small' | 'tiny';
13
+ /** `fill` takes the width of its container. `fit` is as wide as its options, for a control that sits beside a heading. */
14
+ width?: 'fill' | 'fit';
15
+ }
16
+ /**
17
+ * A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
18
+ * Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
19
+ * selected option is in the tab order.
20
+ */
21
+ export default function SegmentedControl({ options, value, onChange, 'aria-label': ariaLabel, size, width, }: SegmentedControlProps): React.JSX.Element;
22
+ export { SegmentedControl };
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ import React, { useRef } from 'react';
3
+ import { SlidingPill, segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes, segmentTrackClasses, segmentTrackStyle, useSlidingIndicator, } from './slidingIndicator';
4
+ /**
5
+ * A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
6
+ * Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
7
+ * selected option is in the tab order.
8
+ */
9
+ export default function SegmentedControl(_a) {
10
+ var options = _a.options, value = _a.value, onChange = _a.onChange, ariaLabel = _a["aria-label"], _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.width, width = _c === void 0 ? 'fill' : _c;
11
+ var _d = useSlidingIndicator(options), containerRef = _d.containerRef, indicator = _d.indicator;
12
+ var refs = useRef([]);
13
+ var sizeClasses = segmentSizes[size];
14
+ var selectedIndex = options.findIndex(function (o) { return o.value === value; });
15
+ // With no match the first option is the way in
16
+ var tabStop = selectedIndex === -1 ? 0 : selectedIndex;
17
+ var move = function (to) {
18
+ var _a;
19
+ (_a = refs.current[to]) === null || _a === void 0 ? void 0 : _a.focus();
20
+ onChange(options[to].value);
21
+ };
22
+ var handleKeyDown = function (e) {
23
+ var current = refs.current.findIndex(function (el) { return el === document.activeElement; });
24
+ if (current === -1 || options.length === 0)
25
+ return;
26
+ var last = options.length - 1;
27
+ var next = {
28
+ ArrowRight: current === last ? 0 : current + 1,
29
+ ArrowDown: current === last ? 0 : current + 1,
30
+ ArrowLeft: current === 0 ? last : current - 1,
31
+ ArrowUp: current === 0 ? last : current - 1,
32
+ Home: 0,
33
+ End: last,
34
+ }[e.key];
35
+ if (next === undefined)
36
+ return;
37
+ e.preventDefault();
38
+ move(next);
39
+ };
40
+ return (<div ref={containerRef} role="radiogroup" aria-label={ariaLabel} onKeyDown={handleKeyDown} className={segmentTrackClasses(width === 'fill', options.length > 0)} style={segmentTrackStyle}>
41
+ <SlidingPill indicator={indicator}/>
42
+ {options.map(function (option, i) {
43
+ var selected = i === selectedIndex;
44
+ return (<button key={option.value} ref={function (el) {
45
+ refs.current[i] = el;
46
+ }} type="button" role="radio" aria-checked={selected} tabIndex={i === tabStop ? 0 : -1} data-tab-selected={selected} onClick={function () { return onChange(option.value); }} className={segmentItemClasses(width === 'fill', sizeClasses.tab, selected ? segmentSelectedClasses : segmentIdleClasses)}>
47
+ <div className={"flex flex-col text-center ".concat(sizeClasses.label)}>
48
+ <span className="whitespace-nowrap">{option.label}</span>
49
+ </div>
50
+ </button>);
51
+ })}
52
+ </div>);
53
+ }
54
+ export { SegmentedControl };