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
package/dist/cases.json CHANGED
@@ -27,17 +27,13 @@
27
27
  "Do not show the login form before the invite is checked.",
28
28
  "Do not remember the invite before the person chooses to log in or sign up, so an old link does not take over a later login."
29
29
  ],
30
- "native": "On Apple, Scindo joins from a sheet with the invite link or code in a field. 'Cancel' and 'Join' sit in the toolbar. While it checks the invite, a small `ProgressView` sits beside a line naming the step.",
31
- "notBuiltYet": "Scindo on the web labels its Buttons 'Log in' and 'Create account' in sentence case, and shows 'Please wait' under its spinner. Its wrong-account Button reads 'Sign out and switch accounts'.",
32
- "seenIn": [
33
- "Scindo"
34
- ],
30
+ "native": "On Apple, joining works from a sheet with the invite link or code in a field. 'Cancel' and 'Join' sit in the toolbar. While it checks the invite, a small `ProgressView` sits beside a line naming the step.",
35
31
  "options": [
36
32
  {
37
33
  "id": "signed-out",
38
34
  "title": "Logged out",
39
35
  "useWhen": "The person is not logged in.",
40
- "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so login and sign-up bring the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\nexport default function AcceptInviteSignedOut() {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n {/* 'Invited by' shows on every invite. */}\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* The address sentence shows only when the invite is tied to an address, and the address is masked: anyone who holds the link sees this page.\n An open link shows nothing in its place, only the workspace and the role: 'You will join as a member.' */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member. This invite is for a***@example.com, so log in or sign up with that address.</Paragraph>\n </Stack>\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => router.push(`/login?next=${next}`)} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Sign Up\" onClickButton={() => router.push(`/sign-up?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
36
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so login and sign-up bring the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\nexport default function AcceptInviteSignedOut() {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n {/* 'Invited by' shows on every invite. */}\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" decorative />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* The address sentence shows only when the invite is tied to an address, and the address is masked: anyone who holds the link sees this page.\n An open link shows nothing in its place, only the workspace and the role: 'You will join as a member.' */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member. This invite is for a***@example.com, so log in or sign up with that address.</Paragraph>\n </Stack>\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => router.push(`/login?next=${next}`)} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Sign Up\" onClickButton={() => router.push(`/sign-up?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
41
37
  "uses": [
42
38
  "Button",
43
39
  "Center",
@@ -53,7 +49,7 @@
53
49
  "id": "signed-in",
54
50
  "title": "Logged in, open link",
55
51
  "useWhen": "The person is logged in and the link is open to anyone who has it.",
56
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so switching accounts brings the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\n// A real app passes the address of the account that is logged in.\nconst address = 'ada@example.com';\n\nexport default function AcceptInviteSignedIn() {\n const [joining, setJoining] = useState(false);\n const [joined, setJoined] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleJoin() {\n if (joining) return;\n setJoining(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setJoining(false);\n setJoined(true);\n }, 1200);\n }\n\n // Joined: a real app opens the workspace as soon as it can.\n if (joined) {\n return (\n <Center fill>\n <LoadingScreen label=\"Opening Acme Design…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* An open link names no address, so the page shows only the workspace and the role. */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Joining as {address}</Paragraph>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Join Acme Design\" loading={joining} onClickButton={handleJoin} />\n <Button size=\"medium\" type=\"textOnly\" state={joining ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push(`/login?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
52
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so switching accounts brings the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\n// A real app passes the address of the account that is logged in.\nconst address = 'ada@example.com';\n\nexport default function AcceptInviteSignedIn() {\n const [joining, setJoining] = useState(false);\n const [joined, setJoined] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleJoin() {\n if (joining) return;\n setJoining(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setJoining(false);\n setJoined(true);\n }, 1200);\n }\n\n // Joined: a real app opens the workspace as soon as it can.\n if (joined) {\n return (\n <Center fill>\n <LoadingScreen label=\"Opening Acme Design…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" decorative />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* An open link names no address, so the page shows only the workspace and the role. */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Joining as {address}</Paragraph>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Join Acme Design\" loading={joining} onClickButton={handleJoin} />\n <Button size=\"medium\" type=\"textOnly\" state={joining ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push(`/login?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
57
53
  "uses": [
58
54
  "Button",
59
55
  "Center",
@@ -68,6 +64,54 @@
68
64
  }
69
65
  ]
70
66
  },
67
+ {
68
+ "id": "account-menu",
69
+ "title": "Account menu",
70
+ "kind": "design",
71
+ "level": "organism",
72
+ "area": "menu",
73
+ "situation": "A person opens a menu for their own account to change settings, get help or log out.",
74
+ "do": [
75
+ "Use a small tertiary `Button` whose label is the person's name, with their `UserImage` as `decoIcon`: `decoIcon={<UserImage userHandle={name} size={20} decorative />}`.",
76
+ "Make the avatar `decorative`. It sits beside the same name, so a screen reader reads the name once.",
77
+ "Give the Button an `aria-label` that starts with the visible name: 'Dana Lee, account menu'.",
78
+ "Set `aria-haspopup=\"menu\"` and `aria-expanded` on the Button, and `state=\"selected\"` while the menu is open.",
79
+ "Open `<Popover returnFocus>` around `<Menu navigable aria-label=\"Account\">` with 'Settings' and 'Help', then a `Line`, then 'Log Out' last.",
80
+ "Use `onClick` items. A navigable menu's arrow keys skip an item with `href`.",
81
+ "Leave 'Log Out' a plain item. It destroys nothing.",
82
+ "Confirm 'Log Out' as the case 'Log-out confirm' says, in a small Modal. 'Cancel' puts focus back on the Button."
83
+ ],
84
+ "dont": [
85
+ "Do not show only the avatar as the trigger when the name fits. The name says whose account it is.",
86
+ "Do not give the avatar its own name beside the same name.",
87
+ "Do not use 'Sign Out'. The words are 'Log In' and 'Log Out'.",
88
+ "Do not give 'Log Out' `color=\"danger\"`.",
89
+ "Do not open the menu when the page loads."
90
+ ],
91
+ "native": "On Apple use a toolbar `Menu` with a `Label` of the person's name, or the sidebar's account row. Put 'Log Out' last, and leave out the `.destructive` role. On Android use an avatar `IconButton` with a `DropdownMenu`.",
92
+ "options": [
93
+ {
94
+ "id": "menu",
95
+ "title": "Avatar and name with a menu",
96
+ "useWhen": "The product has an account, and its header or sidebar has room for a name.",
97
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AccountMenuExample() {\n const [view, setView] = useState('Home');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const trigger = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // The menu closes on any choice. Its Popover gives focus back to the trigger.\n function go(next: string) {\n setOpen(false);\n setView(next);\n }\n\n // The confirm is the one in the case 'Log-out confirm'. Its Modal opens while the menu fades, so the Modal cannot\n // take focus back from the menu item: 'Cancel' sends it to the trigger.\n function askToLogOut() {\n setOpen(false);\n setConfirming(true);\n }\n\n function cancel() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => trigger.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setView('Home'); }} />\n </Cluster>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Acme</Heading>\n {/* The avatar and the name are the trigger. The avatar sits beside the same name, so it is not read aloud. */}\n <Button\n ref={trigger}\n size=\"small\"\n type=\"tertiary\"\n state={open ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClickButton={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{view === 'Home' ? 'Logged in as dana@example.com.' : `You opened ${view}.`}</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => go('Settings')} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => go('Help')} />\n <Line />\n {/* Log Out is last. It destroys nothing, so it is a plain item, not a danger one. */}\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={askToLogOut} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancel}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancel} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
98
+ "uses": [
99
+ "Button",
100
+ "Center",
101
+ "Cluster",
102
+ "Heading",
103
+ "Line",
104
+ "Menu",
105
+ "MenuItem",
106
+ "Modal",
107
+ "Paragraph",
108
+ "Popover",
109
+ "Stack",
110
+ "UserImage"
111
+ ]
112
+ }
113
+ ]
114
+ },
71
115
  {
72
116
  "id": "agent-asks-before-risky-action",
73
117
  "title": "An agent asks before a risky action",
@@ -88,10 +132,6 @@
88
132
  "Do not replace the steps or the changes with a one-line summary.",
89
133
  "Do not let the agent write the label of an approve or merge button.",
90
134
  "Do not let a second click on a decided card approve or cancel it again."
91
- ],
92
- "notBuiltYet": "In Scindo the agent asks before carrying out a plan, opening a pull request and merging one. It does not yet ask before deleting files, closing an issue or rolling back a release.",
93
- "seenIn": [
94
- "Scindo"
95
135
  ]
96
136
  },
97
137
  {
@@ -112,10 +152,305 @@
112
152
  "dont": [
113
153
  "Do not treat no answer as approval.",
114
154
  "Do not cancel a request without saying so in the thread."
155
+ ]
156
+ },
157
+ {
158
+ "id": "agent-options",
159
+ "title": "Agent options",
160
+ "kind": "design",
161
+ "level": "organism",
162
+ "area": "agent",
163
+ "situation": "The agent sees two to four ways forward and needs the person to pick one. These are ways forward for the agent's own work. For a fact or a decision only the person has, see the case 'Agent question'.",
164
+ "do": [
165
+ "Put the card in the agent's `Message`, in a `Surface` with the question as its heading.",
166
+ "Show each way forward as an option of `<RadioGroup variant=\"card\">`, with a `secondLabel` that says what it means.",
167
+ "Give the agent's pick the `badge` 'Recommended', on one option only.",
168
+ "Preselect the recommended option: the agent has a view, and the person can pick another. With no recommended option, preselect nothing.",
169
+ "Disable 'Choose' until an option is picked when nothing is preselected.",
170
+ "Give the RadioGroup an `aria-label` that starts with the question.",
171
+ "Order the buttons 'Cancel', then 'Choose' as the primary Button, at the start of the row.",
172
+ "Make the pressed Button `loading` and keep its label. Disable the options and the other Button while the request runs.",
173
+ "Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
174
+ "Show the waiting time on the card while it waits: 'Waits 10 more minutes, then cancels.'",
175
+ "Notify the person who asked when the agent needs their answer.",
176
+ "Keep only the chosen option once it is decided, as text, with a 'Chosen' `Tag`. Remove the buttons.",
177
+ "Mark the card with a 'Cancelled' `Tag` when it is cancelled, and add one compact agent row under it that says what was not done: 'Cancelled. Nothing was changed.'",
178
+ "Mark the card Cancelled when the waiting time is up, with the same row on what was not done.",
179
+ "Announce the decided `Tag` politely: the app wraps it in a polite live region.",
180
+ "Move focus to the message box once the card is decided, since its buttons are gone."
181
+ ],
182
+ "dont": [
183
+ "Do not offer one option, or more than four.",
184
+ "Do not give more than one option the 'Recommended' badge.",
185
+ "Do not preselect an option the agent does not recommend.",
186
+ "Do not recommend or preselect an option that does more than the others, such as one that deletes, publishes or widens access.",
187
+ "Do not act on an option before the person presses Choose.",
188
+ "Do not change a Button's label while it is loading, such as to 'Confirming...'."
189
+ ],
190
+ "options": [
191
+ {
192
+ "id": "cards",
193
+ "title": "Option cards",
194
+ "useWhen": "The default: each way forward is a card with a line on what it means.",
195
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Surface from 'oneslash-design-system/components/surface';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\nconst question = 'Which layout should the pricing page use?';\n\nconst options = [\n { value: 'columns', label: 'Three columns', secondLabel: 'One card per plan, side by side. Easy to compare.', badge: 'Recommended' },\n { value: 'table', label: 'Table', secondLabel: 'Plans as columns and features as rows.' },\n { value: 'switch', label: 'One plan at a time', secondLabel: 'A switch moves between the plans.' },\n];\n\ntype Status = 'open' | 'chosen' | 'cancelled';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentOptionsCards() {\n // The recommended option starts selected: the agent has a view, and the person can pick another.\n const [selected, setSelected] = useState('columns');\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'choose' | 'cancel' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Decided once: the buttons go away, so a second click cannot change it.\n // Nothing takes their place, so a real app moves focus to the message box.\n function decide(action: 'choose' | 'cancel') {\n if (pending || status !== 'open' || (action === 'choose' && selected === '')) return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus(action === 'choose' ? 'chosen' : 'cancelled');\n }, 1200);\n }\n\n const chosen = options.find((o) => o.value === selected);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n {status === 'chosen' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Chosen\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n {status === 'open' && (\n <>\n <RadioGroup\n variant=\"card\"\n aria-label={question}\n options={options}\n selectedValue={selected}\n onChange={setSelected}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'choose' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button size=\"small\" type=\"primary\" state={selected === '' || pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Choose\" loading={pending === 'choose'} onClickButton={() => decide('choose')} />\n </Cluster>\n </>\n )}\n {/* Once decided, only the chosen option is left on the card. */}\n {status === 'chosen' && chosen && <Paragraph measure=\"none\">{chosen.label}</Paragraph>}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
196
+ "uses": [
197
+ "Button",
198
+ "Center",
199
+ "Cluster",
200
+ "Heading",
201
+ "Message",
202
+ "Paragraph",
203
+ "RadioGroup",
204
+ "Stack",
205
+ "Surface",
206
+ "Tag",
207
+ "TimeStamp",
208
+ "UserImage"
209
+ ]
210
+ }
211
+ ]
212
+ },
213
+ {
214
+ "id": "agent-pending-reply",
215
+ "title": "Agent at work",
216
+ "kind": "design",
217
+ "level": "organism",
218
+ "area": "agent",
219
+ "situation": "The agent is working on a request in the thread, and its reply is not ready yet.",
220
+ "do": [
221
+ "Follow the rule 'An agent shows its progress': one row in the thread, where the reply will appear.",
222
+ "Mark the row as the rule 'An agent says what it is' says: an icon avatar, the agent's name, an 'Agent' `Tag`, the time and the model line.",
223
+ "Show the seconds so far in a caption, 'Working for 12 seconds', and update it once a second.",
224
+ "Show the steps in a `StepList`: the finished ones with a check, and the current one running, in plain words.",
225
+ "Leave out steps the agent has not started, unless it knows them.",
226
+ "Put the only 'Stop' in the row's `footer`, for the whole run, and under the reply while it is written.",
227
+ "Make 'Stop' `loading` while the run stops. Once the run has ended, replace the row in place with a note on what was and was not done.",
228
+ "Say 'Stopped. Nothing was changed.' when nothing was. When part was done, say what: 'Stopped after 2 of 4 steps. The rest of the plan was not done.'",
229
+ "Say 'Stopped. Nothing was written.' when a streaming reply is stopped before any text.",
230
+ "Keep the text and say 'Stopped before the reply was finished.' when a streaming reply is stopped after some text.",
231
+ "Show a failed run in the row: an inline error `Alert` with no close button and `autoDismiss={false}`, the failed step marked, and 'Try Again'.",
232
+ "Turn the row into the agent's reply when the run is done, and remove 'Stop'.",
233
+ "Move focus to the message box when 'Stop' goes away and no other control takes its place.",
234
+ "Announce the changing part politely, such as the running step: the app wraps it in a polite live region, since `StepList` has none.",
235
+ "Give the list that holds the rows `role=\"log\"`."
236
+ ],
237
+ "dont": [
238
+ "Do not show a spinner with no words.",
239
+ "Do not hide 'Stop' while the agent writes its reply.",
240
+ "Do not put 'Stop' in the Composer of a thread that people also write in.",
241
+ "Do not say the agent stopped before the run has really ended.",
242
+ "Do not report a failed run only in a toast away from the row."
243
+ ],
244
+ "options": [
245
+ {
246
+ "id": "steps",
247
+ "title": "Steps",
248
+ "useWhen": "The run has steps to show.",
249
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Alert from 'oneslash-design-system/components/alert';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };\nconst runStartedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Finding the new plans', done: 'Found the new plans' },\n { doing: 'Reading the pricing page', done: 'Read the pricing page' },\n { doing: 'Comparing the prices', done: 'Compared the prices' },\n];\n\nconst reply = \"The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15.\";\n\ntype Phase = 'running' | 'stopping' | 'stopped' | 'failed' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(current: number, failed: boolean): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) =>\n i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: failed ? 'failed' : 'running' },\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPendingReplySteps() {\n // Opens on a still of a run in progress, 12 seconds in, so the picture in the docs does not move.\n // 'Run Again' runs it live: the seconds tick and the steps go on.\n const [phase, setPhase] = useState<Phase>('running');\n const [current, setCurrent] = useState(2);\n const [seconds, setSeconds] = useState(12);\n const [startedAt, setStartedAt] = useState(runStartedAt);\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The first live run fails at the pricing page, so the example shows the failed row; 'Try Again' then works.\n const triedAgain = useRef(false);\n\n // On unmount it stops the run, its clock and the cancel request.\n useEffect(() => () => {\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function stopTimers() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === 2 && !triedAgain.current) {\n stopTimers();\n setPhase('failed');\n return;\n }\n if (at === plan.length - 1) {\n stopTimers();\n setPhase('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n function runLive() {\n stopTimers();\n setPhase('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n }\n\n function tryAgain() {\n triedAgain.current = true;\n runLive();\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setPhase('stopped');\n // 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.\n focusNext.current = () => runAgainButton.current?.focus();\n }, 1200);\n }\n\n const working = phase === 'running' || phase === 'stopping';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : phase === 'failed' ? (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Try Again\" onClickButton={tryAgain} />\n </Cluster>\n ) : phase === 'stopped' ? (\n <Cluster>\n <Button ref={runAgainButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Run Again\" onClickButton={runLive} />\n </Cluster>\n ) : undefined\n }\n >\n {phase === 'done' ? (\n // The run is over: the row is the reply, and Stop is gone. A real app moves focus to the message box.\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : phase === 'stopped' ? (\n <Paragraph measure=\"none\">Stopped. Nothing was changed.</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n {working && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>}\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current, phase === 'failed')} />\n {phase === 'failed' && (\n // It reports where the run stands, so it has no close button and stays.\n <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message=\"Acme Agent could not open the pricing page. Nothing was changed.\" />\n )}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
250
+ "uses": [
251
+ "Alert",
252
+ "Button",
253
+ "Center",
254
+ "Cluster",
255
+ "Heading",
256
+ "Message",
257
+ "Paragraph",
258
+ "Stack",
259
+ "StepList",
260
+ "Tag",
261
+ "TimeStamp",
262
+ "UserImage"
263
+ ]
264
+ },
265
+ {
266
+ "id": "streaming",
267
+ "title": "Streaming reply",
268
+ "useWhen": "The reply text arrives as it is written.",
269
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };\nconst runStartedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Reading the pricing page', done: 'Read the pricing page' },\n { doing: 'Writing the reply', done: 'Wrote the reply' },\n];\nconst writing = plan.length - 1;\n\nconst words = \"The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15. The Team plan is missing too.\".split(' ');\n\ntype Phase = 'running' | 'stopping' | 'stopped' | 'done';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) =>\n i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' },\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPendingReplyStreaming() {\n // Opens on a still of a run that is writing its reply, 18 seconds in, so the picture in the docs does not move.\n // 'Run Again' runs it live: the seconds tick and the reply grows word by word.\n const [phase, setPhase] = useState<Phase>('running');\n const [current, setCurrent] = useState(writing);\n const [shown, setShown] = useState(10);\n const [seconds, setSeconds] = useState(18);\n const [startedAt, setStartedAt] = useState(runStartedAt);\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the run, its clock and the cancel request.\n useEffect(() => () => {\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function stopTimers() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n }\n\n // Stands in for the agent's run: a step every 1.5 seconds, then a word of the reply every 0.2 seconds.\n function advance(at: number, count: number) {\n if (at < writing) {\n step.current = setTimeout(() => {\n setCurrent(at + 1);\n advance(at + 1, 0);\n }, 1500);\n return;\n }\n step.current = setTimeout(() => {\n if (count === words.length) {\n stopTimers();\n setPhase('done');\n return;\n }\n setShown(count + 1);\n advance(at, count + 1);\n }, 200);\n }\n\n function runLive() {\n stopTimers();\n setPhase('running');\n setCurrent(0);\n setShown(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0, 0);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setPhase('stopped');\n // 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.\n focusNext.current = () => runAgainButton.current?.focus();\n }, 1200);\n }\n\n const working = phase === 'running' || phase === 'stopping';\n const text = words.slice(0, shown).join(' ');\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n working ? (\n // The only Stop, under the reply while it is written. It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : phase === 'stopped' ? (\n <Cluster>\n <Button ref={runAgainButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Run Again\" onClickButton={runLive} />\n </Cluster>\n ) : undefined\n }\n >\n {phase === 'done' ? (\n // The run is over: the row is a plain reply, and Stop is gone. A real app moves focus to the message box.\n <Paragraph measure=\"none\">{text}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n {working && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>}\n {working && <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />}\n {text !== '' && <Paragraph measure=\"none\">{text}</Paragraph>}\n {/* A stop before any text says nothing was written; a stop after some text keeps it. */}\n {phase === 'stopped' && (\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">\n {text === '' ? 'Stopped. Nothing was written.' : 'Stopped before the reply was finished.'}\n </Paragraph>\n )}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
270
+ "uses": [
271
+ "Button",
272
+ "Center",
273
+ "Cluster",
274
+ "Heading",
275
+ "Message",
276
+ "Paragraph",
277
+ "Stack",
278
+ "StepList",
279
+ "Tag",
280
+ "TimeStamp",
281
+ "UserImage"
282
+ ]
283
+ }
284
+ ]
285
+ },
286
+ {
287
+ "id": "agent-plan-proposal",
288
+ "title": "Plan proposal",
289
+ "kind": "design",
290
+ "level": "organism",
291
+ "area": "agent",
292
+ "situation": "The agent is about to change shared work and needs the person to approve it first.",
293
+ "do": [
294
+ "Follow the rule 'An agent asks before a risky action': the agent does nothing until the person presses 'Approve'.",
295
+ "Put the card in the agent's `Message`, in a `Surface` with a heading, the plan, then the buttons.",
296
+ "List every step in a `<StepList numbered>`, in the order the agent will do them, each one waiting.",
297
+ "Offer 'View Changes' when the changes are ready, so the person sees them before they approve. It opens a `Modal` that lists them.",
298
+ "List each changed file in that Modal with one line on what changes in it. ODS has no diff part yet.",
299
+ "Order the steps card's buttons 'Cancel', 'Edit', then 'Approve' as the primary Button, at the start of the row under the plan.",
300
+ "Order the changes card's buttons 'Cancel', 'Request Changes', then 'Approve' as the primary Button.",
301
+ "Let the product write the label 'Approve'. The agent never writes the label of an approve or merge button.",
302
+ "Show the waiting time on the card while it waits, and while the person edits: 'Waits 10 more minutes, then cancels.'",
303
+ "Notify the person who asked when the agent needs their answer.",
304
+ "Make the pressed Button `loading` and keep its label. Disable the others while the request runs.",
305
+ "Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
306
+ "Mark the card with an 'Approved' or 'Cancelled' `Tag` once it is decided, and remove its buttons.",
307
+ "Announce the decided `Tag` politely: the app wraps it in a polite live region.",
308
+ "Keep an approved card as the record: the steps as they were approved, none running, and no buttons.",
309
+ "Move the run to its own progress row under the card, as the case 'Agent at work' shows, with its 'Stop'.",
310
+ "Say how far a stopped run got: 'Stopped after 2 of 4 steps. The rest of the plan was not done.' Take the count from the server's answer, not from the list on screen.",
311
+ "Add one compact agent row under a cancelled card that says what was not done: 'Cancelled. Nothing was changed.'",
312
+ "Mark the card Cancelled when the waiting time is up, with the same row on what was not done.",
313
+ "Turn the steps into a `Textarea` on 'Edit', one step per line, with 'Discard' and 'Save'.",
314
+ "Use 'Discard' to leave an edit on an agent card, since 'Cancel' there cancels the proposal. Editing your own message keeps 'Cancel'.",
315
+ "Send the edited steps to the agent on 'Save'. The plan comes back with the new steps, still waiting for a yes.",
316
+ "Open a `Textarea` labelled 'What should change?' on 'Request Changes', with 'Discard' and 'Send'.",
317
+ "Say on the card that the agent is redoing the changes once the request is sent, and remove its buttons.",
318
+ "Move focus to the field when 'Edit' or 'Request Changes' opens it, and back to that button after 'Discard', or after 'Save' in an edit.",
319
+ "Move focus to 'Stop' when the run's progress row appears.",
320
+ "Move focus to the message box when the card's buttons or 'Stop' go away and nothing takes their place."
321
+ ],
322
+ "dont": [
323
+ "Do not carry out any step before the person approves.",
324
+ "Do not replace the steps or the changes with a one-line summary.",
325
+ "Do not label the approve button 'Proceed', 'Confirm' or 'OK', or let the agent choose its label.",
326
+ "Do not change a Button's label while it is loading, such as to 'Proceeding...'.",
327
+ "Do not let a second click on a decided card approve or cancel it again.",
328
+ "Do not treat no answer as approval.",
329
+ "Do not show the run's steps as running on the card. The run has its own row."
330
+ ],
331
+ "options": [
332
+ {
333
+ "id": "steps",
334
+ "title": "Steps",
335
+ "useWhen": "The agent will carry out a list of steps.",
336
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Surface from 'oneslash-design-system/components/surface';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };\nconst proposedAt = new Date('2025-01-15T11:41:00Z');\n\nconst firstSteps = [\n 'Change the Pro price from $12 to $15',\n 'Add the Team plan at $25 per seat',\n 'Update the plan table on the pricing page',\n 'Open a pull request for review',\n];\n\nconst reply = 'The pricing page is updated, and the pull request is open for review.';\n\ntype Status = 'open' | 'editing' | 'approved' | 'cancelled';\ntype Run = 'running' | 'stopping' | 'stopped' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(steps: string[], current: number): StepListStep[] {\n return steps.slice(0, current + 1).map((label, i) => ({ label, status: i < current ? 'done' : 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPlanProposalSteps() {\n const [steps, setSteps] = useState(firstSteps);\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'approve' | 'cancel' | 'save' | null>(null);\n const [draft, setDraft] = useState('');\n // The run after 'Approve', in its own progress row under the card.\n const [run, setRun] = useState<Run | null>(null);\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [startedAt, setStartedAt] = useState(proposedAt);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const editButton = useRef<Focusable>(null);\n const stopButton = useRef<Focusable>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the requests, the run and its clock.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === steps.length - 1) {\n clearInterval(tick.current);\n setRun('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The card stays as the record, and the run shows in its own progress row below it.\n // 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.\n function startRun() {\n setRun('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Decided once: the buttons go away, so a second click cannot approve or cancel it again.\n // After 'Cancel' nothing takes their place: a real app moves focus to the message box.\n function decide(action: 'approve' | 'cancel') {\n if (pending || status !== 'open') return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n if (action === 'cancel') {\n setStatus('cancelled');\n return;\n }\n setStatus('approved');\n startRun();\n }, 1200);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (run !== 'running') return;\n clearTimeout(step.current);\n setRun('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setRun('stopped');\n }, 1200);\n }\n\n function startEditing() {\n if (pending) return;\n setDraft(steps.join('\\n'));\n setStatus('editing');\n }\n\n // 'Discard' leaves the edit and keeps the plan as it was. 'Cancel' would cancel the whole proposal.\n function discard() {\n setStatus('open');\n focusNext.current = () => editButton.current?.focus();\n }\n\n const draftSteps = draft.split('\\n').map((s) => s.trim()).filter((s) => s !== '');\n\n // 'Save' sends the edited steps to the agent. The plan comes back with them, still waiting for a yes.\n function save() {\n if (pending || draftSteps.length === 0) return;\n setPending('save');\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setSteps(draftSteps);\n setStatus('open');\n focusNext.current = () => editButton.current?.focus();\n }, 1200);\n }\n\n // A stop says how far the run got, so it never says nothing changed when something did.\n // A real app takes the count from the server's answer, not from the list on screen.\n const stoppedNote = current === 0\n ? 'Stopped. Nothing was changed.'\n : `Stopped after ${current} of ${steps.length} steps. The rest of the plan was not done.`;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(proposedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Proposed plan</Heading>\n {status === 'approved' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Approved\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n {status === 'editing' ? (\n <Textarea\n id=\"agent-plan-proposal-steps\"\n label=\"Steps, one per line\"\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n onSubmit={save}\n autoFocus\n maxRows={10}\n disabled={pending === 'save'}\n />\n ) : (\n // Every step, in the order the agent will do them. Once decided, the card is the record:\n // an approved plan keeps its steps as they were, and a cancelled one marks each step cancelled.\n <StepList\n numbered\n aria-label=\"Proposed plan\"\n steps={steps.map((label) => ({ label, status: status === 'cancelled' ? 'cancelled' : 'waiting' }))}\n />\n )}\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n {(status === 'open' || status === 'editing') && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n )}\n {status === 'open' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'approve' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button ref={editButton} size=\"small\" type=\"secondary\" state={pending ? 'disabled' : 'enabled'} label=\"Edit\" onClickButton={startEditing} />\n {/* The product writes this label, never the agent. */}\n <Button size=\"small\" type=\"primary\" state={pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Approve\" loading={pending === 'approve'} onClickButton={() => decide('approve')} />\n </Cluster>\n )}\n {status === 'editing' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'save' ? 'disabled' : 'enabled'} label=\"Discard\" onClickButton={discard} />\n <Button size=\"small\" type=\"primary\" state={draftSteps.length === 0 ? 'disabled' : 'enabled'} label=\"Save\" loading={pending === 'save'} onClickButton={save} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n {run && (\n // The run's own progress row, as the case 'Agent at work' shows.\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n run === 'running' || run === 'stopping' ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n // When it goes, a real app moves focus to the message box.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : undefined\n }\n >\n {run === 'done' ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : run === 'stopped' ? (\n <Paragraph measure=\"none\">{stoppedNote}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(steps, current)} />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
337
+ "uses": [
338
+ "Button",
339
+ "Center",
340
+ "Cluster",
341
+ "Heading",
342
+ "Message",
343
+ "Paragraph",
344
+ "Stack",
345
+ "StepList",
346
+ "Surface",
347
+ "Tag",
348
+ "Textarea",
349
+ "TimeStamp",
350
+ "UserImage"
351
+ ]
352
+ },
353
+ {
354
+ "id": "changes",
355
+ "title": "Changes",
356
+ "useWhen": "The agent has changes ready to apply.",
357
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Modal from 'oneslash-design-system/components/modal';\nimport List from 'oneslash-design-system/components/list';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };\nconst proposedAt = new Date('2025-01-15T11:44:00Z');\n\n// ODS has no diff part yet, so the changes are a list of the files they touch, each with what changes in it.\nconst changedFiles = [\n { path: 'pages/pricing.tsx', change: 'Adds the Team plan to the page.' },\n { path: 'data/plans.json', change: 'Sets the Pro price to $15 and adds the Team plan at $25 per seat.' },\n { path: 'components/planTable.tsx', change: 'Adds a column for the Team plan.' },\n];\n\n// The run after 'Approve': one step per file.\nconst runSteps = changedFiles.map((f) => `Change ${f.path}`);\n\nconst reply = 'The three files are changed. The pricing page shows the new plans.';\n\ntype Status = 'open' | 'requesting' | 'redoing' | 'approved' | 'cancelled';\ntype Run = 'running' | 'stopping' | 'stopped' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(current: number): StepListStep[] {\n return runSteps.slice(0, current + 1).map((label, i) => ({ label, status: i < current ? 'done' : 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPlanProposalChanges() {\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'approve' | 'cancel' | 'send' | null>(null);\n const [viewing, setViewing] = useState(false);\n const [draft, setDraft] = useState('');\n // The run after 'Approve', in its own progress row under the card.\n const [run, setRun] = useState<Run | null>(null);\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [startedAt, setStartedAt] = useState(proposedAt);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const requestButton = useRef<Focusable>(null);\n const stopButton = useRef<Focusable>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the requests, the run and its clock.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === runSteps.length - 1) {\n clearInterval(tick.current);\n setRun('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The card stays as the record, and the run shows in its own progress row below it.\n // 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.\n function startRun() {\n setRun('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Decided once: the buttons go away, so a second click cannot approve or cancel it again.\n // After 'Cancel' nothing takes their place: a real app moves focus to the message box.\n function decide(action: 'approve' | 'cancel') {\n if (pending || status !== 'open') return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n if (action === 'cancel') {\n setStatus('cancelled');\n return;\n }\n setStatus('approved');\n startRun();\n }, 1200);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (run !== 'running') return;\n clearTimeout(step.current);\n setRun('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setRun('stopped');\n }, 1200);\n }\n\n function startRequest() {\n if (pending) return;\n setDraft('');\n setStatus('requesting');\n }\n\n // 'Discard' leaves the sub-form and keeps the proposal open. 'Cancel' would cancel the whole proposal.\n function discard() {\n setStatus('open');\n focusNext.current = () => requestButton.current?.focus();\n }\n\n const empty = draft.trim() === '';\n\n // 'Send' gives the agent what should change. The card's buttons go, and the agent redoes the changes.\n // Nothing takes their place: a real app moves focus to the message box.\n function send() {\n if (pending || empty) return;\n setPending('send');\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus('redoing');\n }, 1200);\n }\n\n // A real app takes the count from the server's answer. Here the file that was being changed when the run\n // stopped may be partly changed, so the note says so and does not claim it is untouched.\n const partFile = changedFiles[current].path;\n const stoppedNote = current === 0\n ? `Stopped before any file was done. ${partFile} may be partly changed. Check it.`\n : `Stopped after ${current} of ${runSteps.length} files. ${partFile} may be partly changed. Check it.`;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(proposedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Changes ready</Heading>\n {status === 'approved' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Approved\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n <Paragraph measure=\"none\">These changes set the Pro price to $15 and add the Team plan to the pricing page. Three files change.</Paragraph>\n {(status === 'open' || status === 'requesting') && (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"View Changes\" onClickButton={() => setViewing(true)} />\n </Cluster>\n )}\n {status === 'requesting' && (\n <Textarea\n id=\"agent-plan-proposal-change-request\"\n label=\"What should change?\"\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n onSubmit={send}\n autoFocus\n disabled={pending === 'send'}\n />\n )}\n {status === 'redoing' && (\n <Paragraph measure=\"none\">Acme Agent is redoing the changes. It posts a new card when they are ready.</Paragraph>\n )}\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n {(status === 'open' || status === 'requesting') && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n )}\n {status === 'open' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'approve' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button ref={requestButton} size=\"small\" type=\"secondary\" state={pending ? 'disabled' : 'enabled'} label=\"Request Changes\" onClickButton={startRequest} />\n {/* The product writes this label, never the agent. */}\n <Button size=\"small\" type=\"primary\" state={pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Approve\" loading={pending === 'approve'} onClickButton={() => decide('approve')} />\n </Cluster>\n )}\n {status === 'requesting' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'send' ? 'disabled' : 'enabled'} label=\"Discard\" onClickButton={discard} />\n <Button size=\"small\" type=\"primary\" state={empty ? 'disabled' : 'enabled'} label=\"Send\" loading={pending === 'send'} onClickButton={send} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n {run && (\n // The run's own progress row, as the case 'Agent at work' shows.\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n run === 'running' || run === 'stopping' ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n // When it goes, a real app moves focus to the message box.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : undefined\n }\n >\n {run === 'done' ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : run === 'stopped' ? (\n <Paragraph measure=\"none\">{stoppedNote}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n <Modal\n isOpen={viewing}\n title=\"Changed Files\"\n onClose={() => setViewing(false)}\n actions={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Close\" onClickButton={() => setViewing(false)} />}\n >\n <Paragraph measure=\"none\">Approve changes these files.</Paragraph>\n <List\n marker=\"dot\"\n size=\"body1\"\n items={changedFiles.map((f) => (\n <Stack key={f.path} gap=\"small\">\n <Paragraph mono measure=\"none\">{f.path}</Paragraph>\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{f.change}</Paragraph>\n </Stack>\n ))}\n />\n </Modal>\n </Center>\n );\n}\n",
358
+ "uses": [
359
+ "Button",
360
+ "Center",
361
+ "Cluster",
362
+ "Heading",
363
+ "List",
364
+ "Message",
365
+ "Modal",
366
+ "Paragraph",
367
+ "Stack",
368
+ "StepList",
369
+ "Surface",
370
+ "Tag",
371
+ "Textarea",
372
+ "TimeStamp",
373
+ "UserImage"
374
+ ]
375
+ }
376
+ ]
377
+ },
378
+ {
379
+ "id": "agent-question",
380
+ "title": "Agent question",
381
+ "kind": "design",
382
+ "level": "organism",
383
+ "area": "agent",
384
+ "situation": "The agent needs an answer from the person before it can go on. It needs a fact or a decision only the person has. For ways forward in its own work, see the case 'Agent options'.",
385
+ "do": [
386
+ "Put the card in the agent's `Message`, in a `Surface` with the question as its heading.",
387
+ "Say which question it is in a caption when there are several: 'Question 1 of 3'.",
388
+ "Replace the question with the next one in the same card once it is answered or skipped, and move focus to its first answer.",
389
+ "Show a few answers as `<RadioGroup variant=\"card\">`, with an `aria-label` that starts with the question.",
390
+ "Preselect nothing unless the agent recommends an answer. Then give it the `badge` 'Recommended' and preselect it.",
391
+ "Take a free answer in a `Textarea` with a visible label.",
392
+ "Let Cmd+Enter or Ctrl+Enter in the field answer. Enter adds a line.",
393
+ "Order the buttons 'Skip', a tertiary Button that is always there, then 'Answer' as the primary Button.",
394
+ "Disable 'Answer' until an answer is picked or typed.",
395
+ "Make the pressed Button `loading` and keep its label. Disable the field and the other Button while the request runs.",
396
+ "Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
397
+ "Follow the rule 'An agent cancels and reports when nobody answers': show the waiting time on the card, 'Waits 10 more minutes, then cancels.'",
398
+ "Notify the person who asked when the agent needs their answer.",
399
+ "Show the answer as text with an 'Answered' `Tag` once it is sent, and remove the buttons.",
400
+ "Mark a skipped question with a 'Skipped' `Tag`, and say that the agent will list it as an open question in the plan.",
401
+ "Mark the card with a 'Cancelled' `Tag` when the waiting time is up. Add one compact agent row under it that says what was not done: 'Cancelled. Nothing was changed.'",
402
+ "Announce the decided `Tag` politely: the app wraps it in a polite live region.",
403
+ "Move focus to the message box once the last question is answered or skipped, since its buttons are gone."
404
+ ],
405
+ "dont": [
406
+ "Do not treat no answer as a yes.",
407
+ "Do not send an answer the person did not choose.",
408
+ "Do not recommend or preselect an option that does more than the others, such as one that deletes, publishes or widens access.",
409
+ "Do not leave a question waiting with no end, and do not cancel it without saying so in the thread.",
410
+ "Do not hide 'Skip'.",
411
+ "Do not change a Button's label while it is loading, such as to 'Submitting...'."
115
412
  ],
116
- "notBuiltYet": "No product cancels a waiting request on its own yet. In Scindo a request waits until a person answers, cancels or skips it, and the waiting time is not decided.",
117
- "seenIn": [
118
- "Scindo"
413
+ "options": [
414
+ {
415
+ "id": "choices",
416
+ "title": "Choices",
417
+ "useWhen": "The answer is one of a few.",
418
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Surface from 'oneslash-design-system/components/surface';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you plan the new pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\n// The agent has three questions. Each one replaces the one before it in the same card.\nconst questions = [\n {\n question: 'Which plans should the pricing page show?',\n options: [\n { value: 'three', label: 'Free, Pro and Team' },\n { value: 'two', label: 'Pro and Team only' },\n { value: 'four', label: 'Free, Pro, Team and Enterprise' },\n ],\n },\n {\n question: 'Should prices show per month or per year?',\n options: [\n { value: 'month', label: 'Per month' },\n { value: 'year', label: 'Per year' },\n { value: 'both', label: 'Both, with a switch' },\n ],\n },\n {\n question: 'Where should the plan table go?',\n options: [\n { value: 'top', label: 'At the top of the page' },\n { value: 'below', label: 'Below the feature list' },\n ],\n },\n];\n\n// What the person did with each question: the label of the answer, or null when it was skipped.\ntype Outcome = string | null;\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentQuestionChoices() {\n const [index, setIndex] = useState(0);\n const [outcomes, setOutcomes] = useState<Outcome[]>([]);\n // No option is recommended, so nothing starts selected.\n const [selected, setSelected] = useState('');\n const [pending, setPending] = useState<'answer' | 'skip' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const done = outcomes.length === questions.length;\n const { question, options } = questions[index];\n\n // After an answer or a skip, the next question replaces this one in the same card, with nothing selected.\n // A real app moves focus to its first answer. After the last one the buttons are gone, and a real app\n // moves focus to the message box.\n function send(action: 'answer' | 'skip') {\n if (pending || done || (action === 'answer' && selected === '')) return;\n setPending(action);\n const outcome = action === 'answer' ? options.find((o) => o.value === selected)?.label ?? null : null;\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setOutcomes((list) => [...list, outcome]);\n setSelected('');\n if (index < questions.length - 1) setIndex(index + 1);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n {done ? (\n // Every question is decided: the card is the record, with each answer or skip.\n // A real app announces the decided Tag in a polite live region.\n <Stack gap=\"medium\">\n {questions.map((q, i) => (\n <Stack key={q.question} gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{q.question}</Heading>\n {outcomes[i] === null\n ? <Tag variant=\"contained\" size=\"small\" label=\"Skipped\" />\n : <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Answered\" />}\n </Cluster>\n <Paragraph measure=\"none\">{outcomes[i] ?? 'Acme Agent will list this as an open question in the plan.'}</Paragraph>\n </Stack>\n ))}\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n {/* The agent has more than one question, so the card says which one this is. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`Question ${index + 1} of ${questions.length}`}</Paragraph>\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n <RadioGroup\n variant=\"card\"\n aria-label={question}\n options={options}\n selectedValue={selected}\n onChange={setSelected}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'answer' ? 'disabled' : 'enabled'} label=\"Skip\" loading={pending === 'skip'} onClickButton={() => send('skip')} />\n <Button\n size=\"small\"\n type=\"primary\"\n state={selected === '' || pending === 'skip' ? 'disabled' : 'enabled'}\n label=\"Answer\"\n loading={pending === 'answer'}\n onClickButton={() => send('answer')}\n />\n </Cluster>\n </Stack>\n )}\n </Surface>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
419
+ "uses": [
420
+ "Button",
421
+ "Center",
422
+ "Cluster",
423
+ "Heading",
424
+ "Message",
425
+ "Paragraph",
426
+ "RadioGroup",
427
+ "Stack",
428
+ "Surface",
429
+ "Tag",
430
+ "TimeStamp",
431
+ "UserImage"
432
+ ]
433
+ },
434
+ {
435
+ "id": "free-text",
436
+ "title": "Free text",
437
+ "useWhen": "The answer is the person's own words.",
438
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\nconst question = 'What should the Team plan say under its price?';\n\ntype Status = 'open' | 'answered' | 'skipped';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentQuestionFreeText() {\n const [text, setText] = useState('');\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'answer' | 'skip' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const empty = text.trim() === '';\n\n // Ctrl+Enter or Cmd+Enter in the field answers too, and Enter adds a line.\n // Once it is answered or skipped the buttons are gone, and a real app moves focus to the message box.\n function send(action: 'answer' | 'skip') {\n if (pending || status !== 'open' || (action === 'answer' && empty)) return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus(action === 'answer' ? 'answered' : 'skipped');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* One question only, so there is no 'Question 1 of 3' line. */}\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n {status === 'answered' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Answered\" />}\n {status === 'skipped' && <Tag variant=\"contained\" size=\"small\" label=\"Skipped\" />}\n </Cluster>\n {status === 'open' && (\n <>\n <Textarea\n id=\"agent-question-answer\"\n label=\"Your answer\"\n value={text}\n onChange={(e) => setText(e.target.value)}\n onSubmit={() => send('answer')}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'answer' ? 'disabled' : 'enabled'} label=\"Skip\" loading={pending === 'skip'} onClickButton={() => send('skip')} />\n <Button\n size=\"small\"\n type=\"primary\"\n state={empty || pending === 'skip' ? 'disabled' : 'enabled'}\n label=\"Answer\"\n loading={pending === 'answer'}\n onClickButton={() => send('answer')}\n />\n </Cluster>\n </>\n )}\n {status === 'answered' && <Paragraph measure=\"none\">{text.trim()}</Paragraph>}\n {status === 'skipped' && <Paragraph measure=\"none\">Acme Agent will list this as an open question in the plan.</Paragraph>}\n </Stack>\n </Surface>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
439
+ "uses": [
440
+ "Button",
441
+ "Center",
442
+ "Cluster",
443
+ "Heading",
444
+ "Message",
445
+ "Paragraph",
446
+ "Stack",
447
+ "Surface",
448
+ "Tag",
449
+ "Textarea",
450
+ "TimeStamp",
451
+ "UserImage"
452
+ ]
453
+ }
119
454
  ]
120
455
  },
121
456
  {
@@ -137,11 +472,7 @@
137
472
  "Do not show a general error message for a refusal.",
138
473
  "Do not show an Upgrade button to someone who cannot upgrade."
139
474
  ],
140
- "native": "On Apple the refusal is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page.",
141
- "notBuiltYet": "Scindo on the web does not follow this yet: it shows the Upgrade button to everyone. Scindo's Apple app shows it only to admins.",
142
- "seenIn": [
143
- "Scindo"
144
- ]
475
+ "native": "On Apple the refusal is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page."
145
476
  },
146
477
  {
147
478
  "id": "agent-says-what-it-is",
@@ -162,9 +493,56 @@
162
493
  "Do not show a photo for an agent, even when one is set.",
163
494
  "Do not show the product's logo on an agent the product does not run."
164
495
  ],
165
- "native": "On Apple an 'Agent' label with a sparkles icon sits next to a named agent's name, and the app draws the agent's avatar itself.",
166
- "seenIn": [
167
- "Scindo"
496
+ "native": "On Apple an 'Agent' label with a sparkles icon sits next to a named agent's name, and the app draws the agent's avatar itself."
497
+ },
498
+ {
499
+ "id": "agent-settings",
500
+ "title": "Agent settings",
501
+ "kind": "design",
502
+ "level": "organism",
503
+ "area": "settings",
504
+ "situation": "An admin sets which model the agent uses, how it picks one, what it should know about the team and how much it may spend.",
505
+ "do": [
506
+ "Follow the rule 'A setting saves in place, or with one Save Button'. Keep the choices and the two groups of fields in their own `SettingsSection`s.",
507
+ "Show the provider as `<RadioGroup variant=\"card\">`, with the models in the `secondLabel`. It saves as soon as the person chooses.",
508
+ "Disable the group while it saves and show nothing when it works. When the save fails, put the old choice back and say why under it: 'Could not save. Try again.'",
509
+ "Show the routing as a `RadioGroup` too. Each choice needs a line that says what it does, such as 'Use cheaper models when they can do the job.' A `SegmentedControl` fits two to four short choices that need no line.",
510
+ "Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. Give a `RadioGroup` an `aria-label` that starts with the visible label: 'AI provider'.",
511
+ "Put the instructions in a `Textarea` inside a `Form` with one Save Button. Say the limit in the help line, and show a problem with it under the field.",
512
+ "Put the budget cap in a `TextField type=\"number\"` inside its own `Form` with one Save Button. Say what happens at the cap and when it resets.",
513
+ "Keep each Save Button `state=\"disabled\"` while nothing has changed. It shows `loading`, keeps its label, then reads 'Saved' for 2 seconds. Name each one with an `aria-label`: 'Save instructions' and 'Save budget'.",
514
+ "Show everything read-only to a person who is not an admin, with one line at the top: 'Only admins can change this.' Remove the Save Buttons."
515
+ ],
516
+ "dont": [
517
+ "Do not mix a choice that saves on change and a Save Button in one section.",
518
+ "Do not label the Button 'Saving…'. It keeps its label.",
519
+ "Do not show a toast or a green caption when a setting saves. The control shows the new value, and the Button says Saved.",
520
+ "Do not hide a choice from a person who cannot change it with `pointer-events-none`. Show it disabled, with the line.",
521
+ "Do not use a `Select` for three choices that need a line each. Show them all in a `RadioGroup`.",
522
+ "Do not show a failed save as red text written by hand. Use the error line of `FormField`."
523
+ ],
524
+ "native": "On Apple use a grouped `Form` with a `Picker` for the provider and the routing. Use a `TextEditor` for the instructions and a `TextField` for the cap, each with one Save Button.",
525
+ "options": [
526
+ {
527
+ "id": "form",
528
+ "title": "Choices that save, and two groups with a Save Button",
529
+ "useWhen": "An admin sets the agent once for the whole workspace.",
530
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the person's role. Only an admin can change the agent.\nconst canChange = true;\n\nconst providerOptions = [\n { value: 'anthropic', label: 'Anthropic', secondLabel: 'Claude Sonnet, Opus and Haiku' },\n { value: 'openai', label: 'OpenAI', secondLabel: 'GPT-4o and GPT-4.1' },\n { value: 'google', label: 'Google Gemini', secondLabel: 'Gemini Pro and Flash' },\n];\n\n// Each choice needs a line that says what it does, so this is a RadioGroup and not a SegmentedControl.\nconst routingOptions = [\n { value: 'auto', label: 'Auto', secondLabel: 'The best model for each request. The default.' },\n { value: 'cost', label: 'Lower cost', secondLabel: 'Use cheaper models when they can do the job.' },\n { value: 'quality', label: 'Higher quality', secondLabel: 'Use the most capable model for every request.' },\n];\n\nconst maxInstructions = 1000;\nconst failedMessage = 'Could not save. Try again.';\n\nexport default function AgentSettingsForm() {\n const [provider, setProvider] = useState('anthropic');\n const [providerError, setProviderError] = useState('');\n const [savingProvider, setSavingProvider] = useState(false);\n\n const [routing, setRouting] = useState('auto');\n const [routingError, setRoutingError] = useState('');\n const [savingRouting, setSavingRouting] = useState(false);\n\n const [savedInstructions, setSavedInstructions] = useState('Answer in short sentences. Link the task when you mention one.');\n const [instructions, setInstructions] = useState('Answer in short sentences. Link the task when you mention one.');\n const [instructionsError, setInstructionsError] = useState('');\n const [savingInstructions, setSavingInstructions] = useState(false);\n const [instructionsSaved, setInstructionsSaved] = useState(false);\n\n const [savedBudget, setSavedBudget] = useState('200');\n const [budget, setBudget] = useState('200');\n const [budgetError, setBudgetError] = useState('');\n const [savingBudget, setSavingBudget] = useState(false);\n const [budgetSaved, setBudgetSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const instructionsSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const budgetSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(instructionsSavedTimer.current);\n clearTimeout(budgetSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A choice stands alone, so it saves as soon as it is made. Nothing shows when it works.\n // While the request runs the group is disabled. When it fails, the old choice comes back and a line says why.\n function handleProvider(next: string) {\n if (savingProvider || next === provider) return;\n const before = provider;\n setProviderError('');\n setProvider(next);\n setSavingProvider(true);\n later(() => {\n setSavingProvider(false);\n // Stands in for a connection that is down: Google Gemini never saves.\n if (next === 'google') {\n setProvider(before);\n setProviderError(failedMessage);\n }\n }, 900);\n }\n\n function handleRouting(next: string) {\n if (savingRouting || next === routing) return;\n setRoutingError('');\n setRouting(next);\n setSavingRouting(true);\n later(() => setSavingRouting(false), 900);\n }\n\n // Instructions are a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveInstructions() {\n if (savingInstructions) return;\n if (instructions.length > maxInstructions) {\n setInstructionsError(`Use up to ${maxInstructions.toLocaleString('en-US')} characters.`);\n return;\n }\n setInstructionsError('');\n setSavingInstructions(true);\n later(() => {\n setSavedInstructions(instructions);\n setSavingInstructions(false);\n setInstructionsSaved(true);\n clearTimeout(instructionsSavedTimer.current);\n instructionsSavedTimer.current = setTimeout(() => setInstructionsSaved(false), 2000);\n }, 1200);\n }\n\n function handleSaveBudget() {\n if (savingBudget) return;\n if (!/^\\d+$/.test(budget.trim())) {\n setBudgetError('Enter a whole number of dollars, like 200.');\n return;\n }\n setBudgetError('');\n setSavingBudget(true);\n later(() => {\n setSavedBudget(budget.trim());\n setBudget(budget.trim());\n setSavingBudget(false);\n setBudgetSaved(true);\n clearTimeout(budgetSavedTimer.current);\n budgetSavedTimer.current = setTimeout(() => setBudgetSaved(false), 2000);\n }, 1200);\n }\n\n const instructionsChanged = instructions !== savedInstructions;\n const budgetChanged = budget.trim() !== savedBudget;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">How the Acme agent works for everyone in this workspace.</Paragraph>\n {!canChange && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n {/* Both choices save as soon as they change, so this section has no Save Button. */}\n <SettingsSection title=\"Model\" description=\"Each choice saves as soon as you make it.\">\n <FormField id=\"agent-settings-provider\" label=\"AI provider\" error={providerError}>\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"AI provider\"\n variant=\"card\"\n options={providerOptions}\n selectedValue={provider}\n disabled={!canChange || savingProvider}\n onChange={handleProvider}\n />\n )}\n </FormField>\n <FormField id=\"agent-settings-routing\" label=\"Routing\" help=\"How the agent picks a model for each request.\" error={routingError}>\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"Routing\"\n options={routingOptions}\n selectedValue={routing}\n disabled={!canChange || savingRouting}\n onChange={handleRouting}\n />\n )}\n </FormField>\n </SettingsSection>\n\n <SettingsSection title=\"Instructions\" description=\"What the agent should know about how your team works.\">\n <Form aria-label=\"Instructions\" gap=\"medium\" onSubmit={handleSaveInstructions}>\n <FormField id=\"agent-settings-instructions\" label=\"Instructions\" help={`Up to ${maxInstructions.toLocaleString('en-US')} characters. Every conversation uses them.`} error={instructionsError}>\n {(f) => (\n <Textarea\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={instructions}\n disabled={!canChange || savingInstructions}\n onChange={(e) => { setInstructions(e.target.value); setInstructionsError(''); setInstructionsSaved(false); }}\n />\n )}\n </FormField>\n {canChange && (\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={instructionsChanged || savingInstructions ? 'enabled' : 'disabled'} label={instructionsSaved ? 'Saved' : 'Save'} aria-label={`${instructionsSaved ? 'Saved' : 'Save'} instructions`} htmlType=\"submit\" loading={savingInstructions} />\n </Cluster>\n )}\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Budget\" description=\"This month the agent has used $84.\">\n <Form aria-label=\"Budget\" gap=\"medium\" onSubmit={handleSaveBudget}>\n <FormField id=\"agent-settings-budget\" label=\"Monthly cap in US dollars\" help=\"The agent stops when this month's use reaches the cap, and starts again next month.\" error={budgetError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"number\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={budget}\n disabled={!canChange || savingBudget}\n autoComplete=\"off\"\n onChange={(e) => { setBudget(e.target.value); setBudgetError(''); setBudgetSaved(false); }}\n />\n )}\n </FormField>\n {canChange && (\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={budgetChanged || savingBudget ? 'enabled' : 'disabled'} label={budgetSaved ? 'Saved' : 'Save'} aria-label={`${budgetSaved ? 'Saved' : 'Save'} budget`} htmlType=\"submit\" loading={savingBudget} />\n </Cluster>\n )}\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
531
+ "uses": [
532
+ "Button",
533
+ "Center",
534
+ "Cluster",
535
+ "Form",
536
+ "FormField",
537
+ "Heading",
538
+ "Paragraph",
539
+ "RadioGroup",
540
+ "SettingsSection",
541
+ "Stack",
542
+ "TextField",
543
+ "Textarea"
544
+ ]
545
+ }
168
546
  ]
169
547
  },
170
548
  {
@@ -187,10 +565,7 @@
187
565
  "Do not hide the Stop button while the agent writes its reply.",
188
566
  "Do not say the agent stopped before the run has really ended."
189
567
  ],
190
- "native": "On Apple the Send button turns into Stop while the agent works, and the note reads 'Stopped.' only once the run has really ended.",
191
- "seenIn": [
192
- "Scindo"
193
- ]
568
+ "native": "On Apple the Send button turns into Stop while the agent works, and the note reads 'Stopped.' only once the run has really ended."
194
569
  },
195
570
  {
196
571
  "id": "agent-shows-sources",
@@ -199,21 +574,120 @@
199
574
  "level": "rule",
200
575
  "area": "agent",
201
576
  "situation": "The agent answers from things it read: documents, files, chat, tasks, or a connected service such as a code host or a design tool.",
202
- "answer": "Under the reply, the agent lists what it used. A small tag names the kinds of source, such as 'From Chat · Knowledge base', and one card per source shows its title, its kind and where it lives. Each card opens the source. A reply that used no sources shows no sources section.",
577
+ "answer": "Under the reply, the agent lists what it used. A small tag names the kinds of source, such as 'From Chat · Knowledge base', and one card per source shows its title, its kind and where it lives. Each card opens the source. A reply that used no sources shows no sources section. When the reply read only the messages already on screen above it, the Tag alone is enough.",
203
578
  "why": "A person can check an answer only when they can open what it came from.",
204
579
  "do": [
205
580
  "Put the sources directly under the reply they support.",
206
581
  "Show each source as a card with its title and where it lives, such as the space name or the date.",
207
582
  "Make each card open the source itself, in the product or on the service it came from.",
208
- "Show the first six sources and a 'Show N more' button for the rest."
583
+ "Show the first six sources and a 'Show N More' button for the rest."
209
584
  ],
210
585
  "dont": [
211
586
  "Do not show a sources section when the reply used no sources.",
212
587
  "Do not show source cards on a person's message.",
213
588
  "Do not link a source card to any site other than the product or the service the source came from."
589
+ ]
590
+ },
591
+ {
592
+ "id": "api-keys",
593
+ "title": "API keys",
594
+ "kind": "design",
595
+ "level": "organism",
596
+ "area": "settings",
597
+ "situation": "A person makes keys that let a script or a service use the product as them, and revokes keys they no longer use.",
598
+ "do": [
599
+ "List each key with its name, the start of the key in the mono face, when it was created and when it was last used. Say 'Never used' when it was not.",
600
+ "Show only a prefix of 14 characters in the list, with an ellipsis. Never show a whole key again once the Modal is closed.",
601
+ "Open a Modal titled 'Create Key' from a 'Create Key' Button, with one field, 'Name', and 'Cancel' then 'Create'.",
602
+ "Say under the name what to put in it: 'Say what will use it, such as CI pipeline.'",
603
+ "Keep the Modal open when the key is made, change its title to 'Key Created' and show the key in a `CopyField` with `reveal=\"once\"` and `mono`. The field says 'Copy it now. You will not see it again.'",
604
+ "Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.",
605
+ "Confirm 'Revoke' in the row, as the case 'Delete confirm' does: the row asks 'Revoke CI pipeline?' and shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'CI pipeline key revoked.'",
606
+ "Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the key: 'Revoke CI pipeline' and 'Cancel revoking CI pipeline'.",
607
+ "Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what is empty' says.",
608
+ "Disable the name field while the key is made, and show `loading` on the Button without changing its label."
609
+ ],
610
+ "dont": [
611
+ "Do not show a whole key in the list, in a toast or in a URL.",
612
+ "Do not revoke a key on the first click.",
613
+ "Do not label the Button 'Create' on the page. Name the thing: 'Create Key'.",
614
+ "Do not close the Modal when the key is made, because the person has not copied it yet.",
615
+ "Do not put the key in a plain field the person has to select by hand. Use `CopyField`.",
616
+ "Do not use an icon-only Button for Revoke. It names no key."
617
+ ],
618
+ "native": "On Apple use a `Table` with a monospaced prefix, a `.destructive` Button that asks in a `confirmationDialog`, and a sheet that shows the new key once with a Copy Button.",
619
+ "options": [
620
+ {
621
+ "id": "list",
622
+ "title": "A list of keys with a create Modal",
623
+ "useWhen": "Scripts or services act as the person with a key they paste.",
624
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Key = { id: string; name: string; prefix: string; created: string; lastUsed: string };\n\nconst firstKeys: Key[] = [\n { id: 'k1', name: 'CI pipeline', prefix: 'acme_live_7Hd2', created: 'Oct 3, 2026', lastUsed: 'Today' },\n { id: 'k2', name: 'Reporting script', prefix: 'acme_live_Qm4x', created: 'Aug 19, 2026', lastUsed: 'Nov 20, 2026' },\n];\n\n// The key the server made. A real app gets it once, in the reply to the create request, and never again.\nconst madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';\nconst prefixLength = 14;\n\nexport default function ApiKeysList() {\n // Opens on the new key, as if the person just chose Create. The list already holds it, without the key.\n const [keys, setKeys] = useState<Key[]>(() => [\n { id: 'k3', name: 'Deploy bot', prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' },\n ...firstKeys,\n ]);\n const [open, setOpen] = useState(true);\n const [shownKey, setShownKey] = useState<string | null>(madeKey);\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Gives each new key its own id, so no two rows share a key.\n const keyCount = useRef(0);\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleOpen() {\n setName('');\n setNameError('');\n setShownKey(null);\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel close the first step, except while the request runs.\n // Once the key shows, only 'Done' closes it, so a stray click cannot throw the key away.\n function handleClose() {\n if (creating || shownKey) return;\n setOpen(false);\n }\n\n // 'Done' drops the key from the page. It is not kept anywhere else.\n function handleDone() {\n setOpen(false);\n setShownKey(null);\n }\n\n function handleCreate() {\n if (creating) return;\n if (!name.trim()) {\n setNameError('Enter a name for the key.');\n return;\n }\n setNameError('');\n setCreating(true);\n later(() => {\n setCreating(false);\n keyCount.current += 1;\n const id = `new-${keyCount.current}`;\n setKeys((list) => [{ id, name: name.trim(), prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' }, ...list]);\n setShownKey(madeKey);\n }, 1200);\n }\n\n function handleRevoke(key: Key) {\n if (revoking) return;\n setRevoking(key.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setKeys((list) => list.filter((k) => k.id !== key.id));\n toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">API keys</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Key\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>\n </Stack>\n\n {keys.length > 0 ? (\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Name</TableHeaderCell>\n <TableHeaderCell width=\"150px\">Key</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Created</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Last used</TableHeaderCell>\n <TableHeaderCell width=\"200px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {keys.map((k) => (\n <TableRow key={k.id}>\n <TableCell>{k.name}</TableCell>\n <TableCell width=\"150px\">\n <Paragraph mono size=\"body2\" measure=\"none\">{k.prefix}…</Paragraph>\n </TableCell>\n <TableCell width=\"100px\">{k.created}</TableCell>\n <TableCell width=\"100px\">{k.lastUsed}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"200px\">\n {confirming === k.id ? (\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke {k.name}?</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={revoking === k.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => setConfirming(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />\n </Cluster>\n </Stack>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${k.name}`} onClickButton={() => setConfirming(k.id)} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"KeyRound\" text=\"No API keys\" secondText=\"Keys you create appear here.\" />\n )}\n </Stack>\n\n <Modal\n isOpen={open}\n size=\"medium\"\n initialFocus=\"body\"\n title={shownKey ? 'Key Created' : 'Create Key'}\n onClose={handleClose}\n actions={\n shownKey ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n ) : (\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n )\n }\n >\n {shownKey ? (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Use this key where the service asks for one. Anyone who has it can use Acme as you.</Paragraph>\n {/* `reveal=\"once\"` adds the line that says the key will not show again. */}\n <CopyField id=\"api-keys-key\" label=\"API key\" value={shownKey} mono reveal=\"once\" />\n </Stack>\n ) : (\n <Form aria-label=\"Create key\" onSubmit={handleCreate}>\n <TextField id=\"api-keys-name\" label=\"Name\" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} helperText=\"Say what will use it, such as CI pipeline.\" onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n </Form>\n )}\n </Modal>\n </Center>\n );\n}\n",
625
+ "uses": [
626
+ "Button",
627
+ "Center",
628
+ "Cluster",
629
+ "CopyField",
630
+ "EmptyBox",
631
+ "Form",
632
+ "Heading",
633
+ "Modal",
634
+ "Paragraph",
635
+ "Stack",
636
+ "TableCell",
637
+ "TableContainer",
638
+ "TableHeader",
639
+ "TableHeaderCell",
640
+ "TableRow",
641
+ "TextField",
642
+ "Toaster",
643
+ "dismissToast",
644
+ "toast"
645
+ ]
646
+ }
647
+ ]
648
+ },
649
+ {
650
+ "id": "artifact-card",
651
+ "title": "Document card",
652
+ "kind": "design",
653
+ "level": "organism",
654
+ "area": "agent",
655
+ "situation": "The agent made a document for the person, such as a plan or a report.",
656
+ "do": [
657
+ "Keep the reply to one sentence on what the agent made. Then put the card in the reply's `footer`.",
658
+ "Show the document as a `SourceCard`: an icon for its kind, its title, its kind and length in `meta` ('Document · 4 pages'), and `action=\"Open\"`.",
659
+ "Open the document from the card with `onClick`, in a pane beside the thread.",
660
+ "Move focus into the pane when it opens.",
661
+ "Give the pane a Close control, and move focus back to the card when the pane closes.",
662
+ "Bring the open pane forward when the person presses the card again, instead of opening a second one.",
663
+ "Mark the agent's row as the rule 'An agent says what it is' says.",
664
+ "Give the list that holds the rows `role=\"log\"`."
665
+ ],
666
+ "dont": [
667
+ "Do not paste the document into the thread.",
668
+ "Do not repeat or list what the document says in the reply.",
669
+ "Do not show the document's card on a person's message."
214
670
  ],
215
- "seenIn": [
216
- "Scindo"
671
+ "native": "On Mac the card opens the document in the canvas beside the thread. On iPhone it opens the document in a read-only sheet.",
672
+ "options": [
673
+ {
674
+ "id": "card",
675
+ "title": "In the thread",
676
+ "useWhen": "A reply made a document.",
677
+ "source": "'use client';\nimport { Bot, FileText } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Center, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// One sentence on what the agent made. The document itself stays out of the thread.\nconst reply = 'I wrote the launch plan for March 3 as a document.';\n\nconst doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\n// A real app opens the document in a pane beside the thread and moves focus into it.\n// ODS has no side pane part yet, so this example shows the card only.\nfunction openDocument() {}\n\nexport default function ArtifactCardCard() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={FileText} title={doc.title} meta={doc.meta} action=\"Open\" onClick={openDocument} />\n </Grid>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
678
+ "uses": [
679
+ "Center",
680
+ "Grid",
681
+ "Heading",
682
+ "Message",
683
+ "Paragraph",
684
+ "SourceCard",
685
+ "Stack",
686
+ "Tag",
687
+ "TimeStamp",
688
+ "UserImage"
689
+ ]
690
+ }
217
691
  ]
218
692
  },
219
693
  {
@@ -237,11 +711,6 @@
237
711
  "Do not put more than one line under the spinner, or write it in a separate Paragraph."
238
712
  ],
239
713
  "native": "On Apple use `ProgressView()` centered in the window, with a label only for a named step that can take longer.",
240
- "notBuiltYet": "Scindo on the web shows 'Please wait' under the step while it checks an invite, and a small spinner instead of `LoadingScreen` while onboarding checks for a workspace.",
241
- "seenIn": [
242
- "Commentify admin",
243
- "Scindo"
244
- ],
245
714
  "options": [
246
715
  {
247
716
  "id": "spinner",
@@ -286,11 +755,6 @@
286
755
  "Do not make the person close the success Alert, and do not let it close on its own before they have read it.",
287
756
  "Do not change 'Send Again' to 'Sending…' while it sends."
288
757
  ],
289
- "notBuiltYet": "Neither Commentify nor Scindo can send the email again from the check-your-email screen. Both show their success Alert above the login form with a close button, and it starts 'Account created.', even for an address that already had an account.",
290
- "seenIn": [
291
- "Commentify",
292
- "Scindo"
293
- ],
294
758
  "options": [
295
759
  {
296
760
  "id": "page",
@@ -327,33 +791,150 @@
327
791
  ]
328
792
  },
329
793
  {
330
- "id": "confirm-destructive-action",
331
- "title": "Delete confirm",
794
+ "id": "collapsible-search",
795
+ "title": "Collapsible search",
332
796
  "kind": "design",
333
797
  "level": "organism",
334
- "area": "confirm",
335
- "situation": "A person asks to delete or remove something, and it cannot be undone.",
798
+ "area": "menu",
799
+ "situation": "A person filters a list by a word, and the list should keep its room when they are not typing.",
336
800
  "do": [
337
- "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, 'Cancel' first, then the action with `color=\"danger\"`.",
338
- "Name the thing and what goes with it: \"This deletes 'Q3 plan' and its 12 tasks.\"",
339
- "Turn the row's Buttons into 'Cancel' and a danger 'Remove' in place for the inline confirm. The rest of the row stays as it is.",
340
- "Give each row's Buttons an `aria-label` that starts with the visible label and names the thing, such as 'Remove Dana Lee' and 'Cancel removing Dana Lee'.",
341
- "Name the thing in the label so a screen reader knows which row a Button acts on.",
342
- "Keep one row confirming at a time. Starting a confirm on another row cancels the first.",
343
- "Show a toast that names the thing once it is gone."
801
+ "Use an `IconButton` with `iconName=\"Search\"` beside the list's heading, and open a `<Popover returnFocus>` with a search `TextField` from it.",
802
+ "Keep the words in the page, not in the Popover. The list stays filtered while the Popover is closed.",
803
+ "Show that a search is on: `color=\"secondary\"` on the button, and a line such as '2 of 5 invoices match \"north\".'.",
804
+ "Say the current search in the button's `ariaLabel`: 'Search: north'. It is plain 'Search' when no search is on.",
805
+ "Set `aria-haspopup=\"dialog\"` and `aria-expanded` on the button, and `state=\"selected\"` while the Popover is open.",
806
+ "Focus the field with `autoFocus` when the Popover opens, and name it with `aria-label`, such as `aria-label=\"Search invoices\"`.",
807
+ "Clear the search and close the Popover on Escape. Focus goes back to the button.",
808
+ "Keep the search when the Popover closes any other way: Enter, a click outside, or Tab.",
809
+ "Follow the case 'Empty search' when nothing matches. Its 'Clear Search' Button clears the filter. Focus goes to the search button, not the field, because the field is in the closed Popover."
344
810
  ],
345
811
  "dont": [
346
- "Do not ask for a confirm when the action is easy to undo.",
347
- "Do not remove a row on the first click of its Button.",
348
- "Do not open a Modal for a row in a long list when the inline confirm keeps the place.",
349
- "Do not ask a question in place of the action, such as 'Are you sure?'."
812
+ "Do not clear the search when the Popover closes, except with Escape.",
813
+ "Do not name the button 'Search' while a search is on. Its name says what is searched for.",
814
+ "Do not show the filter only in color. The line under the heading says it too.",
815
+ "Do not open the Popover when the page loads."
350
816
  ],
351
- "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role and 'Cancel' in the `.cancel` role.",
352
- "notBuiltYet": "Commentify's Delete project confirm is not danger-colored and asks a question in its body. Scindo on the web confirms removing a saved card in place, but asks 'Are you sure?' and labels its Buttons 'Confirm' and 'No'.",
353
- "seenIn": [
354
- "Commentify",
355
- "Scindo"
817
+ "native": "On Apple use `.searchable` on the list, which collapses into the toolbar and keeps its text. On Android use a `SearchBar` that expands from the app bar.",
818
+ "options": [
819
+ {
820
+ "id": "popover",
821
+ "title": "Search button with a Popover",
822
+ "useWhen": "A list has a header with little room, and a search is a filter the person sets once in a while.",
823
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Button from 'oneslash-design-system/components/button';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport List from 'oneslash-design-system/components/list';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst invoices = ['Northwind, March', 'Harbor Studio, March', 'Lumen Labs, February', 'Northstar Dental, February', 'Pine and Co, January'];\n\nexport default function CollapsibleSearchPopover() {\n // The filter belongs to the page, not to the Popover: it stays when the Popover closes.\n const [query, setQuery] = useState('north');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const trigger = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const words = query.trim();\n const on = words !== '';\n const found = invoices.filter((name) => name.toLowerCase().includes(words.toLowerCase()));\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Escape clears the search and closes. The field handles it before the Popover's own Escape, which only closes.\n // Enter closes and keeps the filter. A click outside and Tab close and keep it too.\n function keyDown(e: { key: string; preventDefault(): void }) {\n if (e.key === 'Escape') {\n e.preventDefault();\n setQuery('');\n setOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setOpen(false);\n }\n }\n\n // The field is closed, so 'Clear Search' clears the filter and focus goes to the search button.\n function clearSearch() {\n setQuery('');\n trigger.current?.focus();\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">Invoices</Heading>\n {/* A search that is on shows in a filled button and says what it is looking for. */}\n <Tooltip title={on ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={trigger}\n color={on ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={on ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {on ? `${found.length} of ${invoices.length} invoices match \"${words}\".` : `All ${invoices.length} invoices.`}\n </Paragraph>\n {found.length > 0 ? (\n <Surface>\n <List items={found} size=\"body1\" />\n </Surface>\n ) : (\n <Surface align=\"center\" minHeight=\"short\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={`No invoices match \"${words}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n </Surface>\n )}\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n {/* Menu gives the Popover its surface and a width. It holds a field here, not items. */}\n <Menu width={288}>\n <TextField\n id=\"collapsible-search-query\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onKeyDown={keyDown}\n />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
824
+ "uses": [
825
+ "Button",
826
+ "Center",
827
+ "Cluster",
828
+ "EmptyBox",
829
+ "Heading",
830
+ "IconButton",
831
+ "List",
832
+ "Menu",
833
+ "Paragraph",
834
+ "Popover",
835
+ "Stack",
836
+ "Surface",
837
+ "TextField",
838
+ "Tooltip"
839
+ ]
840
+ }
841
+ ]
842
+ },
843
+ {
844
+ "id": "composer-limit",
845
+ "title": "Composer at a limit",
846
+ "kind": "design",
847
+ "level": "organism",
848
+ "area": "chat",
849
+ "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its agent replies for the month.",
850
+ "do": [
851
+ "Follow the rule 'An agent refuses clearly' word for word: \"You've used all 50 AI agent responses this month.\"",
852
+ "Put the notice in the Composer's `above` slot: `<Alert variant=\"inline\" autoDismiss={false}>`, with no close button on the Alert itself.",
853
+ "Say when it resets and who can change it: 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'",
854
+ "Give everyone 'Not Now', a tertiary Button, so the refusal can be closed. Put the Buttons in a `Cluster` under the Alert.",
855
+ "Give a person who can lift the limit the action after 'Not Now', as a primary Button, such as 'Upgrade to Pro'.",
856
+ "Keep the agent toggle pressable while the limit stands, as the case 'Upgrade prompt' says. Pressing it shows the notice again, and it does not turn on.",
857
+ "Say in the placeholder when agent replies start again, once the person chose 'Not Now'.",
858
+ "Move focus to the message box after 'Not Now', since the Button that had it is gone.",
859
+ "Keep the field and send working, so messages to people still go.",
860
+ "Follow the case 'Upgrade prompt' for a limit reached anywhere outside the message box."
861
+ ],
862
+ "dont": [
863
+ "Do not disable the whole Composer. Only the agent is refused.",
864
+ "Do not hide or disable the agent toggle. The person presses it and learns why it does not work.",
865
+ "Do not show the upgrade Button to someone who cannot upgrade.",
866
+ "Do not show a general error, or a toast that goes away, for a limit.",
867
+ "Do not cover the thread with a Modal when the agent is refused."
868
+ ],
869
+ "native": "On Apple the notice is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page.",
870
+ "options": [
871
+ {
872
+ "id": "notice",
873
+ "title": "Notice",
874
+ "useWhen": "The person cannot lift the limit.",
875
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNotice() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-notice-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person cannot change the plan, so it says who can. Everyone can close a refusal. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. Ask a workspace admin to upgrade Acme Design to Pro for more replies.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
876
+ "uses": [
877
+ "Alert",
878
+ "Button",
879
+ "Center",
880
+ "Cluster",
881
+ "Composer",
882
+ "Heading",
883
+ "IconButton",
884
+ "Message",
885
+ "Paragraph",
886
+ "Stack",
887
+ "TimeStamp",
888
+ "Tooltip",
889
+ "UserImage"
890
+ ]
891
+ },
892
+ {
893
+ "id": "notice-with-action",
894
+ "title": "Notice with an action",
895
+ "useWhen": "The person can lift the limit.",
896
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNoticeWithAction() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-action-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person can change the plan, so they get the button that lifts the limit. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. The Pro plan gives Acme Design 1,000 AI agent responses a month.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
897
+ "uses": [
898
+ "Alert",
899
+ "Button",
900
+ "Center",
901
+ "Cluster",
902
+ "Composer",
903
+ "Heading",
904
+ "IconButton",
905
+ "Message",
906
+ "Paragraph",
907
+ "Stack",
908
+ "TimeStamp",
909
+ "Tooltip",
910
+ "UserImage"
911
+ ]
912
+ }
913
+ ]
914
+ },
915
+ {
916
+ "id": "confirm-destructive-action",
917
+ "title": "Delete confirm",
918
+ "kind": "design",
919
+ "level": "organism",
920
+ "area": "confirm",
921
+ "situation": "A person asks to delete or remove something, and it cannot be undone.",
922
+ "do": [
923
+ "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, 'Cancel' first, then the action with `color=\"danger\"`.",
924
+ "Name the thing and what goes with it: \"This deletes 'Q3 plan' and its 12 tasks.\"",
925
+ "Turn the row's Buttons into 'Cancel' and a danger 'Remove' in place for the inline confirm. The rest of the row stays as it is.",
926
+ "Give each row's Buttons an `aria-label` that starts with the visible label and names the thing, such as 'Remove Dana Lee' and 'Cancel removing Dana Lee'.",
927
+ "Name the thing in the label so a screen reader knows which row a Button acts on.",
928
+ "Keep one row confirming at a time. Starting a confirm on another row cancels the first.",
929
+ "Show a toast that names the thing once it is gone."
930
+ ],
931
+ "dont": [
932
+ "Do not ask for a confirm when the action is easy to undo.",
933
+ "Do not remove a row on the first click of its Button.",
934
+ "Do not open a Modal for a row in a long list when the inline confirm keeps the place.",
935
+ "Do not ask a question in place of the action, such as 'Are you sure?'."
356
936
  ],
937
+ "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role and 'Cancel' in the `.cancel` role.",
357
938
  "options": [
358
939
  {
359
940
  "id": "modal",
@@ -421,11 +1002,68 @@
421
1002
  "Do not replace the Modal body with a spinner, or close the Modal, while the request runs.",
422
1003
  "Do not ask for a confirm when the action is easy to undo."
423
1004
  ],
424
- "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm.",
425
- "notBuiltYet": "No Commentify confirm Modal uses `color=\"danger\"`, and two of them label Cancel 'No'. Scindo on the web makes Cancel a secondary Button in some confirms and a tertiary one in others. It leaves its Delete Task and Remove Member confirms uncolored. Scindo on the web revokes an API key, and Commentify revokes an agent client, with no confirm.",
426
- "seenIn": [
427
- "Commentify",
428
- "Scindo"
1005
+ "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm."
1006
+ },
1007
+ {
1008
+ "id": "conversation-starters",
1009
+ "title": "Conversation starters",
1010
+ "kind": "design",
1011
+ "level": "organism",
1012
+ "area": "chat",
1013
+ "situation": "A thread has no messages yet, and the person may not know what to write first.",
1014
+ "do": [
1015
+ "Show the empty thread as the rule 'An empty list says what will fill it' says. Use `EmptyBox` with `size=\"large\"`, the `text` 'No messages yet', and a `secondText` that says what to do.",
1016
+ "Pass the starters as the `action`: a `Cluster` of three or four clickable `Tag`s, each a short thing to ask in the person's words.",
1017
+ "Pass `toggle={false}` to each starter `Tag`, so it is a plain button and not a toggle.",
1018
+ "Use `Tag`, not Button: a starter is a phrase the person might say, and a Button label is in Title Case.",
1019
+ "Fill the Composer with the starter and focus it, with the caret at the end. Do not send it: the person reads it and can change it first.",
1020
+ "Say who reads the message in the placeholder: 'Message Acme Agent'.",
1021
+ "Hide the starters once the thread has a message.",
1022
+ "Write the starters for the place: in a task, ask about the plan; in a channel, ask about what the team discussed."
1023
+ ],
1024
+ "dont": [
1025
+ "Do not send a starter on a click.",
1026
+ "Do not show starters in a thread between people. Say what to do in `secondText` instead.",
1027
+ "Do not offer more than four starters.",
1028
+ "Do not write starters in the system's words, such as 'Run summary'."
1029
+ ],
1030
+ "options": [
1031
+ {
1032
+ "id": "chips",
1033
+ "title": "Things to ask",
1034
+ "useWhen": "A conversation with the agent: three or four things to ask it.",
1035
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst agentName = 'Acme Agent';\n\n// Things to ask, in the person's words.\nconst starters = [\n 'Summarize the launch plan',\n 'Draft the launch email',\n 'List what is still open',\n 'Check the pricing page for mistakes',\n];\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nexport default function ConversationStartersChips() {\n const [thread, setThread] = useState<Row[]>([]);\n const [text, setText] = useState('');\n // Set when a starter fills the field; the effect below focuses it with the caret at the end.\n const [filled, setFilled] = useState(0);\n const field = useRef<HTMLTextAreaElement>(null);\n\n useEffect(() => {\n if (!filled || !field.current) return;\n const end = field.current.value.length;\n field.current.focus();\n field.current.setSelectionRange(end, end);\n }, [filled]);\n\n // Fills the field and does not send: the person can change it first.\n function fillWith(starter: string) {\n setText(starter);\n setFilled((n) => n + 1);\n }\n\n function send() {\n // A real app sends the message to the agent here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">{`Ask ${agentName}`}</Heading>\n {thread.length === 0 ? (\n <EmptyBox\n size=\"large\"\n icon=\"MessageCircle\"\n text=\"No messages yet\"\n secondText={`Ask ${agentName} about the launch, or start with one of these.`}\n action={\n <Cluster gap=\"small\">\n {starters.map((s) => (\n <Tag key={s} variant=\"contained\" size=\"small\" label={s} toggle={false} onClick={() => fillWith(s)} />\n ))}\n </Cluster>\n }\n />\n ) : (\n // A real app gives the list that holds the rows role=\"log\".\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n )}\n <Composer\n ref={field}\n id=\"conversation-starters-chips-message\"\n aria-label=\"Message\"\n placeholder={`Message ${agentName}`}\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
1036
+ "uses": [
1037
+ "Center",
1038
+ "Cluster",
1039
+ "Composer",
1040
+ "EmptyBox",
1041
+ "Heading",
1042
+ "Message",
1043
+ "Paragraph",
1044
+ "Stack",
1045
+ "Tag",
1046
+ "TimeStamp",
1047
+ "UserImage"
1048
+ ]
1049
+ },
1050
+ {
1051
+ "id": "none",
1052
+ "title": "No starters",
1053
+ "useWhen": "A thread between people, where the agent is not the one asked.",
1054
+ "source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nexport default function ConversationStartersNone() {\n const [thread, setThread] = useState<Row[]>([]);\n const [text, setText] = useState('');\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {thread.length === 0 ? (\n // A thread between people: no starters, and secondText says what to do.\n <EmptyBox\n size=\"large\"\n icon=\"MessageCircle\"\n text=\"No messages yet\"\n secondText=\"Send the first message to the team in Launch plan.\"\n />\n ) : (\n // A real app gives the list that holds the rows role=\"log\".\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n )}\n <Composer\n id=\"conversation-starters-none-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
1055
+ "uses": [
1056
+ "Center",
1057
+ "Composer",
1058
+ "EmptyBox",
1059
+ "Heading",
1060
+ "Message",
1061
+ "Paragraph",
1062
+ "Stack",
1063
+ "TimeStamp",
1064
+ "UserImage"
1065
+ ]
1066
+ }
429
1067
  ]
430
1068
  },
431
1069
  {
@@ -455,10 +1093,6 @@
455
1093
  "Do not show a toast when the new thing is on screen. It shows where it lives."
456
1094
  ],
457
1095
  "native": "On Apple use a sheet with a `Form`. Put 'Cancel' in the `.cancellationAction` placement and 'Create' in `.confirmationAction`, and create on `.onSubmit` from the name field.",
458
- "notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates a workspace or a task, and makes Cancel a secondary Button. Scindo's Apple app labels the Button 'Creating...' while it runs.",
459
- "seenIn": [
460
- "Scindo"
461
- ],
462
1096
  "options": [
463
1097
  {
464
1098
  "id": "quick",
@@ -501,6 +1135,69 @@
501
1135
  }
502
1136
  ]
503
1137
  },
1138
+ {
1139
+ "id": "danger-zone",
1140
+ "title": "Danger zone",
1141
+ "kind": "design",
1142
+ "level": "organism",
1143
+ "area": "settings",
1144
+ "situation": "A settings page offers actions that are hard or impossible to undo, such as deleting an account or a workspace, or leaving one.",
1145
+ "do": [
1146
+ "Put the actions in a `SettingsSection tone=\"danger\"` titled 'Danger zone', or titled with the action, such as 'Delete workspace'. It is the last section on the page.",
1147
+ "Hide them behind a 'Show Danger Zone' Button when the page has more above it. Give the Button `aria-expanded`, and change its label to 'Hide Danger Zone' while they show. This label says what a press does next. It is not a status, so it may change.",
1148
+ "Say what is deleted and what is kept, above the action: 'Messages and tasks you shared stay with your team.'",
1149
+ "Delete an account or a workspace as the case 'Type to confirm' says: the field shows in place, 'Cancel' comes first, and the danger Button stays disabled until the text matches exactly.",
1150
+ "Type a fixed word such as DELETE for an account. Type the name for a workspace: 'Type Acme to confirm'.",
1151
+ "Leave a workspace with a plain confirm in a small Modal, as the rule 'A confirm says exactly what will happen' says. Name the action with the title's verb: the title is 'Leave Workspace' and the Button is 'Leave'.",
1152
+ "Give 'Leave' the plain primary color. Leaving destroys nothing: the workspace and its work stay.",
1153
+ "Show a page that says it is done when the account or workspace is gone, in place of the toast in the rule 'A confirm says exactly what will happen'. The page that showed it is gone too, and the person may be logged out.",
1154
+ "Mark the section with the danger color on the title and the hairline. `SettingsSection` does both."
1155
+ ],
1156
+ "dont": [
1157
+ "Do not put a danger zone above the settings that people use every day.",
1158
+ "Do not delete on the first click. Ask the person to type, or to confirm.",
1159
+ "Do not ask someone to type for leaving a workspace. A plain confirm is enough.",
1160
+ "Do not change the Button's label while it is loading, such as to 'Deleting…'.",
1161
+ "Do not hide what is kept. Say it before the person confirms.",
1162
+ "Do not use a native `details` element. Use a Button with `aria-expanded`."
1163
+ ],
1164
+ "native": "On Apple put the actions in their own `Section` of the settings `Form`, with the Delete Button in the `.destructive` role. Delete asks in an `.alert` with a `TextField`, as the case 'Type to confirm' says.",
1165
+ "options": [
1166
+ {
1167
+ "id": "collapsed",
1168
+ "title": "Hidden until asked for",
1169
+ "useWhen": "The page has more above it, and most visits have no use for these actions.",
1170
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// An account has no name to type, so the person types a fixed word.\nconst word = 'DELETE';\n\nexport default function DangerZoneCollapsed() {\n const [shown, setShown] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // An exact match, with case. Pasting the word is fine.\n const matches = typed === word;\n\n function handleToggle() {\n if (deleting) return;\n setShown(!shown);\n setConfirming(false);\n setTyped('');\n }\n\n function handleCancel() {\n setConfirming(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setDeleted(true);\n }, 1200);\n }\n\n // The account is gone, so the page that showed it is gone too.\n if (deleted) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">Your account is deleted</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a note to dana@acme.example to say so.</Paragraph>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Account</Heading>\n <SettingsSection title=\"Profile\" description=\"Dana Lee, dana@acme.example.\">\n <Paragraph size=\"body2\" measure=\"none\">Your name and picture are in Profile Settings.</Paragraph>\n </SettingsSection>\n <SettingsSection tone=\"danger\" title=\"Danger zone\" description=\"These actions cannot be undone.\">\n <Cluster>\n <Button\n size=\"small\"\n type=\"textOnly\"\n state={deleting ? 'disabled' : 'enabled'}\n label={shown ? 'Hide Danger Zone' : 'Show Danger Zone'}\n aria-expanded={shown}\n onClickButton={handleToggle}\n />\n </Cluster>\n {shown && (\n <Stack gap=\"medium\">\n <Paragraph size=\"body2\" measure=\"none\">This deletes your account and your private documents. Messages and tasks you shared stay with your team and show as &apos;Deleted user&apos;.</Paragraph>\n {confirming ? (\n <>\n <TextField id=\"danger-zone-collapsed-word\" label={`Type ${word} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete Account\" loading={deleting} onClickButton={handleDelete} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Account\" onClickButton={() => setConfirming(true)} />\n </Cluster>\n )}\n </Stack>\n )}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
1171
+ "uses": [
1172
+ "Button",
1173
+ "Center",
1174
+ "Cluster",
1175
+ "Heading",
1176
+ "Paragraph",
1177
+ "SettingsSection",
1178
+ "Stack",
1179
+ "TextField"
1180
+ ]
1181
+ },
1182
+ {
1183
+ "id": "shown",
1184
+ "title": "Shown on its own page",
1185
+ "useWhen": "The page is about the one thing to delete or leave, such as a workspace.",
1186
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A workspace has a name, so the person types it.\nconst workspaceName = 'Acme';\n\nexport default function DangerZoneShown() {\n const [leaving, setLeaving] = useState(false);\n const [leaveOpen, setLeaveOpen] = useState(false);\n const [left, setLeft] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // An exact match, with case. Pasting the name is fine.\n const matches = typed === workspaceName;\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleLeaveClose() {\n if (leaving) return;\n setLeaveOpen(false);\n }\n\n function handleLeave() {\n if (leaving) return;\n setLeaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLeaving(false);\n setLeaveOpen(false);\n setLeft(true);\n }, 1200);\n }\n\n function handleCancelDelete() {\n setConfirming(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n timer.current = setTimeout(() => {\n setDeleting(false);\n setDeleted(true);\n }, 1200);\n }\n\n // The workspace is gone, or the person is out of it, so the page that showed it is gone too.\n if (left || deleted) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">{deleted ? `${workspaceName} is deleted` : `You left ${workspaceName}`}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">{deleted ? 'Everyone in it was told.' : 'An owner can invite you again.'}</Paragraph>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Danger zone</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Leave or delete the Acme workspace.</Paragraph>\n </Stack>\n <SettingsSection tone=\"danger\" title=\"Leave workspace\" description=\"You lose access to Acme.\">\n <Paragraph size=\"body2\" measure=\"none\">Your messages and tasks stay in Acme. An owner can invite you again.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Leave Workspace\" onClickButton={() => setLeaveOpen(true)} />\n </Cluster>\n </SettingsSection>\n <SettingsSection tone=\"danger\" title=\"Delete workspace\" description=\"This cannot be undone.\">\n <Paragraph size=\"body2\" measure=\"none\">This deletes Acme, its 128 messages, 42 tasks and 9 documents. Every member keeps their own account, and files exported earlier stay where they are.</Paragraph>\n {confirming ? (\n <>\n <TextField id=\"danger-zone-shown-name\" label={`Type ${workspaceName} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancelDelete} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete Workspace\" loading={deleting} onClickButton={handleDelete} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Workspace\" onClickButton={() => setConfirming(true)} />\n </Cluster>\n )}\n </SettingsSection>\n </Stack>\n <Modal\n isOpen={leaveOpen}\n size=\"small\"\n title=\"Leave Workspace\"\n onClose={handleLeaveClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={leaving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleLeaveClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Leave\" loading={leaving} onClickButton={handleLeave} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will lose access to Acme.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Your messages and tasks stay in Acme. An owner can invite you again.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1187
+ "uses": [
1188
+ "Button",
1189
+ "Center",
1190
+ "Cluster",
1191
+ "Heading",
1192
+ "Modal",
1193
+ "Paragraph",
1194
+ "SettingsSection",
1195
+ "Stack",
1196
+ "TextField"
1197
+ ]
1198
+ }
1199
+ ]
1200
+ },
504
1201
  {
505
1202
  "id": "device-login",
506
1203
  "title": "Device login",
@@ -523,11 +1220,6 @@
523
1220
  "Do not leave a popup blank while it finishes.",
524
1221
  "Do not label a provider Button with its name alone, such as 'Google'. Write 'Continue with Google'."
525
1222
  ],
526
- "notBuiltYet": "Scindo's CLI login shows 'Login successful!' as soon as its request to the CLI gets any reply. It sends that request in a way that leaves the page unable to read the CLI's reply, so it cannot tell whether the CLI took the login. Its provider Buttons read 'GitHub' and 'Google'. Commentify's popup shows nothing while it finishes.",
527
- "seenIn": [
528
- "Commentify",
529
- "Scindo"
530
- ],
531
1223
  "options": [
532
1224
  {
533
1225
  "id": "provider-first",
@@ -578,11 +1270,6 @@
578
1270
  "Do not ask the person to log in again in the browser where they are already logged in.",
579
1271
  "Do not make the person close the success Alert."
580
1272
  ],
581
- "notBuiltYet": "Scindo on the web shows its success Alert above the login form with a close button. Commentify has no confirmed page and no Alert for it: the link goes straight to the dashboard.",
582
- "seenIn": [
583
- "Commentify",
584
- "Scindo"
585
- ],
586
1273
  "options": [
587
1274
  {
588
1275
  "id": "page",
@@ -636,11 +1323,6 @@
636
1323
  "Do not show the empty text while the list is still loading."
637
1324
  ],
638
1325
  "native": "On Apple use `ContentUnavailableView`, with the same words.",
639
- "notBuiltYet": "Commentify writes most of its empty lists in Title Case, such as 'No Comments Available', and gives them no `secondText`.",
640
- "seenIn": [
641
- "Commentify",
642
- "Scindo"
643
- ],
644
1326
  "options": [
645
1327
  {
646
1328
  "id": "region",
@@ -693,14 +1375,7 @@
693
1375
  "Do not use the system's words, such as 'No data' or 'No records found'.",
694
1376
  "Do not pass an `action` the person is not allowed to use."
695
1377
  ],
696
- "native": "On Apple use `ContentUnavailableView`, with the same words.",
697
- "notBuiltYet": "Scindo on the web uses `EmptyBox` in three places and bare text elsewhere, such as 'No API keys yet.' Commentify uses `EmptyBox` in most lists and bare text in a few. Commentify admin and jinhwankim.com show bare text. No product passes an `action` yet.",
698
- "seenIn": [
699
- "Commentify",
700
- "Commentify admin",
701
- "Scindo",
702
- "jinhwankim.com"
703
- ]
1378
+ "native": "On Apple use `ContentUnavailableView`, with the same words."
704
1379
  },
705
1380
  {
706
1381
  "id": "empty-not-set-up",
@@ -720,11 +1395,6 @@
720
1395
  "Do not offer more than one Button."
721
1396
  ],
722
1397
  "native": "On Apple use `ContentUnavailableView`, with the Button in its `actions`.",
723
- "notBuiltYet": "Commentify puts its 'Open Settings' Button under `EmptyBox`, not in its `action`, and writes the text in Title Case: 'No App, Team, or User Connected'.",
724
- "seenIn": [
725
- "Commentify",
726
- "Scindo"
727
- ],
728
1398
  "options": [
729
1399
  {
730
1400
  "id": "action",
@@ -773,11 +1443,6 @@
773
1443
  "Do not clear the search field unless the person asks."
774
1444
  ],
775
1445
  "native": "On Apple use `ContentUnavailableView.search(text:)`.",
776
- "notBuiltYet": "Scindo on the web shows a bare line, 'No results found', with no words and no way to clear them. Scindo on Apple shows 'No results found' in a `ContentUnavailableView`, without the words. Commentify shows the words in an `EmptyBox`, with no Clear Search Button.",
777
- "seenIn": [
778
- "Commentify",
779
- "Scindo"
780
- ],
781
1446
  "options": [
782
1447
  {
783
1448
  "id": "clear-search",
@@ -813,12 +1478,6 @@
813
1478
  "Do not show a line of text with no way out.",
814
1479
  "Do not hide the navigation when only one route failed."
815
1480
  ],
816
- "notBuiltYet": "Scindo on the web shows the error's own message and its id. Commentify shows one line and 'Try again', with no heading and no way home. jinhwankim.com shows an `EmptyBox` with no Button.",
817
- "seenIn": [
818
- "Commentify",
819
- "Scindo",
820
- "jinhwankim.com"
821
- ],
822
1481
  "options": [
823
1482
  {
824
1483
  "id": "full-page",
@@ -877,10 +1536,6 @@
877
1536
  "Do not fail without a word. Say that the feedback was not sent.",
878
1537
  "Do not clear what the person wrote when sending fails."
879
1538
  ],
880
- "notBuiltYet": "Scindo's feedback form labels the Button 'Sending...' while it runs, shows no error when sending fails, and replaces the form with a thank-you that closes after 1.5 seconds. It labels its fields with captions written by hand.",
881
- "seenIn": [
882
- "Scindo"
883
- ],
884
1539
  "options": [
885
1540
  {
886
1541
  "id": "modal",
@@ -905,6 +1560,73 @@
905
1560
  }
906
1561
  ]
907
1562
  },
1563
+ {
1564
+ "id": "filter-menu",
1565
+ "title": "Filter menu",
1566
+ "kind": "design",
1567
+ "level": "organism",
1568
+ "area": "menu",
1569
+ "situation": "A person narrows a list by one choice, such as a date range, or turns the filter off.",
1570
+ "do": [
1571
+ "Open a navigable menu from an `IconButton`: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Filter by date\">` with `onClick` items.",
1572
+ "Pass `event.currentTarget` to the Popover as `anchorEl`, and set `state=\"selected\"` on the button while the menu is open.",
1573
+ "Give the button `color=\"secondary\"` while a filter is on.",
1574
+ "Say the current filter in the button's `ariaLabel`: 'Filter by date: Last 7 days'.",
1575
+ "Show the current filter in a `Tooltip` on the button, such as 'Last 7 days'.",
1576
+ "Give each item `role=\"menuitemradio\"` and mark the current one with `isSelected`. It sets `aria-checked`, so a screen reader says which one is on.",
1577
+ "Write each choice in Title Case, such as 'Last 24 Hours', and close the menu when one is chosen.",
1578
+ "Add 'Clear Filter' last, after a `Line`, when the filter can be off. Show it only while a filter is on.",
1579
+ "Show what the list holds under the heading, such as how many comments the filter leaves.",
1580
+ "Use the case 'Range switch' instead when two to four ranges are the page's main view and the header has room."
1581
+ ],
1582
+ "dont": [
1583
+ "Do not use a Tooltip as the only place that names the current filter.",
1584
+ "Do not mark the current choice with color only.",
1585
+ "Do not keep the menu open after a choice.",
1586
+ "Do not add a custom date range in a menu. ODS has no date picker yet.",
1587
+ "Do not put a destructive item in a filter menu."
1588
+ ],
1589
+ "native": "On Apple use a `Menu` with a `Picker` inside it, so the current choice gets a check mark. On Android use a dropdown menu with radio items.",
1590
+ "options": [
1591
+ {
1592
+ "id": "presets",
1593
+ "title": "Presets",
1594
+ "useWhen": "The choices are dates or a few fixed choices, and one is always on.",
1595
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server. `label` is the menu item, in Title Case. `current` names the\n// choice in the button's name, its tooltip and the line, in sentence case.\nconst filters = [\n { value: 'day', label: 'Last 24 Hours', current: 'Last 24 hours', count: 4 },\n { value: 'week', label: 'Last 7 Days', current: 'Last 7 days', count: 18 },\n { value: 'month', label: 'Last 30 Days', current: 'Last 30 days', count: 64 },\n { value: 'quarter', label: 'Last 90 Days', current: 'Last 90 days', count: 171 },\n { value: 'all', label: 'All Time', current: 'All time', count: 240 },\n];\n\nexport default function FilterMenuPresets() {\n const [value, setValue] = useState('week');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = filters.find((f) => f.value === value) ?? filters[1];\n\n // The trigger toggles the menu. Popover's returnFocus gives focus back to it on close.\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string) {\n setValue(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Comments</Heading>\n {/* The tooltip names the current filter, and so does the button's name. A filter that is on\n shows in a filled button; 'All Time' filters nothing, so the button is plain. */}\n <Tooltip title={current.current}>\n <IconButton\n color={value === 'all' ? 'iconOnly' : 'secondary'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={`Filter by date: ${current.current}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{current.count} comments, {current.current.toLowerCase()}.</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by date\" width={200}>\n {filters.map((f) => (\n <MenuItem\n key={f.value}\n size=\"small\"\n label={f.label}\n isSelected={f.value === value}\n role=\"menuitemradio\"\n onClick={() => choose(f.value)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1596
+ "uses": [
1597
+ "Center",
1598
+ "Cluster",
1599
+ "Heading",
1600
+ "IconButton",
1601
+ "Menu",
1602
+ "MenuItem",
1603
+ "Paragraph",
1604
+ "Popover",
1605
+ "Stack",
1606
+ "Tooltip"
1607
+ ]
1608
+ },
1609
+ {
1610
+ "id": "with-clear",
1611
+ "title": "Presets with Clear Filter",
1612
+ "useWhen": "The filter can be off, so the list shows everything until the person picks a choice.",
1613
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. `label` is the menu item, in Title Case. `current` names the\n// choice in the button's name, its tooltip and the line, in sentence case.\nconst filters = [\n { value: 'mentions', label: 'Mentions', current: 'Mentions', count: 3 },\n { value: 'unread', label: 'Unread', current: 'Unread', count: 5 },\n { value: 'assigned', label: 'Assigned to Me', current: 'Assigned to me', count: 2 },\n];\nconst total = 12;\n\nexport default function FilterMenuWithClear() {\n // null means the filter is off.\n const [value, setValue] = useState<string | null>('unread');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = filters.find((f) => f.value === value);\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string | null) {\n setValue(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Inbox</Heading>\n {/* A filter that is on shows in a filled button. When it is off the button is plain. */}\n <Tooltip title={current ? current.current : 'Filter messages'}>\n <IconButton\n color={current ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={current ? `Filter messages: ${current.current}` : 'Filter messages'}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {current ? `${current.count} of ${total} messages, ${current.current.toLowerCase()}.` : `All ${total} messages.`}\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter messages\" width={200}>\n {filters.map((f) => (\n <MenuItem\n key={f.value}\n size=\"small\"\n label={f.label}\n isSelected={f.value === value}\n role=\"menuitemradio\"\n onClick={() => choose(f.value)}\n />\n ))}\n {/* Clear is last, and shows only while a filter is on. */}\n {current && <Line />}\n {current && <MenuItem size=\"small\" iconName=\"X\" label=\"Clear Filter\" onClick={() => choose(null)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1614
+ "uses": [
1615
+ "Center",
1616
+ "Cluster",
1617
+ "Heading",
1618
+ "IconButton",
1619
+ "Line",
1620
+ "Menu",
1621
+ "MenuItem",
1622
+ "Paragraph",
1623
+ "Popover",
1624
+ "Stack",
1625
+ "Tooltip"
1626
+ ]
1627
+ }
1628
+ ]
1629
+ },
908
1630
  {
909
1631
  "id": "forgot-password",
910
1632
  "title": "Forgot password",
@@ -928,11 +1650,6 @@
928
1650
  "Do not replace the form with a spinner while sending the link."
929
1651
  ],
930
1652
  "native": "On Apple, put 'Forgot Password?' under the 'Log In' Button and open the web reset form from it.",
931
- "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while sending the link. Both then say 'We sent a password reset link to' the address, even when it has no account.",
932
- "seenIn": [
933
- "Commentify",
934
- "Scindo"
935
- ],
936
1653
  "options": [
937
1654
  {
938
1655
  "id": "in-place",
@@ -999,12 +1716,6 @@
999
1716
  "Do not use the browser's `alert()`.",
1000
1717
  "Do not clear the form after a failed submit.",
1001
1718
  "Do not change the submit Button's label while it is loading, such as to 'Saving…'."
1002
- ],
1003
- "notBuiltYet": "Commentify writes red captions by hand on its consent screen and in its Figma import dialog. Scindo on the web does the same in its dialogs, such as renaming a workspace or a task. Commentify uses the browser's `alert()` in three files, and Scindo on the web in one.",
1004
- "seenIn": [
1005
- "Commentify",
1006
- "Scindo",
1007
- "jinhwankim.com"
1008
1719
  ]
1009
1720
  },
1010
1721
  {
@@ -1032,10 +1743,6 @@
1032
1743
  "Do not clear the selection when the person searches.",
1033
1744
  "Do not show a bare line of text when the list is empty or nothing matches."
1034
1745
  ],
1035
- "notBuiltYet": "Scindo's Notion import labels its Buttons 'Select all' and 'Import', changes the action to 'Importing… 1/2' while it runs, and shows bare text when nothing matches.",
1036
- "seenIn": [
1037
- "Scindo"
1038
- ],
1039
1746
  "options": [
1040
1747
  {
1041
1748
  "id": "modal",
@@ -1079,10 +1786,6 @@
1079
1786
  "Do not say 'successfully'."
1080
1787
  ],
1081
1788
  "native": "On Apple there is no toast. Show the result in place.",
1082
- "notBuiltYet": "Scindo on the web labels its save Buttons 'Saving...' while they save. Its profile settings show nothing when a save fails. Its instructions settings show the error's own message in an inline Alert with no close button.",
1083
- "seenIn": [
1084
- "Scindo"
1085
- ],
1086
1789
  "options": [
1087
1790
  {
1088
1791
  "id": "button-label",
@@ -1138,6 +1841,77 @@
1138
1841
  }
1139
1842
  ]
1140
1843
  },
1844
+ {
1845
+ "id": "integrations-list",
1846
+ "title": "Integrations",
1847
+ "kind": "design",
1848
+ "level": "organism",
1849
+ "area": "settings",
1850
+ "situation": "A person connects the product to other tools, sees which ones are connected and disconnects them.",
1851
+ "do": [
1852
+ "Show each provider in a row: its logo, its name and one line on what connecting does: 'Link pull requests to tasks and close tasks when they merge.'",
1853
+ "Use `BrandIcon` for a logo it has, and a Lucide icon in `Icon` for the others. Both are decorative, because the name sits beside them.",
1854
+ "Show 'Connect' on a provider that is not connected, and its account beside 'Disconnect' once it is. Name the provider in each `aria-label`: 'Connect Slack'.",
1855
+ "Show a `Tag` with `color=\"warning\"` that reads 'Needs attention', and a primary 'Reconnect', on a connection whose access ran out. Say in the line what is wrong.",
1856
+ "Confirm 'Disconnect' in a small Modal, as the rule 'A confirm says exactly what will happen' says, because what it stops does not come back by itself. Title it with the verb and the thing: 'Disconnect Slack', or 'Disconnect acme-labs' for one account. Say what stops and that the person can connect again.",
1857
+ "Show `loading` on 'Connect' and 'Reconnect' while the sign-in runs, and keep the label. Disable the other Buttons until it ends.",
1858
+ "Group the accounts under their provider, with 'Add Account' on the provider's row, for a provider that holds several. Each account has its own 'Reconnect' and 'Disconnect'.",
1859
+ "Name the account in each account's `aria-label`: 'Disconnect acme-labs'. Disconnecting one account leaves the others connected.",
1860
+ "Show a connection the person cannot change as read-only, with one line that says who can: 'Only admins can change this.'"
1861
+ ],
1862
+ "dont": [
1863
+ "Do not use an icon-only Button for Disconnect. It names no provider.",
1864
+ "Do not label a running Button 'Connecting…'. It keeps its label and shows `loading`.",
1865
+ "Do not disconnect on the first click.",
1866
+ "Do not show red text as the only sign that access ran out. Add the 'Needs attention' Tag and a 'Reconnect' Button.",
1867
+ "Do not give each provider its own page section with a heading and no logo. Put them in one list."
1868
+ ],
1869
+ "native": "On Apple use a grouped `Form` with one `Section` per provider, 'Connect' as a Button, and 'Disconnect' in the `.destructive` role in a `confirmationDialog`. On Android use a list of rows that opens a confirm.",
1870
+ "options": [
1871
+ {
1872
+ "id": "rows",
1873
+ "title": "One row per provider",
1874
+ "useWhen": "A few providers, and each one holds a single account.",
1875
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Figma, Slack } from 'lucide-react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Provider = {\n id: string;\n name: string;\n /** One line on what connecting does. */\n does: string;\n /** What stops when it is disconnected, for the confirm. */\n stops: string;\n /** The account a person connects as, once connected. */\n account: string;\n brand?: 'google' | 'github';\n};\n\nconst providers: Provider[] = [\n { id: 'slack', name: 'Slack', does: 'Post the weekly digest and link previews in your channels.', stops: 'The weekly digest and link previews stop.', account: 'Acme workspace' },\n { id: 'github', name: 'GitHub', does: 'Link pull requests to tasks and close tasks when they merge.', stops: 'Pull requests stop linking to tasks.', account: 'acme', brand: 'github' },\n { id: 'google', name: 'Google Calendar', does: 'Show your calendar events beside your tasks.', stops: 'Calendar events stop showing beside tasks.', account: 'dana@acme.example', brand: 'google' },\n { id: 'figma', name: 'Figma', does: 'Show a preview when someone pastes a Figma link.', stops: 'Figma links stop showing a preview.', account: 'Acme team' },\n];\n\nfunction renderLogo(p: Provider) {\n if (p.brand) return <BrandIcon name={p.brand} size={24} />;\n return <Icon icon={p.id === 'slack' ? Slack : Figma} size=\"medium\" color=\"secondary\" />;\n}\n\nexport default function IntegrationsListRows() {\n // Opens with GitHub needing attention, as if its access ran out.\n const [connected, setConnected] = useState<Record<string, boolean>>({ github: true, google: true });\n const [needsAttention, setNeedsAttention] = useState<Record<string, boolean>>({ github: true });\n const [working, setWorking] = useState<string | null>(null);\n const [confirming, setConfirming] = useState<Provider | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => timers.current.forEach(clearTimeout), []);\n\n // Stands in for the sign-in a provider asks for, and the request that follows.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleConnect(p: Provider) {\n if (working) return;\n setWorking(p.id);\n later(() => {\n setWorking(null);\n setConnected((current) => ({ ...current, [p.id]: true }));\n setNeedsAttention((current) => ({ ...current, [p.id]: false }));\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (working) return;\n setConfirming(null);\n }\n\n function handleDisconnect(p: Provider) {\n if (working) return;\n setWorking(p.id);\n later(() => {\n setWorking(null);\n setConfirming(null);\n setConnected((current) => ({ ...current, [p.id]: false }));\n setNeedsAttention((current) => ({ ...current, [p.id]: false }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Integrations</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Connect the tools your team already uses.</Paragraph>\n </Stack>\n <TableContainer>\n {providers.map((p) => {\n const isConnected = Boolean(connected[p.id]);\n const attention = isConnected && Boolean(needsAttention[p.id]);\n const busy = working === p.id;\n return (\n <TableRow key={p.id}>\n <TableCell width=\"56px\">{renderLogo(p)}</TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{p.name}</Heading>\n {attention && <Tag variant=\"contained\" size=\"small\" color=\"warning\" label=\"Needs attention\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {attention ? 'Access ran out. Reconnect to keep it working.' : p.does}\n </Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {isConnected ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Paragraph size=\"body2\" measure=\"none\">{p.account}</Paragraph>\n {attention && <Button size=\"small\" type=\"primary\" state={working && !busy ? 'disabled' : 'enabled'} label=\"Reconnect\" aria-label={`Reconnect ${p.name}`} loading={busy} onClickButton={() => handleConnect(p)} />}\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Disconnect\" aria-label={`Disconnect ${p.name}`} onClickButton={() => setConfirming(p)} />\n </Cluster>\n ) : (\n <Cluster gap=\"small\" justify=\"end\">\n <Button size=\"small\" type=\"secondary\" state={working && !busy ? 'disabled' : 'enabled'} label=\"Connect\" aria-label={`Connect ${p.name}`} loading={busy} onClickButton={() => handleConnect(p)} />\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={confirming !== null}\n size=\"small\"\n title={confirming ? `Disconnect ${confirming.name}` : 'Disconnect'}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Disconnect\" loading={Boolean(working)} onClickButton={() => confirming && handleDisconnect(confirming)} />\n </>\n }\n >\n {confirming && (\n <Paragraph measure=\"none\">{confirming.stops} You can connect {confirming.name} again any time.</Paragraph>\n )}\n </Modal>\n </Center>\n );\n}\n",
1876
+ "uses": [
1877
+ "BrandIcon",
1878
+ "Button",
1879
+ "Center",
1880
+ "Cluster",
1881
+ "Heading",
1882
+ "Icon",
1883
+ "Modal",
1884
+ "Paragraph",
1885
+ "Stack",
1886
+ "TableCell",
1887
+ "TableContainer",
1888
+ "TableRow",
1889
+ "Tag"
1890
+ ]
1891
+ },
1892
+ {
1893
+ "id": "nested",
1894
+ "title": "Accounts under each provider",
1895
+ "useWhen": "A provider can hold several accounts or teams, such as the organizations of one GitHub login.",
1896
+ "source": "'use client';\nimport { Fragment, useEffect, useRef, useState } from 'react';\nimport { Slack } from 'lucide-react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Account = { id: string; name: string; detail: string; attention?: boolean };\ntype Provider = {\n id: string;\n name: string;\n /** One line on what connecting does. */\n does: string;\n /** What stops when one account is disconnected, for the confirm. */\n stops: string;\n brand?: 'github';\n accounts: Account[];\n};\n\nconst firstProviders: Provider[] = [\n {\n id: 'github',\n name: 'GitHub',\n does: 'Link pull requests to tasks and close tasks when they merge.',\n stops: 'Pull requests from it stop linking to tasks.',\n brand: 'github',\n accounts: [\n { id: 'acme', name: 'acme', detail: 'Connected Oct 3 · 14 repositories' },\n { id: 'acme-labs', name: 'acme-labs', detail: 'Access ran out. Reconnect to keep it working.', attention: true },\n ],\n },\n {\n id: 'slack',\n name: 'Slack',\n does: 'Post the weekly digest and link previews in your channels.',\n stops: 'The digest and link previews stop in its channels.',\n accounts: [],\n },\n];\n\nexport default function IntegrationsListNested() {\n const [providers, setProviders] = useState(firstProviders);\n // Which Button is working: it shows `loading`, and every other Button waits.\n const [working, setWorking] = useState<string | null>(null);\n const [confirming, setConfirming] = useState<{ provider: Provider; account: Account } | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => timers.current.forEach(clearTimeout), []);\n\n // Stands in for the sign-in a provider asks for, and the request that follows.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function update(providerId: string, change: (accounts: Account[]) => Account[]) {\n setProviders((list) => list.map((p) => (p.id === providerId ? { ...p, accounts: change(p.accounts) } : p)));\n }\n\n // 'Connect' and 'Add Account' both start a sign-in, and the account that comes back joins its provider.\n function handleAdd(p: Provider) {\n if (working) return;\n setWorking(`add-${p.id}`);\n later(() => {\n setWorking(null);\n const next: Account = p.id === 'github'\n ? { id: 'acme-design', name: 'acme-design', detail: 'Connected today · 3 repositories' }\n : { id: 'acme-slack', name: 'Acme', detail: 'Connected today · 6 channels' };\n update(p.id, (accounts) => [...accounts, next]);\n }, 1200);\n }\n\n function handleReconnect(p: Provider, a: Account) {\n if (working) return;\n setWorking(`reconnect-${a.id}`);\n later(() => {\n setWorking(null);\n update(p.id, (accounts) => accounts.map((x) => (x.id === a.id ? { ...x, detail: 'Connected today · 5 repositories', attention: false } : x)));\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (working) return;\n setConfirming(null);\n }\n\n function handleDisconnect(p: Provider, a: Account) {\n if (working) return;\n setWorking(`remove-${a.id}`);\n later(() => {\n setWorking(null);\n setConfirming(null);\n update(p.id, (accounts) => accounts.filter((x) => x.id !== a.id));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Integrations</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">A tool can hold several accounts. Each one connects and disconnects on its own.</Paragraph>\n </Stack>\n <TableContainer>\n {providers.map((p) => (\n <Fragment key={p.id}>\n <TableRow>\n <TableCell width=\"56px\">\n {p.brand ? <BrandIcon name={p.brand} size={24} /> : <Icon icon={Slack} size=\"medium\" color=\"secondary\" />}\n </TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{p.name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.does}</Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"240px\">\n <Cluster justify=\"end\">\n <Button\n size=\"small\"\n type=\"secondary\"\n state={working && working !== `add-${p.id}` ? 'disabled' : 'enabled'}\n label={p.accounts.length === 0 ? 'Connect' : 'Add Account'}\n aria-label={p.accounts.length === 0 ? `Connect ${p.name}` : `Add Account to ${p.name}`}\n loading={working === `add-${p.id}`}\n onClickButton={() => handleAdd(p)}\n />\n </Cluster>\n </TableCell>\n </TableRow>\n {/* The accounts sit under their provider, indented by an empty first cell. */}\n {p.accounts.map((a) => (\n <TableRow key={a.id}>\n <TableCell width=\"56px\">{''}</TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"subtitle1\">{a.name}</Heading>\n {a.attention && <Tag variant=\"contained\" size=\"small\" color=\"warning\" label=\"Needs attention\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{a.detail}</Paragraph>\n </Stack>\n </TableCell>\n <TableCell width=\"240px\">\n <Cluster gap=\"small\" justify=\"end\">\n {a.attention && (\n <Button size=\"small\" type=\"primary\" state={working && working !== `reconnect-${a.id}` ? 'disabled' : 'enabled'} label=\"Reconnect\" aria-label={`Reconnect ${a.name}`} loading={working === `reconnect-${a.id}`} onClickButton={() => handleReconnect(p, a)} />\n )}\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Disconnect\" aria-label={`Disconnect ${a.name}`} onClickButton={() => setConfirming({ provider: p, account: a })} />\n </Cluster>\n </TableCell>\n </TableRow>\n ))}\n </Fragment>\n ))}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={confirming !== null}\n size=\"small\"\n title={confirming ? `Disconnect ${confirming.account.name}` : 'Disconnect'}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Disconnect\" loading={Boolean(working)} onClickButton={() => confirming && handleDisconnect(confirming.provider, confirming.account)} />\n </>\n }\n >\n {confirming && (\n <Paragraph measure=\"none\">\n {confirming.provider.stops} You can connect {confirming.account.name} again any time.\n </Paragraph>\n )}\n </Modal>\n </Center>\n );\n}\n",
1897
+ "uses": [
1898
+ "BrandIcon",
1899
+ "Button",
1900
+ "Center",
1901
+ "Cluster",
1902
+ "Heading",
1903
+ "Icon",
1904
+ "Modal",
1905
+ "Paragraph",
1906
+ "Stack",
1907
+ "TableCell",
1908
+ "TableContainer",
1909
+ "TableRow",
1910
+ "Tag"
1911
+ ]
1912
+ }
1913
+ ]
1914
+ },
1141
1915
  {
1142
1916
  "id": "invite-member",
1143
1917
  "title": "Member invite",
@@ -1169,10 +1943,6 @@
1169
1943
  "Do not touch `navigator` while the page renders. Copy only in the click handler."
1170
1944
  ],
1171
1945
  "native": "On Apple use a sheet with a `Form`, share the link with `ShareLink`, and revoke a link with a `.destructive` Button that asks first in a `confirmationDialog`.",
1172
- "notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates an invite, labels the way out 'Close' and reads 'Copied!'. It cancels an invite link on one click with no confirm. Scindo's Apple app cancels a pending invite with no confirm too.",
1173
- "seenIn": [
1174
- "Scindo"
1175
- ],
1176
1946
  "options": [
1177
1947
  {
1178
1948
  "id": "by-email",
@@ -1242,11 +2012,6 @@
1242
2012
  "Do not replace the whole page when only one section failed."
1243
2013
  ],
1244
2014
  "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
1245
- "notBuiltYet": "Scindo on the web shows its empty list, with no Try Again, when its API keys or its members fail to load. Commentify puts its 'Try again' Button under `EmptyBox`, not in its `action`.",
1246
- "seenIn": [
1247
- "Commentify",
1248
- "Scindo"
1249
- ],
1250
2015
  "options": [
1251
2016
  {
1252
2017
  "id": "region",
@@ -1302,12 +2067,6 @@
1302
2067
  "Do not show a toast after logging out. The logged-out page says it."
1303
2068
  ],
1304
2069
  "native": "On Apple use a system `confirmationDialog` titled 'Log Out', with a 'Log Out' Button and 'Cancel' in the `.cancel` role. Leave out the `.destructive` role: nothing is destroyed.",
1305
- "notBuiltYet": "Scindo on the web says 'Log Out' but colors it as danger. Scindo on Apple says 'Sign Out' and puts it in the destructive role. Commentify and Commentify admin say 'Sign Out', title the Modal 'Confirm Sign Out', label the action 'Yes, Sign Out' and ask 'Are you sure you want to sign out?'.",
1306
- "seenIn": [
1307
- "Commentify",
1308
- "Commentify admin",
1309
- "Scindo"
1310
- ],
1311
2070
  "options": [
1312
2071
  {
1313
2072
  "id": "modal",
@@ -1348,12 +2107,6 @@
1348
2107
  "Do not say which of the email or the password was wrong."
1349
2108
  ],
1350
2109
  "native": "On Apple use `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
1351
- "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while logging in. They do not use the Button's loading state yet.",
1352
- "seenIn": [
1353
- "Commentify",
1354
- "Commentify admin",
1355
- "Scindo"
1356
- ],
1357
2110
  "options": [
1358
2111
  {
1359
2112
  "id": "centered",
@@ -1432,195 +2185,1210 @@
1432
2185
  ]
1433
2186
  },
1434
2187
  {
1435
- "id": "not-found-page",
1436
- "title": "Page not found",
2188
+ "id": "members-list",
2189
+ "title": "Members",
1437
2190
  "kind": "design",
1438
- "level": "page",
1439
- "area": "state",
1440
- "situation": "A person opens a link to a page that does not exist.",
2191
+ "level": "organism",
2192
+ "area": "settings",
2193
+ "situation": "An admin sees who is in the workspace, changes their roles, removes people and invites more.",
1441
2194
  "do": [
1442
- "Say 'Page not found' in a `Heading` with `level={1}`.",
1443
- "Add one line on what may have happened: 'The link may be wrong, or the page was moved or removed.'",
1444
- "Offer one Button home: 'Go Home'."
2195
+ "Show each member in a row: `UserImage` with `decorative`, the name, the email and the role. The avatar sits beside the same name, so it is hidden from a screen reader.",
2196
+ "Give an admin a `Select` for the role in each row. It saves as soon as it changes, as the rule 'A setting saves in place, or with one Save Button' says. Show no toast. When the save fails, put the old role back and show an inline `Alert` with `type=\"error\"` under the Select, which a screen reader announces. Point the Select's `aria-describedby` at the Alert's `id`.",
2197
+ "Give each role `Select` an `aria-label` that names the person: 'Role for Ben Carter'.",
2198
+ "Show a person who is not an admin the role as plain text, with one line at the top: 'Only admins can change this.' They get no Select, Remove or invites.",
2199
+ "Show your own role as text with a 'You' Tag, and give your row no Remove.",
2200
+ "Confirm 'Remove' in the row, as the case 'Delete confirm' does: the row asks 'Remove Ben Carter?' and shows 'Cancel' and a danger 'Remove'. Then show a toast: 'Ben Carter removed from Acme.'",
2201
+ "Give each row's 'Remove', and the confirm's 'Cancel' and 'Remove', an `aria-label` that names the person: 'Remove Ben Carter' and 'Cancel removing Ben Carter'.",
2202
+ "List pending invites under the members. Each has 'Copy Link', which reads 'Copied' for 2 seconds, and 'Revoke Invite'.",
2203
+ "Confirm 'Revoke Invite' in the row before it ends the link: the row shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'Invite for sam@partner.example revoked.'",
2204
+ "Name the invite in each `aria-label`: 'Revoke invite for sam@partner.example' and 'Cancel revoking the invite for sam@partner.example'.",
2205
+ "Open the Modal of the case 'Member invite' from an 'Invite Member' Button. Count a pending invite as a seat, because it holds one until it is accepted or revoked.",
2206
+ "Keep 'Invite Member' pressable at the seat limit. Open the Modal of the case 'Upgrade prompt', titled 'Upgrade to Pro', that says all the seats are filled.",
2207
+ "Say how many seats are used under the title: '7 of 8 seats used on the Free plan.'",
2208
+ "Sort a table by a Button in the header cell. `TableHeaderCell` has no `aria-sort`, so the Button's `aria-label` says the state and what a press does: 'Name, sorted ascending. Sort descending.'",
2209
+ "Use `state=\"selected\"` and an arrow on the Button of the column that is sorted. The first press sorts A to Z and the next one reverses it."
1445
2210
  ],
1446
2211
  "dont": [
1447
- "Do not make '404' the heading.",
1448
- "Do not show a line of text with no way home.",
1449
- "Do not blame the person for the link."
2212
+ "Do not show a role Select in a row of a person who cannot change roles, or in your own row.",
2213
+ "Do not remove a member on the first click of 'Remove'.",
2214
+ "Do not ask 'Are you sure?'. Name the person in the question.",
2215
+ "Do not disable 'Invite Member' at the seat limit. Let the person press it and learn why.",
2216
+ "Do not leave a Select without a name that says whose role it sets.",
2217
+ "Do not show a failed role save as red text written by hand. Use an inline `Alert`, or the error line of `FormField` when the control has a visible label.",
2218
+ "Do not label a running Button 'Removing…'. It keeps its label and shows `loading`."
2219
+ ],
2220
+ "native": "On Apple use a `Table` with a `Picker` for the role, and a `.destructive` Button that asks in a `confirmationDialog`. On Android use a list with a menu for the role and a confirm for Remove.",
2221
+ "options": [
2222
+ {
2223
+ "id": "rows",
2224
+ "title": "A list of rows",
2225
+ "useWhen": "A workspace of a few dozen people, so the whole list fits and a person finds someone by looking.",
2226
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2227
+ "uses": [
2228
+ "Alert",
2229
+ "Button",
2230
+ "Center",
2231
+ "Cluster",
2232
+ "Form",
2233
+ "Heading",
2234
+ "Modal",
2235
+ "Paragraph",
2236
+ "Select",
2237
+ "Stack",
2238
+ "TableCell",
2239
+ "TableContainer",
2240
+ "TableRow",
2241
+ "Tag",
2242
+ "TextField",
2243
+ "Toaster",
2244
+ "UserImage",
2245
+ "dismissToast",
2246
+ "toast"
2247
+ ]
2248
+ },
2249
+ {
2250
+ "id": "table",
2251
+ "title": "A table with sorting",
2252
+ "useWhen": "More people than a person can scan. The columns Name and Role sort.",
2253
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The header cell has no `aria-sort`, so the Button's name says the state and what a press does.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n const next = active && sort.dir === 'ascending' ? 'descending' : 'ascending';\n const now = active ? `sorted ${sort.dir}` : 'not sorted';\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n aria-label={`${label}, ${now}. Sort ${next}.`}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\">{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2254
+ "uses": [
2255
+ "Alert",
2256
+ "Button",
2257
+ "Center",
2258
+ "Cluster",
2259
+ "Form",
2260
+ "Heading",
2261
+ "Modal",
2262
+ "Paragraph",
2263
+ "Select",
2264
+ "Stack",
2265
+ "TableCell",
2266
+ "TableContainer",
2267
+ "TableHeader",
2268
+ "TableHeaderCell",
2269
+ "TableRow",
2270
+ "Tag",
2271
+ "TextField",
2272
+ "Toaster",
2273
+ "UserImage",
2274
+ "dismissToast",
2275
+ "toast"
2276
+ ]
2277
+ }
2278
+ ]
2279
+ },
2280
+ {
2281
+ "id": "mention-list",
2282
+ "title": "Mention list",
2283
+ "kind": "design",
2284
+ "level": "organism",
2285
+ "area": "chat",
2286
+ "situation": "A person types @ in the message box to name someone, or the agent.",
2287
+ "do": [
2288
+ "Open the list when the person types @ at the start of the text or after a space. A bare @ opens it, and each letter after it narrows it.",
2289
+ "Show at most 8 names. Typing more letters finds the rest.",
2290
+ "Build it as a combobox. The text area gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows with `isActive` and `aria-selected`.",
2291
+ "Show each person's avatar and name. A person with no picture shows their initial, and the avatar is not read aloud, since the name is.",
2292
+ "Put the agent first, with its icon avatar and an 'Agent' tag, as the rule 'An agent says what it is' says.",
2293
+ "Keep focus in the message box while the list is open, so the person keeps typing.",
2294
+ "Move the highlight with the arrow keys. Enter or Tab picks the highlighted name, and Escape closes the list.",
2295
+ "Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.",
2296
+ "Close the list when the caret moves out of the name being typed, and when focus leaves the message box.",
2297
+ "Check the word at the caret again on Enter or Tab, and pick only if a name still matches. Shift+Tab picks nothing.",
2298
+ "Put the name in at the caret with a space after it, and put the caret after the space.",
2299
+ "Close the list when no name matches.",
2300
+ "Leave out the person who is typing."
2301
+ ],
2302
+ "dont": [
2303
+ "Do not move focus into the list. The person keeps typing in the field.",
2304
+ "Do not send the message on the Enter that picks a name.",
2305
+ "Do not show an empty list.",
2306
+ "Do not open the list for an @ inside a word, such as in an email address.",
2307
+ "Do not show the agent with a photo or an initial."
2308
+ ],
2309
+ "native": "On Apple the list shows above the field, the agent with a sparkles icon and people with a person icon. A name is picked with a click or a tap.",
2310
+ "options": [
2311
+ {
2312
+ "id": "in-composer",
2313
+ "title": "List in the composer",
2314
+ "useWhen": "The default: the list opens over the text while the person types a name.",
2315
+ "source": "'use client';\nimport { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the session and the workspace.\nconst me = 'Dana Lee';\ntype Member = { id: string; name: string; agent?: boolean };\n// The agent comes first.\nconst members: Member[] = [\n { id: 'acme-agent', name: 'Acme Agent', agent: true },\n { id: 'ben-carter', name: 'Ben Carter' },\n { id: 'dana-lee', name: 'Dana Lee' },\n { id: 'omar-reyes', name: 'Omar Reyes' },\n];\n\nconst listId = 'mention-list-suggestions';\n// The list shows at most this many names; typing more letters narrows it.\nconst MAX_MATCHES = 8;\nconst optionId = (m: Member) => `mention-list-option-${m.id}`;\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who checks the links before we announce it?' },\n];\n\n// Opens with the person part-way through a mention, so the list shows.\nconst firstText = 'Can you check the links, @';\n\n// The word after the @ that ends the text before the caret, or null when there is none. The @ starts\n// the text or follows a space, so an email address such as dana@example.com opens nothing.\nfunction mentionQuery(before: string) {\n const match = before.match(/(?:^|\\s)@(\\w*)$/);\n return match ? match[1] : null;\n}\n\n// The query for where the caret is now.\nfunction queryAtCaret(field: HTMLTextAreaElement) {\n return mentionQuery(field.value.slice(0, field.selectionStart ?? field.value.length));\n}\n\n// Names with a word that starts with what was typed, at most 8. The person typing is left out.\nfunction matches(query: string) {\n const q = query.toLowerCase();\n return members.filter((m) => m.name !== me && m.name.toLowerCase().split(' ').some((w) => w.startsWith(q))).slice(0, MAX_MATCHES);\n}\n\nexport default function MentionListInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState(firstText);\n const [query, setQuery] = useState<string | null>(mentionQuery(firstText));\n const [active, setActive] = useState(0);\n // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.\n const [caret, setCaret] = useState<number | null>(null);\n const field = useRef<HTMLTextAreaElement>(null);\n\n const results = query === null ? [] : matches(query);\n // No match: the list closes.\n const open = results.length > 0;\n\n // The field opens with the caret at the end, after the @.\n useEffect(() => {\n const end = field.current?.value.length ?? 0;\n field.current?.setSelectionRange(end, end);\n }, []);\n\n useEffect(() => {\n if (caret === null || !field.current) return;\n field.current.focus();\n field.current.setSelectionRange(caret, caret);\n setCaret(null);\n }, [caret]);\n\n function change(value: string) {\n setText(value);\n const at = field.current?.selectionStart ?? value.length;\n setQuery(mentionQuery(value.slice(0, at)));\n setActive(0);\n }\n\n // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and\n // closes when the caret leaves it.\n function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {\n const next = queryAtCaret(e.currentTarget);\n if (next === query) return;\n setQuery(next);\n setActive(0);\n }\n\n // Puts '@Name ' in place of the @ and the word typed so far, and the caret after the space.\n function pick(m: Member) {\n const at = field.current?.selectionStart ?? text.length;\n const before = text.slice(0, at);\n const start = before.lastIndexOf('@');\n if (start < 0) return;\n const inserted = `@${m.name} `;\n setText(before.slice(0, start) + inserted + text.slice(at));\n setQuery(null);\n setCaret(start + inserted.length);\n }\n\n // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.\n function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!open) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {\n // Check the word at the caret again before taking the key. If nothing matches now, the list\n // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.\n const now = queryAtCaret(e.currentTarget);\n const found = now === null ? [] : matches(now);\n if (found.length === 0) {\n setQuery(null);\n return;\n }\n e.preventDefault();\n pick(found[now === query ? Math.min(active, found.length - 1) : 0]);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n setQuery(null);\n }\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n setQuery(null);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"mention-list-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={change}\n onSubmit={send}\n onKeyDown={keyDown}\n onSelect={caretMoved}\n // A press on a row keeps focus in the field, so this runs only when focus leaves for good.\n onBlur={() => setQuery(null)}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-activedescendant={open ? optionId(results[active]) : undefined}\n above={\n open ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"People and agents\" width={280}>\n {results.map((m, i) => (\n <MenuItem\n key={m.id}\n id={optionId(m)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n // A person may have no picture, so the avatar goes in icon: UserImage shows the initial.\n icon={m.agent ? <UserImage userHandle={m.name} icon={Bot} size={20} decorative /> : <UserImage userHandle={m.name} size={20} decorative />}\n label={m.name}\n tag={m.agent ? { label: 'Agent' } : undefined}\n onClick={() => pick(m)}\n />\n ))}\n </Menu>\n ) : undefined\n }\n />\n </Stack>\n </Center>\n );\n}\n",
2316
+ "uses": [
2317
+ "Center",
2318
+ "Composer",
2319
+ "Heading",
2320
+ "Menu",
2321
+ "MenuItem",
2322
+ "Message",
2323
+ "Paragraph",
2324
+ "Stack",
2325
+ "TimeStamp",
2326
+ "UserImage"
2327
+ ]
2328
+ }
2329
+ ]
2330
+ },
2331
+ {
2332
+ "id": "message-actions",
2333
+ "title": "Message actions",
2334
+ "kind": "design",
2335
+ "level": "organism",
2336
+ "area": "chat",
2337
+ "situation": "A person acts on one message: reacts to it, copies it, edits or deletes it.",
2338
+ "do": [
2339
+ "Put the actions in the Message's `actions`. They show while the pointer is on the row or focus is in it.",
2340
+ "Use the More menu on a touch screen, where `actions` always show: one button per row instead of four.",
2341
+ "Order them Add reaction, Copy, then Edit and Delete. Edit and Delete show only on the person's own messages.",
2342
+ "Give each `IconButton` a short `Tooltip`, such as 'Add reaction' or 'Copy'. Give it an `ariaLabel` in sentence case that names the row's message: 'Add reaction to message from Dana Lee'.",
2343
+ "Call the reaction action 'Add Reaction' in the menu, the same action as the 'Add reaction' button.",
2344
+ "Swap Copy's icon to `Check` for 2 seconds after it copies, as the rule 'Success shows where the person is looking' says.",
2345
+ "Show the toast 'Message copied.' when Copy is chosen from a menu, because the menu item is gone.",
2346
+ "Check that the example is still mounted before the clipboard promise sets state, starts a timer or shows a toast.",
2347
+ "Confirm Delete in the row, as the case 'Delete confirm' says for a row in a dense list. The row's `footer` shows 'Delete this message?', 'Cancel', then a danger 'Delete'.",
2348
+ "Make 'Cancel' a small tertiary Button and 'Delete' a small primary Button with `color=\"danger\"`. Hide the row's actions while it asks.",
2349
+ "Show 'Delete' as `loading` while the request runs, and disable 'Cancel'.",
2350
+ "Move focus to 'Cancel' when the confirm opens, and back to the row's Delete or More button after 'Cancel'.",
2351
+ "Remove the row once the message is deleted, and show a toast that names it: 'Message deleted.'",
2352
+ "Move focus to the next row's first action after a delete, or to the message box when no row follows.",
2353
+ "Edit the message in place, as the case 'Message edit' says. After Save or Cancel, focus goes to the row's Edit or More button.",
2354
+ "Put every action in a More menu when there are more than four: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Message actions\">`.",
2355
+ "Open the menu from the More button the person pressed: pass `event.currentTarget` to the Popover as `anchorEl`.",
2356
+ "Keep the More button on screen with `actionsVisible` while its menu is open.",
2357
+ "Make Delete the last item, a `MenuItem` with `color=\"danger\"`."
2358
+ ],
2359
+ "dont": [
2360
+ "Do not delete a message on the first click.",
2361
+ "Do not open a Modal to confirm a delete. The confirm stays in the row, so the person keeps their place in the thread.",
2362
+ "Do not show the actions only on pointer hover. A keyboard and a touch screen must reach them too.",
2363
+ "Do not show Edit or Delete on someone else's message.",
2364
+ "Do not open the menu when the page loads."
2365
+ ],
2366
+ "native": "On Apple put the actions in the row's `contextMenu`: Copy, Edit, Add Reaction, Create Task and Report, with Delete last in the `.destructive` role. Delete asks in a system `confirmationDialog`, not in the row.",
2367
+ "options": [
2368
+ {
2369
+ "id": "hover-toolbar",
2370
+ "title": "Toolbar on the row",
2371
+ "useWhen": "A product used with a pointer, with three or four frequent actions.",
2372
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsHoverToolbar() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [copiedId, setCopiedId] = useState<string | null>(null);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's buttons by row id, so focus can move to one when the thing that had it is gone.\n const reactButtons = useRef<Record<string, Focusable>>({});\n const editButtons = useRef<Record<string, Focusable>>({});\n const deleteButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(copyTimer.current);\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(id: string) {\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, reacted: !m.reacted } : m)));\n }\n\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n setCopiedId(m.id);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopiedId(null), 2000);\n }, () => {});\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's Edit button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => editButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(id: string) {\n setConfirmingId(id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Delete button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => deleteButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's first action, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? reactButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => {\n const own = m.from === me;\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n actions={\n editing || confirming ? undefined : (\n <>\n <Tooltip title=\"Add reaction\">\n <IconButton\n ref={(el) => { reactButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => react(m.id)}\n />\n </Tooltip>\n <Tooltip title={copiedId === m.id ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copiedId === m.id ? 'Check' : 'Copy'} ariaLabel={copiedId === m.id ? 'Copied' : `Copy message from ${m.from}`} onClick={() => copy(m)} />\n </Tooltip>\n {own && (\n <Tooltip title=\"Edit\">\n <IconButton ref={(el) => { editButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={() => startEditing(m)} />\n </Tooltip>\n )}\n {own && (\n <Tooltip title=\"Delete\">\n <IconButton ref={(el) => { deleteButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Trash2\" ariaLabel=\"Delete your message\" onClick={() => askToDelete(m.id)} />\n </Tooltip>\n )}\n </>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-hover-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-hover-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
2373
+ "uses": [
2374
+ "Button",
2375
+ "Center",
2376
+ "Cluster",
2377
+ "Composer",
2378
+ "Heading",
2379
+ "IconButton",
2380
+ "Message",
2381
+ "Paragraph",
2382
+ "Stack",
2383
+ "Tag",
2384
+ "TimeStamp",
2385
+ "Toaster",
2386
+ "Tooltip",
2387
+ "UserImage",
2388
+ "dismissToast",
2389
+ "toast"
2390
+ ]
2391
+ },
2392
+ {
2393
+ "id": "menu",
2394
+ "title": "More menu",
2395
+ "useWhen": "There are more than four actions, or the product is used on a touch screen.",
2396
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsMenu() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Row | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(m: Row) {\n setThread((rows) => rows.map((r) => (r.id === m.id ? { ...r, reacted: !r.reacted } : r)));\n }\n\n // The menu closes when an item is chosen, so a copy shows a toast rather than a check.\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Message copied.' }));\n }, () => {});\n }\n\n // A real app sends the task to the server here.\n function createTask(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `Task created from ${m.from}'s message.` }));\n }\n\n // A real app asks for a reason in a Modal, then sends the report.\n function report(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `${m.from}'s message reported to the workspace admins.` }));\n }\n\n function openMenu(m: Row, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === m.id) {\n closeMenu();\n return;\n }\n setMenuRow(m);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Escape, a click outside and every item close the menu. Popover's returnFocus gives focus back to More.\n function closeMenu() {\n setMenuOpen(false);\n }\n\n function choose(action: (m: Row) => void) {\n if (!menuRow) return;\n const m = menuRow;\n closeMenu();\n action(m);\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's More button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(m: Row) {\n setConfirmingId(m.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's More button, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? moreButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => {\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // One More button. Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n // It stays on screen while its menu is open, though the pointer and focus are in the menu.\n actionsVisible={menuOpen && menuRow?.id === m.id}\n actions={\n editing || confirming ? undefined : (\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(m, e.currentTarget)}\n />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-menu-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-menu-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={closeMenu} returnFocus>\n <Menu navigable aria-label=\"Message actions\" width={200}>\n <MenuItem size=\"small\" iconName=\"SmilePlus\" label=\"Add Reaction\" onClick={() => choose(react)} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy\" onClick={() => choose(copy)} />\n {menuRow?.from === me && <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Edit\" onClick={() => choose(startEditing)} />}\n <MenuItem size=\"small\" iconName=\"ClipboardPlus\" label=\"Create Task\" onClick={() => choose(createTask)} />\n {menuRow?.from !== me && <MenuItem size=\"small\" iconName=\"Flag\" label=\"Report\" onClick={() => choose(report)} />}\n {menuRow?.from === me && <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
2397
+ "uses": [
2398
+ "Button",
2399
+ "Center",
2400
+ "Cluster",
2401
+ "Composer",
2402
+ "Heading",
2403
+ "IconButton",
2404
+ "Menu",
2405
+ "MenuItem",
2406
+ "Message",
2407
+ "Paragraph",
2408
+ "Popover",
2409
+ "Stack",
2410
+ "Tag",
2411
+ "TimeStamp",
2412
+ "Toaster",
2413
+ "Tooltip",
2414
+ "UserImage",
2415
+ "dismissToast",
2416
+ "toast"
2417
+ ]
2418
+ }
2419
+ ]
2420
+ },
2421
+ {
2422
+ "id": "message-attachments",
2423
+ "title": "Attachments",
2424
+ "kind": "design",
2425
+ "level": "organism",
2426
+ "area": "chat",
2427
+ "situation": "A person adds files to a message, and people open the files in a message that was sent.",
2428
+ "do": [
2429
+ "Show each waiting file as a `FileChip` in the Composer's `above` slot, with `onRemove`.",
2430
+ "Show a file that is still uploading with `state=\"uploading\"` and the `meta` 'Uploading'.",
2431
+ "Show a file that cannot be sent with `state=\"failed\"` and the reason in `meta`: 'Too large. The limit is 25 MB.'",
2432
+ "Pass `onClick` and the `meta` 'Failed. Try again' when the upload can be tried again. A file that is too large can only be removed.",
2433
+ "Announce when an upload finishes or fails: the app puts the words in a polite live region, since the chip announces nothing.",
2434
+ "Block sending while a file uploads or has failed, and say why under the chips: 'Wait for the upload to finish, then send.'",
2435
+ "Give that line an `id`, and point the message box at it with `aria-describedby`, so a screen reader hears why it cannot send.",
2436
+ "Say the limit in one line under the chips when it is reached: 'You can attach up to 5 files.' Disable the attach button too.",
2437
+ "Pass `canSubmit` so a message with files and no text can be sent.",
2438
+ "Keep the files and the text when a send fails. Show an inline error Alert above the message box, as the rule 'A form error shows next to the problem' says.",
2439
+ "Move focus to the next chip after a chip is removed, or to the message box when none is left, since the chip that had it is gone.",
2440
+ "Show images in a sent message as thumbnails: a `Grid` of `<Figure crop>` with an `Image` each. Write `alt` text that says what the image shows.",
2441
+ "Show other files as `FileChip`s that open the file, with the kind ('PDF'), the name and the size.",
2442
+ "Show a `FileChip` with the file's name in place of an image that fails to load, so the file can still be opened.",
2443
+ "Let the person open an image at full size. The example shows the thumbnails only."
2444
+ ],
2445
+ "dont": [
2446
+ "Do not show a failed upload only in an Alert away from the file.",
2447
+ "Do not use the file name as the `alt` text of an image. Say what it shows.",
2448
+ "Do not send a message while one of its files is still uploading.",
2449
+ "Do not clear the waiting files when a send is blocked."
2450
+ ],
2451
+ "native": "On Apple the attach button opens a menu with Photo Library and Files on iPhone, and opens Files on a Mac. Waiting files show as chips with a remove button. Sent images open full screen.",
2452
+ "options": [
2453
+ {
2454
+ "id": "in-composer",
2455
+ "title": "In the composer",
2456
+ "useWhen": "Files are waiting to be sent with the next message.",
2457
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport FileChip from 'oneslash-design-system/components/fileChip';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst MAX_FILES = 5;\n\ntype Upload = { id: string; name: string; kind: string; size: string; state: 'ready' | 'uploading' | 'failed'; error?: string };\ntype Row = { id: string; from: string; at: Date; text: string; files?: Upload[] };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Dana has the final versions.' },\n];\n\n// Opens with one file ready, one still uploading and one the server refused.\nconst firstFiles: Upload[] = [\n { id: 'f1', name: 'Launch brief.pdf', kind: 'PDF', size: '1.2 MB', state: 'ready' },\n { id: 'f2', name: 'Hero image.png', kind: 'PNG', size: '3.4 MB', state: 'uploading' },\n { id: 'f3', name: 'Product video.mov', kind: 'MOV', size: '48 MB', state: 'failed', error: 'Too large. The limit is 25 MB.' },\n];\n\n// What the attach button adds, in turn. A real app opens the file picker.\nconst sampleFiles = [\n { name: 'Press list.xlsx', kind: 'XLSX', size: '48 KB' },\n { name: 'Pricing sheet.pdf', kind: 'PDF', size: '320 KB' },\n { name: 'Logo.svg', kind: 'SVG', size: '12 KB' },\n];\n\n// Where a sent file opens. A real app links to the stored file.\nconst fileHref = (name: string) => `/files/${name.toLowerCase().replace(/\\s+/g, '-')}`;\n\n// The line that says why sending is blocked. The message box points at it with aria-describedby.\nconst blockedId = 'message-attachments-send-blocked';\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageAttachmentsInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [files, setFiles] = useState(firstFiles);\n const added = useRef(0);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops every upload still running.\n useEffect(() => () => {\n timers.current.forEach((t) => clearTimeout(t));\n timers.current = [];\n }, []);\n\n const atLimit = files.length >= MAX_FILES;\n const uploading = files.some((f) => f.state === 'uploading');\n const failed = files.find((f) => f.state === 'failed');\n const blockedReason = failed ? `Remove ${failed.name} to send.` : uploading ? 'Wait for the upload to finish, then send.' : null;\n\n function attach() {\n if (atLimit) return;\n const sample = sampleFiles[added.current % sampleFiles.length];\n const id = `a${added.current + 1}`;\n added.current += 1;\n setFiles((list) => [...list, { ...sample, id, state: 'uploading' }]);\n // Stands in for the request to the server.\n timers.current.push(\n setTimeout(() => {\n setFiles((list) => list.map((f) => (f.id === id ? { ...f, state: 'ready' } : f)));\n }, 1200),\n );\n }\n\n // The chip that had focus is gone. A real app moves focus to the next chip, or to the message box when\n // none is left. FileChip does not pass a ref to its remove button, so this example always uses the message box.\n function remove(id: string) {\n setFiles((list) => list.filter((f) => f.id !== id));\n field.current?.focus();\n }\n\n // The Composer calls this only when canSubmit is true: no upload running, none failed.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim(), files }]);\n setText('');\n setFiles([]);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n m.files && m.files.length > 0 ? (\n <Cluster gap=\"small\">\n {m.files.map((f) => (\n // A sent file opens when its chip is pressed.\n <FileChip key={f.id} name={f.name} kind={f.kind} meta={f.size} href={fileHref(f.name)} openInNewTab />\n ))}\n </Cluster>\n ) : undefined\n }\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"message-attachments-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n aria-describedby={blockedReason ? blockedId : undefined}\n // Files alone can be sent, but not while one uploads or has failed.\n canSubmit={(text.trim() !== '' || files.length > 0) && !uploading && !failed}\n above={\n files.length > 0 ? (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {files.map((f) => (\n <FileChip\n key={f.id}\n name={f.name}\n kind={f.kind}\n state={f.state}\n meta={f.state === 'uploading' ? 'Uploading' : f.state === 'failed' ? f.error : f.size}\n onRemove={() => remove(f.id)}\n />\n ))}\n </Cluster>\n {/* A real app also says these in a polite live region when they change. */}\n {blockedReason && (\n <Paragraph id={blockedId} size=\"caption\" tone=\"secondary\" measure=\"none\">{blockedReason}</Paragraph>\n )}\n {atLimit && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`You can attach up to ${MAX_FILES} files.`}</Paragraph>\n )}\n </Stack>\n ) : undefined\n }\n tools={\n <Tooltip title=\"Attach files\">\n <IconButton\n color=\"iconOnly\"\n state={atLimit ? 'disabled' : 'enabled'}\n size=\"small\"\n iconName=\"Paperclip\"\n ariaLabel=\"Attach files\"\n onClick={attach}\n />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
2458
+ "uses": [
2459
+ "Center",
2460
+ "Cluster",
2461
+ "Composer",
2462
+ "FileChip",
2463
+ "Heading",
2464
+ "IconButton",
2465
+ "Message",
2466
+ "Paragraph",
2467
+ "Stack",
2468
+ "TimeStamp",
2469
+ "Tooltip",
2470
+ "UserImage"
2471
+ ]
2472
+ },
2473
+ {
2474
+ "id": "in-message",
2475
+ "title": "In a sent message",
2476
+ "useWhen": "Files are part of a message in the thread.",
2477
+ "source": "'use client';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport FileChip from 'oneslash-design-system/components/fileChip';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Two small drawings stand in for the uploaded photos.\nconst hillside =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E\";\nconst desk =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E\";\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst before: Row = { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' };\nconst withFiles: Row = { id: 'm2', from: 'Dana Lee', at: new Date('2025-01-15T11:44:00Z'), text: 'Here are the two hero options and the brief.' };\n\nexport default function MessageAttachmentsInMessage() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={before.from}\n avatar={<UserImage userHandle={before.from} decorative />}\n name={before.from}\n meta={<TimeStamp createdAt={before.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{before.text}</Paragraph>\n </Message>\n <Message\n aria-label={withFiles.from}\n avatar={<UserImage userHandle={withFiles.from} decorative />}\n name={withFiles.from}\n meta={<TimeStamp createdAt={withFiles.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Stack gap=\"small\">\n {/* Small thumbnails: four columns, two of them used. A real app opens the full image on click. */}\n <Grid columns={4} compact gap=\"small\">\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={hillside} alt=\"Hero option A: a green hillside under a pale sky with the sun on the right\" width={160} height={120} />\n </Figure>\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={desk} alt=\"Hero option B: a laptop on a wooden desk, its screen blue\" width={160} height={120} />\n </Figure>\n </Grid>\n <Cluster gap=\"small\">\n {/* Each chip opens the file. */}\n <FileChip name=\"Launch brief.pdf\" kind=\"PDF\" meta=\"1.2 MB\" href=\"/files/launch-brief.pdf\" openInNewTab />\n <FileChip name=\"Press list.xlsx\" kind=\"XLSX\" meta=\"48 KB\" href=\"/files/press-list.xlsx\" openInNewTab />\n </Cluster>\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{withFiles.text}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
2478
+ "uses": [
2479
+ "Center",
2480
+ "Cluster",
2481
+ "Figure",
2482
+ "FileChip",
2483
+ "Grid",
2484
+ "Heading",
2485
+ "Image",
2486
+ "Message",
2487
+ "Paragraph",
2488
+ "Stack",
2489
+ "TimeStamp",
2490
+ "UserImage"
2491
+ ]
2492
+ }
2493
+ ]
2494
+ },
2495
+ {
2496
+ "id": "message-composer",
2497
+ "title": "Message composer",
2498
+ "kind": "design",
2499
+ "level": "organism",
2500
+ "area": "chat",
2501
+ "situation": "A person writes a message at the bottom of a thread.",
2502
+ "do": [
2503
+ "Use `Composer` under the thread, with an `aria-label`, since it has no visible label.",
2504
+ "Send on Enter and add a line on Shift+Enter, on a keyboard. On a touch screen, set `submitOnEnter={false}` so Return adds a line.",
2505
+ "Say who will read the message in the placeholder: 'Message the team', or 'Message Acme Agent' while the agent is called.",
2506
+ "Add the sent message to the thread at once, and set the Composer's `value` to an empty string.",
2507
+ "Put the tools in `tools`: an attach `IconButton`, and a toggle that calls the agent, `state=\"selected\"` and `aria-pressed` while it is on.",
2508
+ "Pass `canSubmit` when a file alone can be sent.",
2509
+ "Put Stop on the agent's progress row, as the rule 'An agent shows its progress' says. The Composer keeps Send, so a message to people still goes.",
2510
+ "Pass `onStop` in a conversation with the agent only, so Send becomes Stop.",
2511
+ "Show the agent's name, its 'Agent' `Tag`, the model line, the seconds so far and a `StepList` on the progress row. The case 'Agent at work' has the full pattern.",
2512
+ "Show 'Working for 12 seconds' in the progress row's body, above the steps.",
2513
+ "Show 'Stop' as `loading` until the run has ended. Then 'Stopped. Nothing was changed.' replaces the progress row in the same place.",
2514
+ "Move focus to the message box when Stop goes away.",
2515
+ "Announce the progress row politely to screen readers: the app wraps the changing part in a polite live region, since the row has none.",
2516
+ "Show an inline error Alert above the message box when a message fails to send, as the rule 'A form error shows next to the problem' says. Keep the text so it can be sent again.",
2517
+ "Keep the draft when the person leaves the thread, and show it again when they come back."
2518
+ ],
2519
+ "dont": [
2520
+ "Do not clear the field before the message is in the thread.",
2521
+ "Do not write a placeholder that does not say who reads the message, such as 'Type here'.",
2522
+ "Do not send on Return on a touch screen.",
2523
+ "Do not hide the Stop on the agent's row while the agent works.",
2524
+ "Do not turn Send into Stop in a thread that people also write in."
2525
+ ],
2526
+ "native": "On Apple use a `TextField` with `axis: .vertical`. On a Mac, Return sends and Shift-Return adds a line. On an iPhone, Return adds a line. While the agent works, Send becomes Stop.",
2527
+ "options": [
2528
+ {
2529
+ "id": "plain",
2530
+ "title": "Plain composer",
2531
+ "useWhen": "Only people read the thread.",
2532
+ "source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageComposerPlain() {\n const [thread, setThread] = useState(firstThread);\n // A real app keeps the draft per thread, so it is still there when the person comes back.\n const [text, setText] = useState('');\n\n // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is text.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}\n <Composer\n id=\"message-composer-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
2533
+ "uses": [
2534
+ "Center",
2535
+ "Composer",
2536
+ "Heading",
2537
+ "Message",
2538
+ "Paragraph",
2539
+ "Stack",
2540
+ "TimeStamp",
2541
+ "UserImage"
2542
+ ]
2543
+ },
2544
+ {
2545
+ "id": "with-tools",
2546
+ "title": "Composer with tools",
2547
+ "useWhen": "The person can attach files and call the agent.",
2548
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport FileChip from 'oneslash-design-system/components/fileChip';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst agentName = 'Acme Agent';\n\ntype Attachment = { name: string; kind: string; size: string };\n// `progress` marks the agent's row while its run is live. The same row later holds the note or the reply.\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; file?: Attachment; progress?: boolean };\n\nconst sampleFile: Attachment = { name: 'Launch email.pdf', kind: 'PDF', size: '240 KB' };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function MessageComposerWithTools() {\n const [thread, setThread] = useState(firstThread);\n // A real app keeps the draft per thread, so it is still there when the person comes back.\n const [text, setText] = useState('');\n const [file, setFile] = useState<Attachment | null>(null);\n const [mentionAgent, setMentionAgent] = useState(false);\n // The agent's run while it works: the id of its row in the thread, and whether a stop has been asked for.\n const [run, setRun] = useState<{ rowId: string; stopping: boolean } | null>(null);\n const [seconds, setSeconds] = useState(0);\n const runTimer = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops the agent's run, its clock and the cancel request.\n useEffect(() => () => {\n clearTimeout(runTimer.current);\n clearTimeout(cancel.current);\n clearInterval(tick.current);\n }, []);\n\n // The run is over: its own row, in the same place and with the same time, now holds the reply or the note.\n function endRun(rowId: string, text: string) {\n clearTimeout(runTimer.current);\n clearInterval(tick.current);\n setRun(null);\n setThread((rows) => rows.map((m) => (m.id === rowId ? { ...m, text, progress: false } : m)));\n }\n\n function addRow(row: Omit<Row, 'id'>) {\n setThread((rows) => [...rows, { ...row, id: `m${rows.length + 1}` }]);\n }\n\n // A real app opens the file picker here; this one attaches a sample file.\n function attach() {\n setFile(sampleFile);\n }\n\n function removeFile() {\n setFile(null);\n field.current?.focus();\n }\n\n // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is something to send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n addRow({ from: me, at: new Date(), text: text.trim(), file: file ?? undefined });\n setText('');\n setFile(null);\n // One run at a time: a real app queues a second call to the agent.\n if (!mentionAgent || run) return;\n // The run gets one row, added now where the reply will appear. Messages sent during the run go below it.\n const startedAt = new Date();\n const rowId = `run-${startedAt.getTime()}`;\n setThread((rows) => [...rows, { id: rowId, from: agentName, agent: true, at: startedAt, text: '', progress: true }]);\n setRun({ rowId, stopping: false });\n setSeconds(0);\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n // Stands in for the agent's run.\n runTimer.current = setTimeout(() => {\n endRun(rowId, 'The email reads well. The pricing link in the second paragraph points to last year\\'s page.');\n }, 3000);\n }\n\n // Stop asks the server to end the run, and shows loading until it has. Only then does the note that it\n // stopped replace the progress row, in the same row. Stop is gone, so focus goes to the message box.\n function stop() {\n if (!run || run.stopping) return;\n clearTimeout(runTimer.current);\n setRun({ ...run, stopping: true });\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n endRun(run.rowId, 'Stopped. Nothing was changed.');\n field.current?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) =>\n m.progress && run?.rowId === m.id ? (\n // While the agent works, its row shows where the reply will appear: the seconds so far,\n // the steps, and the only Stop. The case 'Agent at work' has the full pattern.\n <Message\n key={m.id}\n aria-label={`${m.from}, agent`}\n avatar={<UserImage userHandle={m.from} icon={Bot} decorative />}\n name={m.from}\n meta={agentMeta(m.at)}\n footer={\n // It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run.stopping} onClickButton={stop} />\n </Cluster>\n }\n >\n {/* A real app wraps this part in a polite live region, since StepList has none. */}\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList\n aria-label=\"Acme Agent's steps\"\n steps={[\n { label: 'Read the thread', status: 'done' },\n { label: 'Checking the links in the email', status: 'running' },\n ]}\n />\n </Stack>\n </Message>\n ) : (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n compact={followsOn(thread, i)}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={m.agent ? agentMeta(m.at) : <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n // A sent file opens when its chip is pressed. A real app links to the stored file.\n footer={m.file ? <FileChip name={m.file.name} kind={m.file.kind} meta={m.file.size} href=\"/files/launch-email.pdf\" openInNewTab /> : undefined}\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ),\n )}\n </Stack>\n {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}\n <Composer\n ref={field}\n id=\"message-composer-tools-message\"\n aria-label=\"Message\"\n // The placeholder says who will read the message.\n placeholder={mentionAgent ? `Message ${agentName}` : 'Message the team'}\n value={text}\n onChange={setText}\n onSubmit={send}\n canSubmit={text.trim() !== '' || file !== null}\n // The Composer keeps Send while the agent works, so a message to people still goes. Stop is on the agent's row.\n above={file ? <FileChip name={file.name} kind={file.kind} meta={file.size} onRemove={removeFile} /> : undefined}\n tools={\n <>\n <Tooltip title=\"Attach files\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Paperclip\" ariaLabel=\"Attach files\" onClick={attach} />\n </Tooltip>\n <Tooltip title=\"Mention the agent\">\n <IconButton\n color=\"iconOnly\"\n state={mentionAgent ? 'selected' : 'enabled'}\n size=\"small\"\n icon={Bot}\n ariaLabel=\"Mention the agent\"\n aria-pressed={mentionAgent}\n onClick={() => setMentionAgent((on) => !on)}\n />\n </Tooltip>\n </>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
2549
+ "uses": [
2550
+ "Button",
2551
+ "Center",
2552
+ "Cluster",
2553
+ "Composer",
2554
+ "FileChip",
2555
+ "Heading",
2556
+ "IconButton",
2557
+ "Message",
2558
+ "Paragraph",
2559
+ "Stack",
2560
+ "StepList",
2561
+ "Tag",
2562
+ "TimeStamp",
2563
+ "Tooltip",
2564
+ "UserImage"
2565
+ ]
2566
+ }
2567
+ ]
2568
+ },
2569
+ {
2570
+ "id": "message-edit",
2571
+ "title": "Message edit",
2572
+ "kind": "design",
2573
+ "level": "organism",
2574
+ "area": "chat",
2575
+ "situation": "A person changes the text of a message they sent.",
2576
+ "do": [
2577
+ "Replace the row's body with a `Composer` that holds the text, and focus it with the caret after the text.",
2578
+ "Put 'Cancel' and 'Save' in the Composer's `actions`: `<Button type=\"tertiary\" size=\"small\">`, then `<Button type=\"primary\" size=\"small\">`.",
2579
+ "Save on Enter, and cancel on Escape. Take Escape in `onKeyDown` with `preventDefault()` and `stopPropagation()`.",
2580
+ "Pass `canSubmit` so an empty or unchanged text cannot be saved, and keep 'Save' `state=\"disabled\"` until then.",
2581
+ "Show 'Save' as `loading` while the request runs, keep its label, and disable the field and 'Cancel'.",
2582
+ "Show the new text in the row once it is saved, with '(edited)' after the time.",
2583
+ "Show '(edited)' on a compact row, which has no time line, as a caption in the row's `footer`.",
2584
+ "Move focus to the row's Edit or More button after Save or Cancel, since the field that had it is gone.",
2585
+ "Keep the field, its text, 'Cancel' and 'Save' when the save fails. Show an inline error Alert above the field, as the rule 'A form error shows next to the problem' says.",
2586
+ "Offer Edit only on the person's own messages."
2587
+ ],
2588
+ "dont": [
2589
+ "Do not open a Modal to edit a message. The text is on screen, so it becomes the field.",
2590
+ "Do not show a toast after an edit. The new text shows where the old one was.",
2591
+ "Do not change 'Save' to 'Saving…' while it runs.",
2592
+ "Do not let Escape in the field close a Modal or a panel around the thread."
2593
+ ],
2594
+ "native": "On Apple the text becomes a field in the row, with 'Cancel' and 'Save', and the row shows '(edited)' after.",
2595
+ "options": [
2596
+ {
2597
+ "id": "in-place",
2598
+ "title": "Edit in place",
2599
+ "useWhen": "The default: the message body becomes the field, where the text was.",
2600
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nconst question = { from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'When does the launch email go out?' };\nconst mine = { from: me, at: new Date('2025-01-15T11:42:00Z') };\n\nexport default function MessageEditInPlace() {\n const [text, setText] = useState('Thursday at 9:00.');\n const [edited, setEdited] = useState(false);\n // Opens with the message in edit mode, as if the person just chose Edit.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Thursday at 9:00.');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const field = useRef<HTMLTextAreaElement>(null);\n const editButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Set when the person presses Edit. The example opens in edit mode without it, so nothing takes focus on load.\n const pressedEdit = useRef(false);\n\n // When the person opens the field, focus it with the caret after the text. When it closes, the field\n // that had focus is gone, so focus goes to the row's Edit button.\n useEffect(() => {\n if (!editing) {\n editButton.current?.focus();\n return;\n }\n if (!pressedEdit.current || !field.current) return;\n const end = field.current.value.length;\n field.current.focus();\n field.current.setSelectionRange(end, end);\n }, [editing]);\n\n // An empty or unchanged text has nothing to save.\n const canSave = draft.trim() !== '' && draft.trim() !== text;\n\n function startEditing() {\n pressedEdit.current = true;\n setDraft(text);\n setEditing(true);\n }\n\n function cancel() {\n if (saving) return;\n setEditing(false);\n }\n\n function save() {\n if (saving || !canSave) return;\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n setText(draft.trim());\n setEdited(true);\n setEditing(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={question.from}\n avatar={<UserImage userHandle={question.from} decorative />}\n name={question.from}\n meta={<TimeStamp createdAt={question.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{question.text}</Paragraph>\n </Message>\n <Message\n aria-label={mine.from}\n avatar={<UserImage userHandle={mine.from} decorative />}\n name={mine.from}\n meta={\n <>\n <TimeStamp createdAt={mine.at} dateFormat=\"absolute\" data=\"time\" />\n {edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n actions={\n editing ? undefined : (\n <Tooltip title=\"Edit\">\n <IconButton ref={editButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={startEditing} />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // The body becomes a Composer in place. Enter saves and Escape cancels.\n <Composer\n ref={field}\n id=\"message-edit-text\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancel();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancel} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{text}</Paragraph>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
2601
+ "uses": [
2602
+ "Button",
2603
+ "Center",
2604
+ "Cluster",
2605
+ "Composer",
2606
+ "Heading",
2607
+ "IconButton",
2608
+ "Message",
2609
+ "Paragraph",
2610
+ "Stack",
2611
+ "TimeStamp",
2612
+ "Tooltip",
2613
+ "UserImage"
2614
+ ]
2615
+ }
2616
+ ]
2617
+ },
2618
+ {
2619
+ "id": "message-reactions",
2620
+ "title": "Reactions",
2621
+ "kind": "design",
2622
+ "level": "organism",
2623
+ "area": "chat",
2624
+ "situation": "People answer a message with an emoji instead of a reply.",
2625
+ "do": [
2626
+ "Put the reactions in the Message's `footer`: a `Cluster` of `Tag`s, then a small 'Add reaction' `IconButton`.",
2627
+ "Label each chip with the emoji and the count, such as '👍 3', and give it `state=\"selected\"` when the person reacted with it.",
2628
+ "Name the emoji in words in the chip's `aria-label`: 'Thumbs up, 3 reactions'. The chip's `aria-pressed` says whether the person reacted.",
2629
+ "Wrap each chip in a `Tooltip` that names who reacted, with the person last: 'Omar and you'.",
2630
+ "Add or remove the reaction when the chip is pressed, and change the count at once.",
2631
+ "Name the 'Add reaction' button after the row: 'Add reaction to message from Dana Lee'.",
2632
+ "Open the quick pick from 'Add reaction': `<Popover returnFocus>` around `<Menu navigable aria-label=\"Add reaction\">`, one `MenuItem` per emoji, named in words.",
2633
+ "Mark the emoji the person already used with an 'Added' tag. Picking it again removes it.",
2634
+ "Close the quick pick when an emoji is picked. Focus goes back to the button that opened it.",
2635
+ "Move focus to the 'Add reaction' button when the chip that had it disappears, because its count reached 0.",
2636
+ "Offer the six emoji for now: ODS has no full emoji picker yet."
2637
+ ],
2638
+ "dont": [
2639
+ "Do not show a chip with a count of 0.",
2640
+ "Do not name a chip by its emoji alone. A screen reader may read it differently, or not at all.",
2641
+ "Do not wait for the server before the count changes.",
2642
+ "Do not open the quick pick on hover. Open it on a press."
2643
+ ],
2644
+ "native": "On Apple a reaction is added from the row's `contextMenu`, with Add Reaction.",
2645
+ "options": [
2646
+ {
2647
+ "id": "chips",
2648
+ "title": "Reaction chips",
2649
+ "useWhen": "A message has reactions: each emoji shows under it with its count.",
2650
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// Each emoji's name in words, for its aria-label.\nconst emojiNames: Record<string, string> = { '👍': 'Thumbs up', '❤️': 'Heart', '🎉': 'Party popper' };\n\ntype Reaction = { emoji: string; by: string[] };\ntype Row = { id: string; from: string; at: Date; text: string; reactions: Reaction[] };\n\nconst firstThread: Row[] = [\n {\n id: 'm1',\n from: 'Ben Carter',\n at: new Date('2025-01-15T11:40:00Z'),\n text: 'The pricing page is live.',\n reactions: [\n { emoji: '👍', by: ['Omar Reyes', me] },\n { emoji: '🎉', by: ['Omar Reyes'] },\n ],\n },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Nice work. I will share it with the sales team.', reactions: [] },\n];\n\nconst firstName = (name: string) => name.split(' ')[0];\n\n// 'Omar and you': other people by first name, the person last.\nfunction whoReacted(by: string[]) {\n const names = [...by.filter((n) => n !== me).map(firstName), ...(by.includes(me) ? ['you'] : [])];\n if (names.length === 1) return names[0] === 'you' ? 'You' : names[0];\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\n// 'Thumbs up, 3 reactions'. The chip's aria-pressed says whether the person reacted.\nfunction chipName(r: Reaction) {\n const count = `${r.by.length} ${r.by.length === 1 ? 'reaction' : 'reactions'}`;\n return `${emojiNames[r.emoji]}, ${count}`;\n}\n\nexport default function MessageReactionsChips() {\n const [thread, setThread] = useState(firstThread);\n // Each row's 'Add reaction' button by row id. When the chip that had focus goes away, focus goes there.\n const addButtons = useRef<Record<string, HTMLButtonElement | HTMLAnchorElement | null>>({});\n const focusAdd = useRef<string | null>(null);\n\n useEffect(() => {\n if (!focusAdd.current) return;\n addButtons.current[focusAdd.current]?.focus();\n focusAdd.current = null;\n });\n\n // The count changes at once. A real app sends the change to the server and puts it back if that fails.\n function toggle(rowId: string, emoji: string) {\n const row = thread.find((m) => m.id === rowId);\n const chip = row?.reactions.find((r) => r.emoji === emoji);\n // The person's reaction was the last one, so the chip goes away.\n if (chip && chip.by.length === 1 && chip.by[0] === me) focusAdd.current = rowId;\n setThread((rows) =>\n rows.map((m) => {\n if (m.id !== rowId) return m;\n const has = m.reactions.find((r) => r.emoji === emoji);\n const reactions = has\n ? m.reactions.map((r) =>\n r.emoji !== emoji ? r : { ...r, by: r.by.includes(me) ? r.by.filter((n) => n !== me) : [...r.by, me] },\n )\n : [...m.reactions, { emoji, by: [me] }];\n // A chip with no reactions left goes away.\n return { ...m, reactions: reactions.filter((r) => r.by.length > 0) };\n }),\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Cluster gap=\"small\">\n {m.reactions.map((r) => (\n <Tooltip key={r.emoji} title={whoReacted(r.by)}>\n <Tag\n variant=\"contained\"\n size=\"small\"\n state={r.by.includes(me) ? 'selected' : 'enabled'}\n label={`${r.emoji} ${r.by.length}`}\n aria-label={chipName(r)}\n onClick={() => toggle(m.id, r.emoji)}\n />\n </Tooltip>\n ))}\n {/* A real app opens the quick pick here, as the option 'Quick pick' shows; this one adds a heart. */}\n <Tooltip title=\"Add reaction\">\n <IconButton\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n ref={(el) => { addButtons.current[m.id] = el; }}\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => {\n if (!m.reactions.some((r) => r.emoji === '❤️' && r.by.includes(me))) toggle(m.id, '❤️');\n }}\n />\n </Tooltip>\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
2651
+ "uses": [
2652
+ "Center",
2653
+ "Cluster",
2654
+ "Heading",
2655
+ "IconButton",
2656
+ "Message",
2657
+ "Paragraph",
2658
+ "Stack",
2659
+ "Tag",
2660
+ "TimeStamp",
2661
+ "Tooltip",
2662
+ "UserImage"
2663
+ ]
2664
+ },
2665
+ {
2666
+ "id": "quick-pick",
2667
+ "title": "Quick pick",
2668
+ "useWhen": "A person adds a reaction from the six emoji people use most.",
2669
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// The six emoji people use most, each named in words. ODS has no full emoji picker yet.\nconst quickEmoji = [\n { emoji: '👍', name: 'Thumbs up' },\n { emoji: '❤️', name: 'Heart' },\n { emoji: '😂', name: 'Tears of joy' },\n { emoji: '🎉', name: 'Party popper' },\n { emoji: '👀', name: 'Eyes' },\n { emoji: '🚀', name: 'Rocket' },\n];\nconst emojiName = (emoji: string) => quickEmoji.find((q) => q.emoji === emoji)?.name ?? emoji;\n\ntype Reaction = { emoji: string; by: string[] };\ntype Row = { id: string; from: string; at: Date; text: string; reactions: Reaction[] };\n\nconst firstThread: Row[] = [\n {\n id: 'm1',\n from: 'Ben Carter',\n at: new Date('2025-01-15T11:40:00Z'),\n text: 'The pricing page is live.',\n reactions: [{ emoji: '👍', by: ['Omar Reyes', me] }],\n },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Nice work. I will share it with the sales team.', reactions: [] },\n];\n\nconst firstName = (name: string) => name.split(' ')[0];\n\n// 'Omar and you': other people by first name, the person last.\nfunction whoReacted(by: string[]) {\n const names = [...by.filter((n) => n !== me).map(firstName), ...(by.includes(me) ? ['you'] : [])];\n if (names.length === 1) return names[0] === 'you' ? 'You' : names[0];\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\n// 'Thumbs up, 3 reactions'. The chip's aria-pressed says whether the person reacted.\nfunction chipName(r: Reaction) {\n const count = `${r.by.length} ${r.by.length === 1 ? 'reaction' : 'reactions'}`;\n return `${emojiName(r.emoji)}, ${count}`;\n}\n\nexport default function MessageReactionsQuickPick() {\n const [thread, setThread] = useState(firstThread);\n // Each row's 'Add reaction' button by row id. When the chip that had focus goes away, focus goes there.\n const addButtons = useRef<Record<string, HTMLButtonElement | HTMLAnchorElement | null>>({});\n const focusAdd = useRef<string | null>(null);\n\n useEffect(() => {\n if (!focusAdd.current) return;\n addButtons.current[focusAdd.current]?.focus();\n focusAdd.current = null;\n });\n // The row whose quick pick is open, and the button it opens from. Both stay set while it fades out.\n const [pickRow, setPickRow] = useState<Row | null>(null);\n const [pickAnchor, setPickAnchor] = useState<HTMLElement | null>(null);\n const [pickOpen, setPickOpen] = useState(false);\n\n // The count changes at once. A real app sends the change to the server and puts it back if that fails.\n function toggle(rowId: string, emoji: string) {\n const row = thread.find((m) => m.id === rowId);\n const chip = row?.reactions.find((r) => r.emoji === emoji);\n // The person's reaction was the last one, so the chip goes away.\n if (chip && chip.by.length === 1 && chip.by[0] === me) focusAdd.current = rowId;\n setThread((rows) =>\n rows.map((m) => {\n if (m.id !== rowId) return m;\n const has = m.reactions.find((r) => r.emoji === emoji);\n const reactions = has\n ? m.reactions.map((r) =>\n r.emoji !== emoji ? r : { ...r, by: r.by.includes(me) ? r.by.filter((n) => n !== me) : [...r.by, me] },\n )\n : [...m.reactions, { emoji, by: [me] }];\n // A chip with no reactions left goes away.\n return { ...m, reactions: reactions.filter((r) => r.by.length > 0) };\n }),\n );\n }\n\n function openPick(m: Row, anchor: HTMLElement) {\n if (pickOpen && pickRow?.id === m.id) {\n setPickOpen(false);\n return;\n }\n setPickRow(m);\n setPickAnchor(anchor);\n setPickOpen(true);\n }\n\n // Escape, a click outside and a pick close it. Popover's returnFocus gives focus back to 'Add reaction'.\n function closePick() {\n setPickOpen(false);\n }\n\n function pick(emoji: string) {\n if (!pickRow) return;\n closePick();\n toggle(pickRow.id, emoji);\n }\n\n // The open row, read from the thread so the quick pick shows its reactions as they are now.\n const openRow = thread.find((m) => m.id === pickRow?.id);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Cluster gap=\"small\">\n {m.reactions.map((r) => (\n <Tooltip key={r.emoji} title={whoReacted(r.by)}>\n <Tag\n variant=\"contained\"\n size=\"small\"\n state={r.by.includes(me) ? 'selected' : 'enabled'}\n label={`${r.emoji} ${r.by.length}`}\n aria-label={chipName(r)}\n onClick={() => toggle(m.id, r.emoji)}\n />\n </Tooltip>\n ))}\n <Tooltip title=\"Add reaction\">\n <IconButton\n color=\"iconOnly\"\n state={pickOpen && pickRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n ref={(el) => { addButtons.current[m.id] = el; }}\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={pickOpen && pickRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openPick(m, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={pickOpen} anchorEl={pickAnchor} onClose={closePick} returnFocus>\n <Menu navigable aria-label=\"Add reaction\" width={200}>\n {quickEmoji.map((q) => (\n <MenuItem\n key={q.emoji}\n size=\"small\"\n icon={q.emoji}\n label={q.name}\n // Picking an emoji the person already used removes it.\n tag={openRow?.reactions.some((r) => r.emoji === q.emoji && r.by.includes(me)) ? { label: 'Added', variant: 'textOnly' } : undefined}\n onClick={() => pick(q.emoji)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
2670
+ "uses": [
2671
+ "Center",
2672
+ "Cluster",
2673
+ "Heading",
2674
+ "IconButton",
2675
+ "Menu",
2676
+ "MenuItem",
2677
+ "Message",
2678
+ "Paragraph",
2679
+ "Popover",
2680
+ "Stack",
2681
+ "Tag",
2682
+ "TimeStamp",
2683
+ "Tooltip",
2684
+ "UserImage"
2685
+ ]
2686
+ }
2687
+ ]
2688
+ },
2689
+ {
2690
+ "id": "message-row",
2691
+ "title": "Message row",
2692
+ "kind": "design",
2693
+ "level": "organism",
2694
+ "area": "chat",
2695
+ "situation": "A thread shows messages from people, and sometimes from an agent.",
2696
+ "do": [
2697
+ "Show each row with `Message`: the sender's `UserImage`, their name and the time. A person's avatar is their picture or their initial.",
2698
+ "Pass `decorative` to the avatar, since the name beside it is already read.",
2699
+ "Mark an agent's row as the rule 'An agent says what it is' says: an icon avatar, its name, an 'Agent' `Tag` and the model line beside the time.",
2700
+ "Give an agent's avatar `UserImage` with `icon`: the product's own agent shows the product's mark, and an agent from outside shows a plain `Bot` icon.",
2701
+ "Write the model line in small secondary text, such as `<Paragraph size=\"caption\" tone=\"secondary\">`, when the product knows the model.",
2702
+ "Show the time with `<TimeStamp dateFormat=\"absolute\" data=\"time\">`. The date line says the day.",
2703
+ "Make a row `compact` when the row above is from the same sender, less than 5 minutes older and on the same day.",
2704
+ "Put a date line between days, a `Line` with a `label` that reads 'Today', 'Yesterday', or the full date with the year: 'Monday, January 13, 2025'.",
2705
+ "Pass an `aria-label` that names the sender on every row, compact ones too: 'Dana Lee', or 'Acme Agent, agent'. The time is in the row.",
2706
+ "Give the list that holds the rows `role=\"log\"`, so a screen reader reads new messages as they arrive.",
2707
+ "Write an agent's text as plain sentences in `Paragraph`."
2708
+ ],
2709
+ "dont": [
2710
+ "Do not show a photo or an initial for an agent.",
2711
+ "Do not group rows from two senders, or rows from two days. The first row after a date line shows its header.",
2712
+ "Do not leave the `aria-label` off a compact row. It shows no name.",
2713
+ "Do not put the agent's model in its name. It goes on the model line."
2714
+ ],
2715
+ "native": "On Apple a row shows the avatar, the name and the time, with an 'Agent' label next to an agent's name.",
2716
+ "options": [
2717
+ {
2718
+ "id": "person-and-agent",
2719
+ "title": "People and an agent",
2720
+ "useWhen": "A thread with gaps between messages: every row shows who and when.",
2721
+ "source": "'use client';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string };\n\nconst thread: Row[] = [\n { id: 'm1', from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Ben Carter', at: new Date('2025-01-15T11:44:00Z'), text: 'I can take the press kit.' },\n];\n\nexport default function MessageRowPersonAndAgent() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) =>\n m.agent ? (\n // An agent's row: an icon avatar, its name, an 'Agent' tag, the time and the model line.\n // The product's own agent shows the product's mark; an agent from outside shows a plain bot icon.\n // Acme has no mark here, so Acme Agent uses Bot.\n <Message\n key={m.id}\n aria-label={`${m.from}, agent`}\n avatar={<UserImage userHandle={m.from} icon={Bot} decorative />}\n name={m.from}\n meta={\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ) : (\n // A person's row: their picture or initial, their name and the time.\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ),\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
2722
+ "uses": [
2723
+ "Center",
2724
+ "Heading",
2725
+ "Message",
2726
+ "Paragraph",
2727
+ "Stack",
2728
+ "Tag",
2729
+ "TimeStamp",
2730
+ "UserImage"
2731
+ ]
2732
+ },
2733
+ {
2734
+ "id": "grouped",
2735
+ "title": "Grouped rows",
2736
+ "useWhen": "A busy thread: follow-on rows from one sender drop the avatar and the name.",
2737
+ "source": "'use client';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\n// A real app builds each date line from the message times, in the reader's time zone, and labels the\n// days 'Today', 'Yesterday', or the full date with the year. These lines are fixed, so the times sit\n// near midday UTC, where the date is the same in most time zones.\nconst days: { label: string; rows: Row[] }[] = [\n {\n label: 'Monday, January 13, 2025',\n rows: [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-13T12:10:00Z'), text: 'I sent the pricing page draft to legal.' },\n { id: 'm2', from: 'Ben Carter', at: new Date('2025-01-13T12:12:00Z'), text: 'They usually answer within a day.' },\n ],\n },\n {\n label: 'Today',\n rows: [\n { id: 'm3', from: 'Ben Carter', at: new Date('2025-01-15T11:30:00Z'), text: 'Legal approved the pricing page.' },\n { id: 'm4', from: 'Ben Carter', at: new Date('2025-01-15T11:31:00Z'), text: 'They asked for two small wording changes, both in the footer.' },\n { id: 'm5', from: 'Ben Carter', at: new Date('2025-01-15T11:33:00Z'), text: 'I made them already.' },\n { id: 'm6', from: 'Dana Lee', at: new Date('2025-01-15T11:45:00Z'), text: 'Thanks. I will publish it this afternoon.' },\n ],\n },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageRowGrouped() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"medium\">\n {days.map((day) => (\n <Stack key={day.label} gap=\"small\">\n <Line label={day.label} />\n {day.rows.map((m, i) => (\n <Message\n key={m.id}\n // A compact row shows no name, so its aria-label carries it.\n aria-label={m.from}\n compact={followsOn(day.rows, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
2738
+ "uses": [
2739
+ "Center",
2740
+ "Heading",
2741
+ "Line",
2742
+ "Message",
2743
+ "Paragraph",
2744
+ "Stack",
2745
+ "TimeStamp",
2746
+ "UserImage"
2747
+ ]
2748
+ }
2749
+ ]
2750
+ },
2751
+ {
2752
+ "id": "not-found-page",
2753
+ "title": "Page not found",
2754
+ "kind": "design",
2755
+ "level": "page",
2756
+ "area": "state",
2757
+ "situation": "A person opens a link to a page that does not exist.",
2758
+ "do": [
2759
+ "Say 'Page not found' in a `Heading` with `level={1}`.",
2760
+ "Add one line on what may have happened: 'The link may be wrong, or the page was moved or removed.'",
2761
+ "Offer one Button home: 'Go Home'."
2762
+ ],
2763
+ "dont": [
2764
+ "Do not make '404' the heading.",
2765
+ "Do not show a line of text with no way home.",
2766
+ "Do not blame the person for the link."
2767
+ ],
2768
+ "options": [
2769
+ {
2770
+ "id": "full-page",
2771
+ "title": "Full page",
2772
+ "useWhen": "The address is outside the app shell, so nothing else can show.",
2773
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function NotFoundPageFullPage() {\n return (\n <Center fill>\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Center>\n );\n}\n",
2774
+ "uses": [
2775
+ "Button",
2776
+ "Center",
2777
+ "Cluster",
2778
+ "Heading",
2779
+ "Paragraph",
2780
+ "Stack"
2781
+ ]
2782
+ },
2783
+ {
2784
+ "id": "in-shell",
2785
+ "title": "Inside the shell",
2786
+ "useWhen": "The address is inside the app and the navigation still works.",
2787
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function NotFoundPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
2788
+ "uses": [
2789
+ "Button",
2790
+ "Cluster",
2791
+ "Heading",
2792
+ "Image",
2793
+ "Paragraph",
2794
+ "Stack",
2795
+ "Surface",
2796
+ "Tab",
2797
+ "TabsContainer"
2798
+ ]
2799
+ }
2800
+ ]
2801
+ },
2802
+ {
2803
+ "id": "notification-menu",
2804
+ "title": "Notification setting",
2805
+ "kind": "design",
2806
+ "level": "organism",
2807
+ "area": "menu",
2808
+ "situation": "A person chooses how much a channel or a thread notifies them.",
2809
+ "do": [
2810
+ "Use an `IconButton` with `iconName=\"Bell\"`, and `BellOff` when the channel is muted.",
2811
+ "Say the current value in the button's `ariaLabel`: 'Notifications: All messages'. Show it in a `Tooltip` too.",
2812
+ "Open a navigable menu of three choices: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Notifications\">`.",
2813
+ "Give each choice a `secondLabel` of one line: 'All Messages', then 'Every message in this channel.'",
2814
+ "Give each item `role=\"menuitemradio\"` and mark the current choice with `isSelected`, which sets `aria-checked`.",
2815
+ "Save as soon as a choice is made, as the rule 'A setting saves in place, or with one Save Button' says. Close the menu and show nothing when it works.",
2816
+ "Set `aria-busy` on the bell while the request runs.",
2817
+ "Put the bell back to its old value when the save fails, and show an error toast: 'Could not save your notification setting. Try again.' This is the exception in the rule 'A setting saves in place, or with one Save Button': a setting chosen from a menu shows a failed save in a toast, because the menu closes.",
2818
+ "Dismiss the toast when the example goes away."
2819
+ ],
2820
+ "dont": [
2821
+ "Do not add a Save Button to the menu.",
2822
+ "Do not show a toast when the save works.",
2823
+ "Do not leave the bell on the new value when the save failed.",
2824
+ "Do not show a failure inside the menu. It has already closed.",
2825
+ "Do not use only the icon to say muted. The button's name says it too."
2826
+ ],
2827
+ "native": "On Apple use a toolbar `Menu` with a `Picker` inside it, with the bell symbol changing to `bell.slash`. On Android use a dropdown menu with radio items.",
2828
+ "options": [
2829
+ {
2830
+ "id": "menu",
2831
+ "title": "Bell with a menu",
2832
+ "useWhen": "There are three or four choices and each one needs a line to explain it.",
2833
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Pref = 'all' | 'mentions' | 'none';\n\nconst choices: { value: Pref; label: string; line: string; current: string }[] = [\n { value: 'all', label: 'All Messages', line: 'Every message in this channel.', current: 'All messages' },\n { value: 'mentions', label: 'Mentions Only', line: 'Only when someone mentions you.', current: 'Mentions only' },\n { value: 'none', label: 'Muted', line: 'No notifications from this channel.', current: 'Muted' },\n];\n\nexport default function NotificationMenuExample() {\n const [pref, setPref] = useState<Pref>('all');\n const [saving, setSaving] = useState(false);\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const current = choices.find((c) => c.value === pref) ?? choices[0];\n\n // On unmount it stops the request and closes the toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n function toggle(anchorEl: HTMLElement) {\n if (saving) return;\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Saves at once and shows nothing when it works: the bell already shows the new value.\n // The menu is gone by now, so a failure says so in a toast, and the bell goes back.\n function choose(next: Pref) {\n const previous = pref;\n setOpen(false);\n if (next === previous) return;\n setPref(next);\n setSaving(true);\n // Stands in for the request to the server. 'Muted' never saves, as if the connection were down.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (next === 'none') {\n setPref(previous);\n toastIds.current.push(toast({ type: 'error', message: 'Could not save your notification setting. Try again.' }));\n }\n }, 900);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Design team</Heading>\n <Tooltip title={current.current}>\n <IconButton\n color={pref === 'none' ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName={pref === 'none' ? 'BellOff' : 'Bell'}\n ariaLabel={`Notifications: ${current.current}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n aria-busy={saving}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Ben Carter: The press kit is in the shared folder.</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Notifications\" width={260}>\n {choices.map((c) => (\n <MenuItem\n key={c.value}\n size=\"small\"\n label={c.label}\n secondLabel={c.line}\n isSelected={c.value === pref}\n role=\"menuitemradio\"\n onClick={() => choose(c.value)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
2834
+ "uses": [
2835
+ "Center",
2836
+ "Cluster",
2837
+ "Heading",
2838
+ "IconButton",
2839
+ "Menu",
2840
+ "MenuItem",
2841
+ "Paragraph",
2842
+ "Popover",
2843
+ "Stack",
2844
+ "Toaster",
2845
+ "Tooltip",
2846
+ "dismissToast",
2847
+ "toast"
2848
+ ]
2849
+ }
2850
+ ]
2851
+ },
2852
+ {
2853
+ "id": "oauth-consent",
2854
+ "title": "OAuth consent",
2855
+ "kind": "design",
2856
+ "level": "page",
2857
+ "area": "auth",
2858
+ "situation": "Another app, such as a CLI or an MCP client, asks to act for a person who is logged in, and the person must allow it.",
2859
+ "do": [
2860
+ "Name the app in a `Heading` with `level={1}`: 'Acme CLI wants to connect to Acme'.",
2861
+ "Say in one or two plain sentences what the app will be able to do, in the person's words: 'read your projects and tasks, and create tasks as you'.",
2862
+ "Say how to remove the access later: 'You can remove its access at any time in Settings, under Connected apps.'",
2863
+ "Show the account that gives the access, with a text-only 'Not You? Switch Account' Button under it.",
2864
+ "Take the app's name and the place the person goes back to from the server's record of the registered app, never from the link.",
2865
+ "Say where the person goes next: 'You will go back to cli.acme.dev.'",
2866
+ "Put 'Cancel' first and 'Allow' second, side by side and the same width, in a `Grid` with `columns={2}`.",
2867
+ "Show `loading` on 'Allow' and disable 'Cancel' and every field while the request runs.",
2868
+ "Show `LoadingScreen` with `label=\"Going back to Acme CLI…\"` while the browser goes back, after 'Allow' and after 'Cancel'.",
2869
+ "Send 'Cancel' back to the app with `error=access_denied`, and return the `state` value the app sent on both paths.",
2870
+ "Leave wider access off until the person turns it on, and say under it what it adds."
2871
+ ],
2872
+ "dont": [
2873
+ "Do not color 'Allow' or 'Cancel' as danger. Allowing is the person's choice, not a destructive action.",
2874
+ "Do not turn on wider access for the person.",
2875
+ "Do not name the access by its scope id, such as 'tasks:write'.",
2876
+ "Do not label Cancel 'Deny' or 'No'."
2877
+ ],
2878
+ "options": [
2879
+ {
2880
+ "id": "simple",
2881
+ "title": "One account, one access",
2882
+ "useWhen": "The app gets one set of access to one account, so the only choice is to allow it or not.",
2883
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function OAuthConsentSimple() {\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read your projects and tasks, and create tasks as you. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
2884
+ "uses": [
2885
+ "Alert",
2886
+ "Button",
2887
+ "Center",
2888
+ "Cluster",
2889
+ "Grid",
2890
+ "Heading",
2891
+ "Image",
2892
+ "LoadingScreen",
2893
+ "Paragraph",
2894
+ "Stack",
2895
+ "UserImage"
2896
+ ]
2897
+ },
2898
+ {
2899
+ "id": "with-scope",
2900
+ "title": "Workspace and wider access",
2901
+ "useWhen": "The person picks the workspace the app can use, or turns on wider access.",
2902
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Select from 'oneslash-design-system/components/select';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The workspaces the person belongs to.\nconst workspaces = [\n { value: 'design', label: 'Acme Design' },\n { value: 'marketing', label: 'Acme Marketing' },\n];\n\nexport default function OAuthConsentWithScope() {\n const [workspace, setWorkspace] = useState('design');\n // The wider access is off until the person turns it on.\n const [allWorkspaces, setAllWorkspaces] = useState(false);\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read the projects and tasks you can see, and create tasks as you, in the workspaces you allow below. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"small\">\n {/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Workspace</Paragraph>\n <Select aria-label=\"Workspace\" value={workspace} options={workspaces} disabled={allowing} onChange={(v) => setWorkspace(typeof v === 'string' ? v : v[0])} />\n </Stack>\n <Checkbox label=\"Also allow my other workspaces\" secondLabel=\"It can then do the same in every workspace you belong to. It still sees only what you can see.\" checked={allWorkspaces} disabled={allowing} onChange={setAllWorkspaces} />\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
2903
+ "uses": [
2904
+ "Alert",
2905
+ "Button",
2906
+ "Center",
2907
+ "Checkbox",
2908
+ "Cluster",
2909
+ "Grid",
2910
+ "Heading",
2911
+ "Image",
2912
+ "LoadingScreen",
2913
+ "Paragraph",
2914
+ "Select",
2915
+ "Stack",
2916
+ "UserImage"
2917
+ ]
2918
+ }
2919
+ ]
2920
+ },
2921
+ {
2922
+ "id": "on-off-settings",
2923
+ "title": "On and off settings",
2924
+ "kind": "design",
2925
+ "level": "organism",
2926
+ "area": "settings",
2927
+ "situation": "A person turns things on and off, such as which notifications they get.",
2928
+ "do": [
2929
+ "Follow the rule 'A setting saves in place, or with one Save Button'. Every `Switch` saves as soon as it changes, and the page has no Save Button.",
2930
+ "Give each `Switch` a visible `label` and a `description` that says what happens when it is on.",
2931
+ "Group the switches in `SettingsSection`s with a title and one line under it.",
2932
+ "Set `busy` on the switch while its request runs. It keeps its position and ignores presses. Show nothing when the save works.",
2933
+ "Put the switch back to its old value when the save fails, and set `error` to a short line: 'Could not save. Try again.'",
2934
+ "Clear the `error` when the person presses the switch again.",
2935
+ "Use a `Checkbox` for an on/off choice only inside a form that has a Save Button, such as a consent line above a Submit Button.",
2936
+ "Give each switch a unique `id`."
2937
+ ],
2938
+ "dont": [
2939
+ "Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`.",
2940
+ "Do not add a Save Button to a list of switches.",
2941
+ "Do not show a toast when a switch saves.",
2942
+ "Do not leave a switch in its new position when the save failed.",
2943
+ "Do not put 'On' or 'Off' in the label. The switch shows it."
2944
+ ],
2945
+ "native": "On Apple use a `Toggle` in a grouped `Form`, and on Android a `Switch`. Both save as they change.",
2946
+ "options": [
2947
+ {
2948
+ "id": "list",
2949
+ "title": "A list of switches",
2950
+ "useWhen": "Each setting is on or off and stands alone. Every switch saves as soon as it changes.",
2951
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Switch from 'oneslash-design-system/components/switch';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Setting = { id: string; label: string; description: string; on: boolean; fails?: boolean };\n\nconst failedMessage = 'Could not save. Try again.';\n\nconst emailSettings: Setting[] = [\n { id: 'mentions', label: 'Mentions', description: 'An email when someone mentions you.', on: true },\n { id: 'replies', label: 'Replies', description: 'An email when someone replies to your message.', on: true },\n { id: 'digest', label: 'Weekly digest', description: 'A summary of last week, every Monday.', on: false },\n];\n\n// Stands in for a connection that is down: this one never saves.\nconst appSettings: Setting[] = [\n { id: 'slack', label: 'Slack digest', description: 'Post the weekly digest in #general.', on: false, fails: true },\n { id: 'push', label: 'Push on your phone', description: 'Mentions and replies, while the app is closed.', on: true },\n];\n\nconst everySetting = [...emailSettings, ...appSettings];\n\nexport default function OnOffSettingsList() {\n const [values, setValues] = useState<Record<string, boolean>>(() => Object.fromEntries(everySetting.map((s) => [s.id, s.on])));\n const [busy, setBusy] = useState<Record<string, boolean>>({});\n // Opens on a failed save, as if the person just turned Slack digest on.\n const [errors, setErrors] = useState<Record<string, string>>({ slack: failedMessage });\n const timers = useRef<Record<string, ReturnType<typeof setTimeout>>>({});\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => Object.values(timers.current).forEach(clearTimeout), []);\n\n // Saves as soon as it changes. Nothing shows when it works. When it fails, the switch goes back and says why.\n function handleChange(setting: Setting, next: boolean) {\n setErrors((current) => ({ ...current, [setting.id]: '' }));\n setBusy((current) => ({ ...current, [setting.id]: true }));\n setValues((current) => ({ ...current, [setting.id]: next }));\n // Stands in for the request to the server.\n timers.current[setting.id] = setTimeout(() => {\n setBusy((current) => ({ ...current, [setting.id]: false }));\n if (setting.fails) {\n setValues((current) => ({ ...current, [setting.id]: !next }));\n setErrors((current) => ({ ...current, [setting.id]: failedMessage }));\n }\n }, 900);\n }\n\n function renderSwitch(setting: Setting) {\n return (\n <Switch\n key={setting.id}\n id={`on-off-settings-${setting.id}`}\n label={setting.label}\n description={setting.description}\n checked={values[setting.id]}\n busy={Boolean(busy[setting.id])}\n error={errors[setting.id] || undefined}\n onChange={(next) => handleChange(setting, next)}\n />\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Notifications</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Each switch saves as soon as you change it.</Paragraph>\n </Stack>\n <SettingsSection title=\"Email\" description=\"Sent to dana@acme.example.\">\n {emailSettings.map(renderSwitch)}\n </SettingsSection>\n <SettingsSection title=\"Apps\" description=\"Where else Acme tells you.\">\n {appSettings.map(renderSwitch)}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
2952
+ "uses": [
2953
+ "Center",
2954
+ "Heading",
2955
+ "Paragraph",
2956
+ "SettingsSection",
2957
+ "Stack",
2958
+ "Switch"
2959
+ ]
2960
+ }
2961
+ ]
2962
+ },
2963
+ {
2964
+ "id": "overflow-menu",
2965
+ "title": "More menu",
2966
+ "kind": "design",
2967
+ "level": "organism",
2968
+ "area": "menu",
2969
+ "situation": "A person opens a menu of less common actions, behind one button, for a thing or for the page.",
2970
+ "do": [
2971
+ "Use an `IconButton` with `iconName=\"Ellipsis\"` and a `Tooltip` of 'More'.",
2972
+ "Name the thing in the button's `ariaLabel`, in sentence case: 'More actions for Q3 report'. In a list, each row names its own item.",
2973
+ "Open `<Popover returnFocus>` around `<Menu navigable aria-label=\"Actions for Q3 report\">` with `onClick` items, from the button the person pressed: pass `event.currentTarget` as `anchorEl`.",
2974
+ "Set `aria-haspopup=\"menu\"` and `aria-expanded` on the button, and `state=\"selected\"` while the menu is open.",
2975
+ "Order the items by how often they are used. Put a destructive item last, after a `Line`, as a `MenuItem` with `color=\"danger\"`.",
2976
+ "Show a toast when an item has no other sign, such as 'Link copied.', since the menu is gone.",
2977
+ "Show no toast for Duplicate on a row: the copy shows under it. Move focus to the copy's More button.",
2978
+ "Confirm a delete on a row in the row, as the case 'Delete confirm' says: 'Cancel' and a danger 'Delete' take the place of the button, and focus goes to 'Cancel'.",
2979
+ "Move focus after a row is deleted to the next row's More button, or the one before it when it was the last.",
2980
+ "Confirm a delete from a header in a small Modal: 'Delete Report', 'Cancel' first, then a danger 'Delete'. 'Cancel' puts focus back on the More button.",
2981
+ "Go back to the list the thing was in after a delete from a header, and show a toast that names it.",
2982
+ "Show an error toast when Copy Link fails, because the clipboard is missing or refuses: 'Copying is blocked here. Select the link and copy it:' and the link. It stays until the person closes it.",
2983
+ "Check that the example is still mounted before the clipboard promise starts a toast, for success and failure."
2984
+ ],
2985
+ "dont": [
2986
+ "Do not name the button only 'More'. Say what it acts on.",
2987
+ "Do not put a frequent action only in the menu. A person needs it in one press.",
2988
+ "Do not put a destructive item first, or color it by hand. It is last, with `color=\"danger\"`.",
2989
+ "Do not delete on the first click.",
2990
+ "Do not open a Modal to confirm a delete on a row in a dense list. The row keeps the place."
2991
+ ],
2992
+ "native": "On Apple use a toolbar `Menu` with an `ellipsis.circle` label, or a row's `contextMenu`, with Delete last in the `.destructive` role. Delete asks in a `confirmationDialog`. On Android use an `IconButton` with a `DropdownMenu`.",
2993
+ "options": [
2994
+ {
2995
+ "id": "on-a-row",
2996
+ "title": "More button on a row",
2997
+ "useWhen": "The actions are for one item in a list, and each row has its own button.",
2998
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; name: string; updated: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the server.\nconst firstReports: Report[] = [\n { id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },\n { id: 'budget', name: 'Budget review', updated: 'Updated last week' },\n { id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },\n { id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },\n];\n\nexport default function OverflowMenuOnARow() {\n const [reports, setReports] = useState(firstReports);\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Report | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The row that asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const cancelDelete = useRef<Focusable>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n // Gives each copy its own id, so no two rows share a key.\n const copies = useRef(0);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function openMenu(r: Report, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === r.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(r);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function choose(action: (r: Report) => void) {\n if (!menuRow) return;\n const r = menuRow;\n setMenuOpen(false);\n action(r);\n }\n\n // The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.\n function duplicate(r: Report) {\n copies.current += 1;\n const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };\n setReports((list) => {\n const at = list.findIndex((x) => x.id === r.id);\n return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];\n });\n focusNext.current = () => moreButtons.current[copy.id]?.focus();\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,\n // in an error toast that stays until the person closes it.\n function copyLink(r: Report) {\n const link = `https://example.com/reports/${r.id}`;\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToDelete(r: Report) {\n setConfirmingId(r.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepReport() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const at = reports.findIndex((r) => r.id === id);\n const gone = reports[at];\n const neighbor = reports[at + 1] ?? reports[at - 1];\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setReports((list) => list.filter((r) => r.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));\n // The row is gone: focus goes to the next row's More button, or the one before it when it was the last.\n focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n {reports.length > 0 ? (\n <TableContainer>\n {reports.map((r) => {\n const confirming = r.id === confirmingId;\n return (\n <TableRow key={r.id}>\n <TableCell>\n <Stack gap=\"small\">\n {r.name}\n {confirming && <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">Delete this report?</Paragraph>}\n </Stack>\n </TableCell>\n <TableCell width=\"160px\">{r.updated}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\" align=\"right\">\n {confirming ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n ) : (\n <Cluster justify=\"end\">\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[r.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${r.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === r.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" text=\"No reports yet\" secondText=\"Reports you create appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose(duplicate)} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={() => choose(copyLink)} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
2999
+ "uses": [
3000
+ "Button",
3001
+ "Center",
3002
+ "Cluster",
3003
+ "EmptyBox",
3004
+ "Heading",
3005
+ "IconButton",
3006
+ "Line",
3007
+ "Menu",
3008
+ "MenuItem",
3009
+ "Paragraph",
3010
+ "Popover",
3011
+ "Stack",
3012
+ "TableCell",
3013
+ "TableContainer",
3014
+ "TableRow",
3015
+ "Toaster",
3016
+ "Tooltip",
3017
+ "dismissToast",
3018
+ "toast"
3019
+ ]
3020
+ },
3021
+ {
3022
+ "id": "in-a-header",
3023
+ "title": "More button in a header",
3024
+ "useWhen": "The actions are for the whole page, and the header has one button.",
3025
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];\n\nexport default function OverflowMenuInAHeader() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function duplicate() {\n setOpen(false);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.\n function copyLink() {\n setOpen(false);\n const link = 'https://example.com/reports/q3';\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n function askToDelete() {\n setOpen(false);\n setConfirming(true);\n }\n\n // The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.\n function keepReport() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n function confirmDelete() {\n if (deleting) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n // A real app goes back to the list of reports here.\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Surface padding=\"large\">\n <List items={otherReports} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Q3 report</Heading>\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Q3 report\"\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n )}\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Q3 report\" width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={duplicate} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={copyLink} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n {/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Report\"\n onClose={keepReport}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes &apos;Q3 report&apos; and its 12 tasks.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3026
+ "uses": [
3027
+ "Button",
3028
+ "Center",
3029
+ "Cluster",
3030
+ "Heading",
3031
+ "IconButton",
3032
+ "Line",
3033
+ "List",
3034
+ "Menu",
3035
+ "MenuItem",
3036
+ "Modal",
3037
+ "Paragraph",
3038
+ "Popover",
3039
+ "Stack",
3040
+ "Surface",
3041
+ "Toaster",
3042
+ "Tooltip",
3043
+ "dismissToast",
3044
+ "toast"
3045
+ ]
3046
+ }
3047
+ ]
3048
+ },
3049
+ {
3050
+ "id": "profile-form",
3051
+ "title": "Profile",
3052
+ "kind": "design",
3053
+ "level": "organism",
3054
+ "area": "settings",
3055
+ "situation": "A person changes how they appear and how they sign in: their picture, their name and their password.",
3056
+ "do": [
3057
+ "Follow the rule 'A setting saves in place, or with one Save Button'.",
3058
+ "Put the picture, the name and the password in their own `SettingsSection`s. Do not mix a control that saves on change and a Save Button in one section.",
3059
+ "Save the picture as soon as the person chooses it, with 'Change Picture' and 'Remove'. Show `loading` on the Button that was pressed while it saves, and nothing when it works.",
3060
+ "When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'",
3061
+ "Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.",
3062
+ "Give the name one Save Button inside a `Form`. It is `state=\"disabled\"` while the name has not changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.",
3063
+ "Give the password one 'Update Password' Button. Ask for the current password and the new one. It is disabled while either field is empty, and reads 'Saved' for 2 seconds. Then clear both fields.",
3064
+ "Show a wrong current password under that field, and keep what the person typed in both.",
3065
+ "Use `<TextField type=\"password\">` for both, with `autoComplete=\"current-password\"` and `autoComplete=\"new-password\"`.",
3066
+ "Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. This ties its label, help and error to it.",
3067
+ "Show a problem with a field under it, as the rule 'A form error shows next to the problem' says: 'Enter your name.' and 'Use at least 8 characters.'",
3068
+ "Disable the field while its request runs, and keep what the person typed when the save fails.",
3069
+ "Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial."
3070
+ ],
3071
+ "dont": [
3072
+ "Do not add one Save Button for the whole page. Each group saves by itself.",
3073
+ "Do not label the Button 'Saving…' while it runs. It keeps its label.",
3074
+ "Do not show a toast when the name or the password is saved. The Button says it.",
3075
+ "Do not keep the passwords in the fields after they are saved.",
3076
+ "Do not ask for the new password twice. Show one field and the length rule."
3077
+ ],
3078
+ "native": "On Apple use a grouped `Form` with the name in a `TextField` and a `SecureField` for the password, and a `PhotosPicker` for the picture. The picture saves when it is chosen.",
3079
+ "options": [
3080
+ {
3081
+ "id": "form",
3082
+ "title": "Picture, name and password",
3083
+ "useWhen": "People sign in with a password and can change their own picture and name.",
3084
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Alert from 'oneslash-design-system/components/alert';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A picture the person chose. A real app uploads the file and gets a URL back.\nconst chosenPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E\";\n\nconst minPasswordLength = 8;\n// Stands in for the server's check. In this example every current password is right except this one.\nconst wrongCurrentPassword = 'incorrect';\n\nexport default function ProfileForm() {\n const [picture, setPicture] = useState<string | undefined>(undefined);\n // Which picture Button was pressed, so only that one shows `loading`.\n const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);\n const [pictureError, setPictureError] = useState('');\n\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [savingName, setSavingName] = useState(false);\n const [nameSaved, setNameSaved] = useState(false);\n\n const [currentPassword, setCurrentPassword] = useState('');\n const [currentPasswordError, setCurrentPasswordError] = useState('');\n const [password, setPassword] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [savingPassword, setSavingPassword] = useState(false);\n const [passwordSaved, setPasswordSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n // The first picture save fails, as if the upload dropped, so the example shows both paths.\n const pictureFails = useRef(true);\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(nameSavedTimer.current);\n clearTimeout(passwordSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.\n // When it fails, the old picture stays and a line under the Buttons says why.\n function savePicture(next: string | undefined, pressed: 'change' | 'remove') {\n if (savingPicture) return;\n setPictureError('');\n setSavingPicture(pressed);\n later(() => {\n setSavingPicture(null);\n if (pictureFails.current) {\n pictureFails.current = false;\n setPictureError('Could not save. Try again.');\n return;\n }\n setPicture(next);\n }, 900);\n }\n\n // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveName() {\n if (savingName) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSavingName(true);\n later(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSavingName(false);\n setNameSaved(true);\n clearTimeout(nameSavedTimer.current);\n nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);\n }, 1200);\n }\n\n function handleUpdatePassword() {\n if (savingPassword || !currentPassword || !password) return;\n setCurrentPasswordError('');\n if (password.length < minPasswordLength) {\n setPasswordError(`Use at least ${minPasswordLength} characters.`);\n return;\n }\n setPasswordError('');\n setSavingPassword(true);\n later(() => {\n setSavingPassword(false);\n // A wrong current password shows under that field, and both fields keep what the person typed.\n if (currentPassword === wrongCurrentPassword) {\n setCurrentPasswordError('This is not your current password. Enter it again.');\n return;\n }\n setCurrentPassword('');\n setPassword('');\n setPasswordSaved(true);\n clearTimeout(passwordSavedTimer.current);\n passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);\n }, 1200);\n }\n\n const nameChanged = name !== savedName;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Profile</Heading>\n\n <SettingsSection title=\"Picture\" description=\"Shown beside your name in Acme.\">\n <Cluster gap=\"large\">\n <UserImage userHandle={savedName} userImgUrl={picture} size={64} />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label=\"Change Picture\" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />\n {picture && <Button size=\"small\" type=\"tertiary\" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label=\"Remove\" aria-label=\"Remove picture\" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}\n </Cluster>\n {pictureError && <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={pictureError} />}\n </Stack>\n </Cluster>\n </SettingsSection>\n\n <SettingsSection title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSaveName}>\n <FormField id=\"profile-form-name\" label=\"Name\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={savingName}\n autoComplete=\"name\"\n onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={savingName} />\n </Cluster>\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Password\" description=\"Sign in with dana@acme.example and a password.\">\n <Form aria-label=\"Password\" gap=\"medium\" onSubmit={handleUpdatePassword}>\n <FormField id=\"profile-form-current-password\" label=\"Current password\" error={currentPasswordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={currentPassword}\n disabled={savingPassword}\n autoComplete=\"current-password\"\n onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <FormField id=\"profile-form-password\" label=\"New password\" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={password}\n disabled={savingPassword}\n autoComplete=\"new-password\"\n onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType=\"submit\" loading={savingPassword} />\n </Cluster>\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
3085
+ "uses": [
3086
+ "Alert",
3087
+ "Button",
3088
+ "Center",
3089
+ "Cluster",
3090
+ "Form",
3091
+ "FormField",
3092
+ "Heading",
3093
+ "SettingsSection",
3094
+ "Stack",
3095
+ "TextField",
3096
+ "UserImage"
3097
+ ]
3098
+ }
3099
+ ]
3100
+ },
3101
+ {
3102
+ "id": "quick-switcher",
3103
+ "title": "Quick switcher",
3104
+ "kind": "design",
3105
+ "level": "organism",
3106
+ "area": "menu",
3107
+ "situation": "A person jumps to a channel, task or document by typing part of its name, from anywhere in the product.",
3108
+ "do": [
3109
+ "Open it with Cmd+K, or Ctrl+K on Windows, and with a visible 'Go to' Button. A shortcut alone is not found.",
3110
+ "Add the shortcut with `useHotkey('k', …)`. It is removed when the page goes away, and it does nothing while the person types in a field.",
3111
+ "Open a small `Modal` with `initialFocus=\"body\"`, so focus lands in the search field. Closing gives focus back to where it was.",
3112
+ "Build it as a combobox, as the case 'Mention list' says. The field gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`.",
3113
+ "Make the list a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows, with `isActive` and `aria-selected` on the highlighted one.",
3114
+ "Name the field with `aria-label=\"Go to\"`, since it has no visible label.",
3115
+ "Show the most recent places, at most 6, before the person types.",
3116
+ "Show each place with its icon and name, and where it lives in `secondLabel`.",
3117
+ "Move the highlight with the arrow keys. Enter opens the highlighted place and closes the Modal. Escape closes it.",
3118
+ "Leave Enter and the arrow keys to an input method while it is still composing.",
3119
+ "Follow the case 'Empty search' when nothing matches: the words searched for and a 'Clear Search' Button, which puts focus back in the field."
3120
+ ],
3121
+ "dont": [
3122
+ "Do not use the shortcut as the only way in.",
3123
+ "Do not take Cmd+K while the person types in a field. Some fields use it for their own commands.",
3124
+ "Do not move focus into the list. The person keeps typing in the field.",
3125
+ "Do not keep the last search. It opens empty.",
3126
+ "Do not show a toast after going to a place. The page changing says it."
3127
+ ],
3128
+ "native": "On Apple use a sheet with a `TextField` over a `List`, opened with `.keyboardShortcut(\"k\")`, and `ContentUnavailableView.search(text:)` when nothing matches. A phone needs no switcher: use the search tab.",
3129
+ "options": [
3130
+ {
3131
+ "id": "modal",
3132
+ "title": "Small Modal with a search field and a list",
3133
+ "useWhen": "The product has many places to go to, and people work with a keyboard.",
3134
+ "source": "'use client';\nimport { useState, type KeyboardEvent } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The most recent place comes first.\ntype Place = { id: string; title: string; kind: 'channel' | 'task' | 'doc'; workspace: string };\nconst places: Place[] = [\n { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },\n { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },\n { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },\n { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },\n { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },\n { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },\n];\nconst icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' } as const;\n\n// At most this many rows show, so the list never needs to scroll; typing more letters narrows it.\nconst MAX_RESULTS = 6;\nconst listId = 'quick-switcher-results';\nconst optionId = (p: Place) => `quick-switcher-option-${p.id}`;\n\n// Places with a word that starts with what was typed. With nothing typed it shows the most recent.\nfunction matches(query: string) {\n const q = query.trim().toLowerCase();\n if (!q) return places.slice(0, MAX_RESULTS);\n return places.filter((p) => p.title.toLowerCase().split(/[\\s-]+/).some((w) => w.startsWith(q))).slice(0, MAX_RESULTS);\n}\n\nexport default function QuickSwitcherModal() {\n // Opens with the switcher showing, as if the person just pressed Cmd+K.\n const [open, setOpen] = useState(true);\n const [query, setQuery] = useState('la');\n const [active, setActive] = useState(0);\n const [here, setHere] = useState<Place>(places[0]);\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field\n // instead of being lost with the Button that the list replaces.\n const [fieldKey, setFieldKey] = useState(0);\n\n const results = matches(query);\n const listOpen = results.length > 0;\n\n function openSwitcher() {\n setQuery('');\n setActive(0);\n setOpen(true);\n }\n\n // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.\n useHotkey('k', () => {\n if (!open) openSwitcher();\n });\n\n function change(value: string) {\n setQuery(value);\n setActive(0);\n }\n\n // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.\n function go(place: Place) {\n setHere(place);\n setOpen(false);\n }\n\n function clearSearch() {\n setQuery('');\n setActive(0);\n setFieldKey((k) => k + 1);\n }\n\n // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.\n function keyDown(e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!listOpen) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n go(results[active]);\n }\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">{here.title}</Heading>\n {/* A shortcut alone is not found by most people, so a Button opens it too. */}\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label=\"Go to\"\n decoIcon=\"Search\"\n aria-haspopup=\"dialog\"\n aria-keyshortcuts=\"Meta+K Control+K\"\n onClickButton={openSwitcher}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.\n </Paragraph>\n </Stack>\n <Modal isOpen={open} size=\"small\" title=\"Go to\" initialFocus=\"body\" onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n <TextField\n key={fieldKey}\n id=\"quick-switcher-query\"\n type=\"search\"\n // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.\n autoFocus={fieldKey > 0}\n aria-label=\"Go to\"\n placeholder=\"Search channels, tasks and documents\"\n value={query}\n onChange={(e) => change(e.target.value)}\n onKeyDown={keyDown}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listId : undefined}\n aria-activedescendant={listOpen ? optionId(results[active]) : undefined}\n />\n {listOpen ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Places\" width=\"100%\">\n {results.map((p, i) => (\n <MenuItem\n key={p.id}\n id={optionId(p)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName={icons[p.kind]}\n label={p.title}\n secondLabel={p.workspace}\n onClick={() => go(p)}\n />\n ))}\n </Menu>\n ) : (\n // The case 'Empty search' says what to show: the words searched for, and a way to clear them.\n <EmptyBox\n size=\"small\"\n icon=\"Search\"\n text={`No places match \"${query.trim()}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n )}\n </Stack>\n </Modal>\n </Center>\n );\n}\n",
3135
+ "uses": [
3136
+ "Button",
3137
+ "Center",
3138
+ "Cluster",
3139
+ "EmptyBox",
3140
+ "Heading",
3141
+ "Menu",
3142
+ "MenuItem",
3143
+ "Modal",
3144
+ "Paragraph",
3145
+ "Stack",
3146
+ "TextField",
3147
+ "useHotkey"
3148
+ ]
3149
+ }
3150
+ ]
3151
+ },
3152
+ {
3153
+ "id": "range-switch",
3154
+ "title": "Range switch",
3155
+ "kind": "design",
3156
+ "level": "organism",
3157
+ "area": "menu",
3158
+ "situation": "A person changes the time range of a chart or a list on the same page, such as Week, Month or Quarter.",
3159
+ "do": [
3160
+ "Use `SegmentedControl` with `size=\"small\"` and `aria-label=\"Range\"`: 'Week', 'Month', 'Quarter'.",
3161
+ "Put it beside the heading of the chart or list it changes, with `width=\"fit\"` so it is as wide as its options.",
3162
+ "Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
3163
+ "Change the numbers in place and keep the page, the heading and the scroll position.",
3164
+ "Move between options with the arrow keys. They select as they move."
3165
+ ],
3166
+ "dont": [
3167
+ "Do not use tabs. Tabs switch panels, and this changes one value on the same page.",
3168
+ "Do not use more than four options. Use a menu, as the case 'Filter menu' says.",
3169
+ "Do not let the person turn every option off.",
3170
+ "Do not hide a range of three choices behind a menu."
3171
+ ],
3172
+ "native": "On Apple use a `Picker` with the `.segmented` style, and on Android a `SingleChoiceSegmentedButtonRow`.",
3173
+ "options": [
3174
+ {
3175
+ "id": "segmented",
3176
+ "title": "Segmented control",
3177
+ "useWhen": "Two to four short choices change the numbers on one page, and one is always on.",
3178
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst ranges = [\n { value: 'week', label: 'Week', count: 18 },\n { value: 'month', label: 'Month', count: 64 },\n { value: 'quarter', label: 'Quarter', count: 171 },\n];\n\nexport default function RangeSwitchSegmented() {\n const [range, setRange] = useState('week');\n const current = ranges.find((r) => r.value === range) ?? ranges[0];\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Overview</Heading>\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Range\"\n options={ranges.map(({ value, label }) => ({ value, label }))}\n value={range}\n onChange={setRange}\n />\n </Cluster>\n {/* The chart or list below changes with the range. This page stays the same. */}\n <Paragraph size=\"body2\" measure=\"none\">{current.count} comments this {current.label.toLowerCase()}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
3179
+ "uses": [
3180
+ "Center",
3181
+ "Cluster",
3182
+ "Heading",
3183
+ "Paragraph",
3184
+ "SegmentedControl",
3185
+ "Stack"
3186
+ ]
3187
+ }
3188
+ ]
3189
+ },
3190
+ {
3191
+ "id": "rename",
3192
+ "title": "Rename",
3193
+ "kind": "design",
3194
+ "level": "organism",
3195
+ "area": "confirm",
3196
+ "situation": "A person renames something, such as a project or a channel.",
3197
+ "do": [
3198
+ "Title the Modal 'Rename' and the thing, such as 'Rename Project', and give its action the same verb: 'Rename'.",
3199
+ "Keep 'Rename' `state=\"disabled\"` while the name is empty or unchanged.",
3200
+ "Save on Enter too: put the field in a `Form`.",
3201
+ "Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
3202
+ "Focus the field with `autoFocus` when the name becomes a field in place.",
3203
+ "Save on Enter and when the person leaves the field. Cancel on Escape, and when the name is empty."
1450
3204
  ],
1451
- "notBuiltYet": "Commentify's page not found is one line of bare text, 'Page not found.', with no way home. Scindo on the web shows '404' as its heading, then bare text and a text link home. jinhwankim.com has no heading: it puts '404:' at the start of its `EmptyBox` text and labels its Button 'Go to Home'.",
1452
- "seenIn": [
1453
- "Commentify",
1454
- "Scindo",
1455
- "jinhwankim.com"
3205
+ "dont": [
3206
+ "Do not label the Modal's action 'Save' or 'OK'.",
3207
+ "Do not show a toast after a rename. The new name shows where the old one was.",
3208
+ "Do not save an empty name.",
3209
+ "Do not drop what the person typed when they leave the field."
1456
3210
  ],
3211
+ "native": "On Apple rename in place in a list with a `TextField` and `.onSubmit`. Use an `.alert` with a `TextField` when the name is not on screen.",
1457
3212
  "options": [
1458
3213
  {
1459
- "id": "full-page",
1460
- "title": "Full page",
1461
- "useWhen": "The address is outside the app shell, so nothing else can show.",
1462
- "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function NotFoundPageFullPage() {\n return (\n <Center fill>\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Center>\n );\n}\n",
3214
+ "id": "modal",
3215
+ "title": "Rename in a Modal",
3216
+ "useWhen": "Rename is opened from a menu or from far away from the name.",
3217
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// Names the server already has. Type one to see the request fail.\nconst takenNames = ['website refresh', 'hiring plan', 'office move'];\n\nexport default function RenameModal() {\n const [name, setName] = useState('Q3 plan');\n // Opens on the Modal, as if the person just chose Rename Project.\n const [open, setOpen] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = draft.trim();\n const canRename = next !== '' && next !== name;\n\n function handleOpen() {\n setDraft(name);\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (saving) return;\n setOpen(false);\n }\n\n function handleRename() {\n if (saving || !canRename) return;\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (takenNames.includes(next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setName(next);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* A real app often opens Rename from a menu on the project. */}\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Rename Project\" onClickButton={handleOpen} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Rename Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={canRename ? 'enabled' : 'disabled'} label=\"Rename\" loading={saving} onClickButton={handleRename} />\n </>\n }\n >\n {/* The Form lets Enter in the field rename too. */}\n <Form aria-label=\"Rename project\" onSubmit={handleRename}>\n <TextField id=\"rename-name\" label=\"Project name\" value={draft} disabled={saving} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setDraft(e.target.value); setNameError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
1463
3218
  "uses": [
1464
3219
  "Button",
1465
3220
  "Center",
1466
3221
  "Cluster",
3222
+ "Form",
1467
3223
  "Heading",
3224
+ "Modal",
1468
3225
  "Paragraph",
1469
- "Stack"
3226
+ "Stack",
3227
+ "TextField"
1470
3228
  ]
1471
3229
  },
1472
3230
  {
1473
- "id": "in-shell",
1474
- "title": "Inside the shell",
1475
- "useWhen": "The address is inside the app and the navigation still works.",
1476
- "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function NotFoundPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
3231
+ "id": "inline",
3232
+ "title": "Rename in place",
3233
+ "useWhen": "The name is on screen, and it becomes a field.",
3234
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function RenameInline() {\n const [name, setName] = useState('Q3 plan');\n // Opens with the name as a field, as if the person just chose Rename.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n\n function startEditing() {\n ended.current = false;\n setDraft(name);\n setEditing(true);\n }\n\n function save() {\n if (ended.current) return;\n ended.current = true;\n const next = draft.trim();\n // An empty or unchanged name cancels: there is nothing to send.\n // Otherwise a real app sends the new name to the server here and shows it at once.\n if (next && next !== name) setName(next);\n setEditing(false);\n }\n\n function cancel() {\n if (ended.current) return;\n ended.current = true;\n setEditing(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n {editing ? (\n <TextField\n id=\"rename-inline-name\"\n label=\"Project name\"\n value={draft}\n autoFocus\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n save();\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel();\n }\n }}\n onBlur={save}\n />\n ) : (\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Tooltip title=\"Rename\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Rename project\" onClick={startEditing} />\n </Tooltip>\n </Cluster>\n )}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
1477
3235
  "uses": [
1478
- "Button",
3236
+ "Center",
1479
3237
  "Cluster",
1480
3238
  "Heading",
1481
- "Image",
3239
+ "IconButton",
1482
3240
  "Paragraph",
1483
3241
  "Stack",
1484
- "Surface",
1485
- "Tab",
1486
- "TabsContainer"
3242
+ "TextField",
3243
+ "Tooltip"
1487
3244
  ]
1488
3245
  }
1489
3246
  ]
1490
3247
  },
1491
3248
  {
1492
- "id": "oauth-consent",
1493
- "title": "OAuth consent",
3249
+ "id": "reply-feedback",
3250
+ "title": "Reply feedback",
1494
3251
  "kind": "design",
1495
- "level": "page",
1496
- "area": "auth",
1497
- "situation": "Another app, such as a CLI or an MCP client, asks to act for a person who is logged in, and the person must allow it.",
3252
+ "level": "organism",
3253
+ "area": "agent",
3254
+ "situation": "The agent has replied, and the person can say whether the reply helped.",
1498
3255
  "do": [
1499
- "Name the app in a `Heading` with `level={1}`: 'Acme CLI wants to connect to Acme'.",
1500
- "Say in one or two plain sentences what the app will be able to do, in the person's words: 'read your projects and tasks, and create tasks as you'.",
1501
- "Say how to remove the access later: 'You can remove its access at any time in Settings, under Connected apps.'",
1502
- "Show the account that gives the access, with a text-only 'Not You? Switch Account' Button under it.",
1503
- "Take the app's name and the place the person goes back to from the server's record of the registered app, never from the link.",
1504
- "Say where the person goes next: 'You will go back to cli.acme.dev.'",
1505
- "Put 'Cancel' first and 'Allow' second, side by side and the same width, in a `Grid` with `columns={2}`.",
1506
- "Show `loading` on 'Allow' and disable 'Cancel' and every field while the request runs.",
1507
- "Show `LoadingScreen` with `label=\"Going back to Acme CLI…\"` while the browser goes back, after 'Allow' and after 'Cancel'.",
1508
- "Send 'Cancel' back to the app with `error=access_denied`, and return the `state` value the app sent on both paths.",
1509
- "Leave wider access off until the person turns it on, and say under it what it adds."
3256
+ "Put a row of small `IconButton`s with Tooltips in the agent reply's `footer`: thumbs up, thumbs down, Copy, then Regenerate.",
3257
+ "Name them for the reply: 'Mark reply as helpful', 'Mark reply as not helpful', 'Copy reply' and 'Regenerate reply'.",
3258
+ "Add what tells the replies apart to the names when several replies are on screen, such as the question each one answers.",
3259
+ "Mark the pressed thumb with `state=\"selected\"` and `aria-pressed`. Pressing it again clears it, and pressing the other thumb moves the mark.",
3260
+ "Show 'Thanks. This helps the agent improve.' after the buttons for 2 seconds. It is the only confirmation, since the result shows in place.",
3261
+ "Confirm in place, unlike the case 'Feedback form', which sends from a Modal and confirms with a toast.",
3262
+ "Announce the thanks politely: the app wraps it in a polite live region.",
3263
+ "Swap Copy's icon to `Check` for 2 seconds once the reply is copied.",
3264
+ "Show Regenerate on the latest reply only. It turns the row into the agent's progress row with 'Stop', as the case 'Agent at work' shows.",
3265
+ "Leave the old reply's time off the progress row while the new reply is written.",
3266
+ "Move focus to 'Stop' when Regenerate turns the row into a progress row.",
3267
+ "Keep the reply and its buttons when Regenerate fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
3268
+ "Keep the reply as it was when the person presses 'Stop', and say 'Stopped. Nothing was changed.' under it.",
3269
+ "Move focus back to Regenerate when the new reply is ready or the run has stopped.",
3270
+ "Show 'What was wrong?' after thumbs down, with four reason `Tag`s with `toggle={false}` and a tertiary small 'Skip' Button.",
3271
+ "Group the reasons under the question and name the group 'What was wrong?', so a screen reader hears them together.",
3272
+ "Close the reasons when the person picks one or presses 'Skip', show the thanks, and move focus back to thumbs down.",
3273
+ "Give the list that holds the rows `role=\"log\"`."
1510
3274
  ],
1511
3275
  "dont": [
1512
- "Do not color 'Allow' or 'Cancel' as danger. Allowing is the person's choice, not a destructive action.",
1513
- "Do not turn on wider access for the person.",
1514
- "Do not name the access by its scope id, such as 'tasks:write'.",
1515
- "Do not label Cancel 'Deny' or 'No'."
1516
- ],
1517
- "notBuiltYet": "Scindo on the web turns on access to every workspace for the person, and shows its spinner on neither Button while the request runs. Commentify puts 'Allow' before 'Deny', writes its error in a red caption by hand, and says nothing about how to remove the access.",
1518
- "seenIn": [
1519
- "Commentify",
1520
- "Scindo"
3276
+ "Do not show a toast for feedback. The thanks shows where the person pressed.",
3277
+ "Do not ask for a reason after thumbs up.",
3278
+ "Do not make the person pick a reason. 'Skip' closes the row.",
3279
+ "Do not show feedback buttons on a person's message.",
3280
+ "Do not show Regenerate on an older reply."
1521
3281
  ],
1522
3282
  "options": [
1523
3283
  {
1524
- "id": "simple",
1525
- "title": "One account, one access",
1526
- "useWhen": "The app gets one set of access to one account, so the only choice is to allow it or not.",
1527
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function OAuthConsentSimple() {\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read your projects and tasks, and create tasks as you. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
3284
+ "id": "thumbs",
3285
+ "title": "Thumbs",
3286
+ "useWhen": "The team wants a signal and will not read reasons.",
3287
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackThumbs() {\n const [thumb, setThumb] = useState<Thumb>(null);\n const [thanks, setThanks] = useState(false);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n clearTimeout(thanksTimer.current);\n setThanks(value !== null);\n if (value !== null) thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
1528
3288
  "uses": [
1529
- "Alert",
1530
3289
  "Button",
1531
3290
  "Center",
1532
3291
  "Cluster",
1533
- "Grid",
1534
3292
  "Heading",
1535
- "Image",
1536
- "LoadingScreen",
3293
+ "IconButton",
3294
+ "Message",
1537
3295
  "Paragraph",
1538
3296
  "Stack",
3297
+ "StepList",
3298
+ "Tag",
3299
+ "TimeStamp",
3300
+ "Tooltip",
1539
3301
  "UserImage"
1540
3302
  ]
1541
3303
  },
1542
3304
  {
1543
- "id": "with-scope",
1544
- "title": "Workspace and wider access",
1545
- "useWhen": "The person picks the workspace the app can use, or turns on wider access.",
1546
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Select from 'oneslash-design-system/components/select';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The workspaces the person belongs to.\nconst workspaces = [\n { value: 'design', label: 'Acme Design' },\n { value: 'marketing', label: 'Acme Marketing' },\n];\n\nexport default function OAuthConsentWithScope() {\n const [workspace, setWorkspace] = useState('design');\n // The wider access is off until the person turns it on.\n const [allWorkspaces, setAllWorkspaces] = useState(false);\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read the projects and tasks you can see, and create tasks as you, in the workspaces you allow below. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"small\">\n {/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Workspace</Paragraph>\n <Select aria-label=\"Workspace\" value={workspace} options={workspaces} disabled={allowing} onChange={(v) => setWorkspace(typeof v === 'string' ? v : v[0])} />\n </Stack>\n <Checkbox label=\"Also allow my other workspaces\" secondLabel=\"It can then do the same in every workspace you belong to. It still sees only what you can see.\" checked={allWorkspaces} disabled={allowing} onChange={setAllWorkspaces} />\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
3305
+ "id": "with-reason",
3306
+ "title": "With reason",
3307
+ "useWhen": "Someone reads the reasons and acts on them.",
3308
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\n\n// A real app sends the reason with the mark, for the team to read.\nconst reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackWithReason() {\n // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.\n const [thumb, setThumb] = useState<Thumb>('down');\n const [thanks, setThanks] = useState(false);\n // The reason row, open after thumbs down until a reason or Skip is picked.\n const [asking, setAsking] = useState(true);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const thumbsDownButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n function showThanks() {\n clearTimeout(thanksTimer.current);\n setThanks(true);\n thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // Thumbs down asks what was wrong; the thanks waits for the answer.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n setAsking(value === 'down');\n clearTimeout(thanksTimer.current);\n setThanks(false);\n if (value === 'up') showThanks();\n }\n\n // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.\n function finish() {\n setAsking(false);\n showThanks();\n thumbsDownButton.current?.focus();\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setAsking(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton ref={thumbsDownButton} color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n {asking && (\n <Cluster gap=\"small\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">What was wrong?</Paragraph>\n {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:\n a real app groups the reasons under the question, named 'What was wrong?'. */}\n {reasons.map((r) => (\n <Tag key={r} variant=\"contained\" size=\"small\" toggle={false} label={r} onClick={finish} />\n ))}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Skip\" onClickButton={finish} />\n </Cluster>\n )}\n </Stack>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
1547
3309
  "uses": [
1548
- "Alert",
1549
3310
  "Button",
1550
3311
  "Center",
1551
- "Checkbox",
1552
3312
  "Cluster",
1553
- "Grid",
1554
3313
  "Heading",
1555
- "Image",
1556
- "LoadingScreen",
3314
+ "IconButton",
3315
+ "Message",
1557
3316
  "Paragraph",
1558
- "Select",
1559
3317
  "Stack",
3318
+ "StepList",
3319
+ "Tag",
3320
+ "TimeStamp",
3321
+ "Tooltip",
1560
3322
  "UserImage"
1561
3323
  ]
1562
3324
  }
1563
3325
  ]
1564
3326
  },
1565
3327
  {
1566
- "id": "rename",
1567
- "title": "Rename",
3328
+ "id": "reply-sources",
3329
+ "title": "Reply sources",
1568
3330
  "kind": "design",
1569
3331
  "level": "organism",
1570
- "area": "confirm",
1571
- "situation": "A person renames something, such as a project or a channel.",
3332
+ "area": "agent",
3333
+ "situation": "The agent answered from things it read, and the person may want to check them.",
1572
3334
  "do": [
1573
- "Title the Modal 'Rename' and the thing, such as 'Rename Project', and give its action the same verb: 'Rename'.",
1574
- "Keep 'Rename' `state=\"disabled\"` while the name is empty or unchanged.",
1575
- "Save on Enter too: put the field in a `Form`.",
1576
- "Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
1577
- "Focus the field with `autoFocus` when the name becomes a field in place.",
1578
- "Save on Enter and when the person leaves the field. Cancel on Escape, and when the name is empty."
3335
+ "Follow the rule 'An agent shows its sources': put the sources in the reply's `footer`, directly under the reply.",
3336
+ "Name the kinds of source in one `Tag`, in the order they first appear: 'From Chat · Knowledge base'.",
3337
+ "Show each source as a `SourceCard` with an icon for its kind, its title, and in `meta` its kind and where it lives: 'Chat · #launch · Jan 12'.",
3338
+ "Lay the cards out in `<Grid columns={2}>` and show the first six.",
3339
+ "Show the rest with a text-only 'Show N More' Button, with the number of hidden cards. It then reads 'Show Fewer', which hides them again.",
3340
+ "Make a card the person can open a link with `href`. A source on another site opens in a new tab.",
3341
+ "Make a card the person cannot open static, with no `href` and no `onClick`, and say why in `meta`: 'Chat · Private channel you are not in'.",
3342
+ "Keep a static card's look at rest the same as the others'. It has no hover look.",
3343
+ "Link each card to its own source, such as the message it read. Two cards never share a link.",
3344
+ "Show only the `Tag` when the reply read only the messages already on screen above it, as the rule allows.",
3345
+ "Show no sources section when the reply used no sources.",
3346
+ "Mark the agent's row as the rule 'An agent says what it is' says.",
3347
+ "Give the list that holds the rows `role=\"log\"`."
1579
3348
  ],
1580
3349
  "dont": [
1581
- "Do not label the Modal's action 'Save' or 'OK'.",
1582
- "Do not show a toast after a rename. The new name shows where the old one was.",
1583
- "Do not save an empty name.",
1584
- "Do not drop what the person typed when they leave the field."
1585
- ],
1586
- "native": "On Apple rename in place in a list with a `TextField` and `.onSubmit`. Use an `.alert` with a `TextField` when the name is not on screen.",
1587
- "notBuiltYet": "Commentify's two renames disagree on what leaving the field does: a project name cancels, a tag name saves. Scindo on the web labels its rename Modals' action 'Save', shows 'Saving...' while it runs, and writes a taken name as a red caption by hand.",
1588
- "seenIn": [
1589
- "Commentify",
1590
- "Scindo"
3350
+ "Do not show sources on a person's message.",
3351
+ "Do not link a card to any site other than the product or the service the source came from.",
3352
+ "Do not make a card look clickable when the person cannot open it.",
3353
+ "Do not show more than six cards before the person asks for the rest."
1591
3354
  ],
3355
+ "native": "On Apple the cards fill as many columns as fit. A card with a link opens it in the browser, and a card with nothing to open cannot be tapped.",
1592
3356
  "options": [
1593
3357
  {
1594
- "id": "modal",
1595
- "title": "Rename in a Modal",
1596
- "useWhen": "Rename is opened from a menu or from far away from the name.",
1597
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// Names the server already has. Type one to see the request fail.\nconst takenNames = ['website refresh', 'hiring plan', 'office move'];\n\nexport default function RenameModal() {\n const [name, setName] = useState('Q3 plan');\n // Opens on the Modal, as if the person just chose Rename Project.\n const [open, setOpen] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = draft.trim();\n const canRename = next !== '' && next !== name;\n\n function handleOpen() {\n setDraft(name);\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (saving) return;\n setOpen(false);\n }\n\n function handleRename() {\n if (saving || !canRename) return;\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (takenNames.includes(next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setName(next);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* A real app often opens Rename from a menu on the project. */}\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Rename Project\" onClickButton={handleOpen} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Rename Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={canRename ? 'enabled' : 'disabled'} label=\"Rename\" loading={saving} onClickButton={handleRename} />\n </>\n }\n >\n {/* The Form lets Enter in the field rename too. */}\n <Form aria-label=\"Rename project\" onSubmit={handleRename}>\n <TextField id=\"rename-name\" label=\"Project name\" value={draft} disabled={saving} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setDraft(e.target.value); setNameError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
3358
+ "id": "cards",
3359
+ "title": "Source cards",
3360
+ "useWhen": "The reply read things a person can open.",
3361
+ "source": "'use client';\nimport { useState } from 'react';\nimport { BookOpen, Bot, MessageSquare, Plug } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What did we decide about the launch date?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\nconst reply = 'The launch moved to March 3. Ben asked for two more weeks of testing, and the team agreed in #launch on Jan 12.';\n\ntype Kind = 'chat' | 'kb';\n// A source with no href is one the person cannot open: its meta says why. Each chat card links to the message it read.\ntype Source = { kind: Kind; title: string; where: string; href?: string };\n\nconst kinds = {\n chat: { label: 'Chat', icon: MessageSquare },\n kb: { label: 'Knowledge base', icon: BookOpen },\n};\n\nconst sources: Source[] = [\n { kind: 'chat', title: 'Launch date', where: '#launch · Jan 12', href: '/chat/launch/m-1042' },\n { kind: 'kb', title: 'Launch plan 2025', where: 'Acme Design', href: '/docs/launch-plan-2025' },\n { kind: 'chat', title: 'Testing schedule', where: '#qa · Jan 10', href: '/chat/qa/m-0981' },\n { kind: 'kb', title: 'Release checklist', where: 'Acme Design', href: '/docs/release-checklist' },\n { kind: 'chat', title: 'Budget for the launch', where: 'Private channel you are not in' },\n { kind: 'kb', title: 'Press kit guide', where: 'Acme Marketing', href: '/docs/press-kit-guide' },\n { kind: 'chat', title: 'Beta feedback', where: '#beta · Jan 8', href: '/chat/beta/m-0917' },\n { kind: 'kb', title: 'Pricing for the new plans', where: 'Acme Design', href: '/docs/pricing' },\n { kind: 'chat', title: 'Launch day roles', where: '#launch · Jan 14', href: '/chat/launch/m-1107' },\n { kind: 'kb', title: 'Support playbook', where: 'Acme Support', href: '/docs/support-playbook' },\n];\n\nconst visible = 6;\n\n// 'From Chat · Knowledge base': each kind once, in the order it first appears.\nfunction kindsTag(list: Source[]) {\n const labels: string[] = [];\n list.forEach((s) => {\n if (!labels.includes(kinds[s.kind].label)) labels.push(kinds[s.kind].label);\n });\n return `From ${labels.join(' · ')}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplySourcesCards() {\n const [expanded, setExpanded] = useState(false);\n const shown = expanded ? sources : sources.slice(0, visible);\n const more = sources.length - visible;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n // A reply that used no sources has no footer at all.\n footer={\n <Stack gap=\"medium\">\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color=\"success\" icon={Plug} label={kindsTag(sources)} />\n </Cluster>\n <Grid columns={2} gap=\"medium\">\n {shown.map((s) => (\n // A source in the product is a path; one on another site is an https:// URL and opens in a new tab.\n <SourceCard\n key={`${s.kind}:${s.title}`}\n icon={kinds[s.kind].icon}\n title={s.title}\n meta={`${kinds[s.kind].label} · ${s.where}`}\n href={s.href}\n />\n ))}\n </Grid>\n {more > 0 && (\n <Cluster>\n <Button\n size=\"small\"\n type=\"textOnly\"\n state=\"enabled\"\n label={expanded ? 'Show Fewer' : `Show ${more} More`}\n aria-expanded={expanded}\n onClickButton={() => setExpanded((e) => !e)}\n />\n </Cluster>\n )}\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
1598
3362
  "uses": [
1599
3363
  "Button",
1600
3364
  "Center",
1601
3365
  "Cluster",
1602
- "Form",
3366
+ "Grid",
1603
3367
  "Heading",
1604
- "Modal",
3368
+ "Message",
1605
3369
  "Paragraph",
3370
+ "SourceCard",
1606
3371
  "Stack",
1607
- "TextField"
3372
+ "Tag",
3373
+ "TimeStamp",
3374
+ "UserImage"
1608
3375
  ]
1609
3376
  },
1610
3377
  {
1611
- "id": "inline",
1612
- "title": "Rename in place",
1613
- "useWhen": "The name is on screen, and it becomes a field.",
1614
- "source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function RenameInline() {\n const [name, setName] = useState('Q3 plan');\n // Opens with the name as a field, as if the person just chose Rename.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n\n function startEditing() {\n ended.current = false;\n setDraft(name);\n setEditing(true);\n }\n\n function save() {\n if (ended.current) return;\n ended.current = true;\n const next = draft.trim();\n // An empty or unchanged name cancels: there is nothing to send.\n // Otherwise a real app sends the new name to the server here and shows it at once.\n if (next && next !== name) setName(next);\n setEditing(false);\n }\n\n function cancel() {\n if (ended.current) return;\n ended.current = true;\n setEditing(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n {editing ? (\n <TextField\n id=\"rename-inline-name\"\n label=\"Project name\"\n value={draft}\n autoFocus\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n save();\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel();\n }\n }}\n onBlur={save}\n />\n ) : (\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Tooltip title=\"Rename\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Rename project\" onClick={startEditing} />\n </Tooltip>\n </Cluster>\n )}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
3378
+ "id": "tag-only",
3379
+ "title": "Tag only",
3380
+ "useWhen": "The reply read only the messages already on screen above it.",
3381
+ "source": "'use client';\nimport { Bot, Plug } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst thread = [\n { from: 'Ben Carter', at: new Date('2025-01-15T11:36:00Z'), text: 'Testing needs two more weeks. It now ends on January 31.' },\n { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Acme Agent, what does that do to the launch date?' },\n];\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// The agent read only the messages above, which the person can already see.\nconst reply = 'If testing ends on January 31, the launch moves to March 3. That keeps the two weeks Ben asked for.';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplySourcesTagOnly() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.from}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n // One kind of source, already on screen: the tag says where the answer came from, and no cards follow.\n footer={\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color=\"success\" icon={Plug} label=\"From Chat\" />\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
1615
3382
  "uses": [
1616
3383
  "Center",
1617
3384
  "Cluster",
1618
3385
  "Heading",
1619
- "IconButton",
3386
+ "Message",
1620
3387
  "Paragraph",
1621
3388
  "Stack",
1622
- "TextField",
1623
- "Tooltip"
3389
+ "Tag",
3390
+ "TimeStamp",
3391
+ "UserImage"
1624
3392
  ]
1625
3393
  }
1626
3394
  ]
@@ -1645,10 +3413,6 @@
1645
3413
  "Do not show the empty text while the list is still loading."
1646
3414
  ],
1647
3415
  "native": "On Apple use `ProgressView()` with no label, centered in the pane.",
1648
- "seenIn": [
1649
- "Commentify",
1650
- "Scindo"
1651
- ],
1652
3416
  "options": [
1653
3417
  {
1654
3418
  "id": "full-screen",
@@ -1677,6 +3441,50 @@
1677
3441
  }
1678
3442
  ]
1679
3443
  },
3444
+ {
3445
+ "id": "scope-picker",
3446
+ "title": "Scope picker",
3447
+ "kind": "design",
3448
+ "level": "organism",
3449
+ "area": "menu",
3450
+ "situation": "A person chooses where a search or a question looks, such as one workspace or all of them.",
3451
+ "do": [
3452
+ "Use a small tertiary `Button` whose label is the current scope, with `actionIcon=\"ChevronDown\"` so it looks like it opens a menu.",
3453
+ "Open a navigable menu from it: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Where to search\">` with `onClick` items.",
3454
+ "Put 'All Workspaces' first, then a `Line`, then one item for each workspace.",
3455
+ "Give each item `role=\"menuitemradio\"` and mark the current scope with `isSelected`, which sets `aria-checked`.",
3456
+ "Give the Button an `aria-label` that starts with its label and says what it does: 'Acme Design, change where to search'.",
3457
+ "Set `aria-haspopup=\"menu\"` and `aria-expanded` on the Button, and `state=\"selected\"` while the menu is open.",
3458
+ "Say what the scope means under the control, such as which workspaces the answers use."
3459
+ ],
3460
+ "dont": [
3461
+ "Do not use a `Select` for a scope that sits in a toolbar.",
3462
+ "Do not put the scope in the Button without a chevron.",
3463
+ "Do not open the menu when the page loads.",
3464
+ "Do not keep the menu open after a choice."
3465
+ ],
3466
+ "native": "On Apple use a toolbar `Menu` with a `Picker` inside it, and on Android a dropdown menu.",
3467
+ "options": [
3468
+ {
3469
+ "id": "menu",
3470
+ "title": "Button with a menu",
3471
+ "useWhen": "There are a few places to choose from, and one choice means everything.",
3472
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst workspaces = ['Acme Design', 'Acme Engineering', 'Acme Marketing'];\nconst all = 'All Workspaces';\n\nexport default function ScopePickerMenu() {\n // null means every workspace.\n const [scope, setScope] = useState<string | null>(null);\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const label = scope ?? all;\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string | null) {\n setScope(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Ask Acme</Heading>\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Searching in</Paragraph>\n {/* The label is the scope. The chevron says it opens a menu. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={open ? 'selected' : 'enabled'}\n label={label}\n actionIcon=\"ChevronDown\"\n aria-label={`${label}, change where to search`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClickButton={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {scope ? `Answers use only ${scope}.` : `Answers use all ${workspaces.length} of your workspaces.`}\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Where to search\" width={220}>\n <MenuItem size=\"small\" label={all} isSelected={scope === null} role=\"menuitemradio\" onClick={() => choose(null)} />\n <Line />\n {workspaces.map((w) => (\n <MenuItem key={w} size=\"small\" label={w} isSelected={scope === w} role=\"menuitemradio\" onClick={() => choose(w)} />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
3473
+ "uses": [
3474
+ "Button",
3475
+ "Center",
3476
+ "Cluster",
3477
+ "Heading",
3478
+ "Line",
3479
+ "Menu",
3480
+ "MenuItem",
3481
+ "Paragraph",
3482
+ "Popover",
3483
+ "Stack"
3484
+ ]
3485
+ }
3486
+ ]
3487
+ },
1680
3488
  {
1681
3489
  "id": "set-new-password",
1682
3490
  "title": "Set new password",
@@ -1701,11 +3509,6 @@
1701
3509
  "Do not replace the form with a spinner while updating.",
1702
3510
  "Do not show the form when the link is invalid or expired."
1703
3511
  ],
1704
- "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while updating, and show field problems in an Alert above the fields. Both accept 6 characters, and say 'Password must be at least 6 characters.' only after it is broken. Scindo's reset page has no invalid-link state.",
1705
- "seenIn": [
1706
- "Commentify",
1707
- "Scindo"
1708
- ],
1709
3512
  "options": [
1710
3513
  {
1711
3514
  "id": "form",
@@ -1745,6 +3548,113 @@
1745
3548
  }
1746
3549
  ]
1747
3550
  },
3551
+ {
3552
+ "id": "settings-page",
3553
+ "title": "Settings page",
3554
+ "kind": "design",
3555
+ "level": "page",
3556
+ "area": "settings",
3557
+ "situation": "A person opens the settings of the product and looks for one area, such as Profile or Billing.",
3558
+ "do": [
3559
+ "Title the page 'Settings' with a level 1 `Heading`.",
3560
+ "Follow the rule 'A setting saves in place, or with one Save Button' in every area.",
3561
+ "Put each area's controls in `SettingsSection`s. Put them in `SettingsColumns` when an area has several: one column on a phone, two from `md`.",
3562
+ "Give each `Tab` an `href` and the app's `router`, so the selected Tab follows the page.",
3563
+ "Keep the tabs to four areas or fewer, each named with one short word, such as 'Profile' or 'Billing', so the tabs fit on a phone without scrolling.",
3564
+ "Group the areas in a `Navigation` with `aria-label=\"Settings\"` when there are more. Give each `NavigationGroup` a `label`, such as 'Account' and 'Workspace'.",
3565
+ "Make each nav item a `MenuItem` with an `href`. Mark the open one with `isSelected` and `aria-current=\"page\"`.",
3566
+ "Put 'Log Out' last in the nav, and ask first as the case 'Log-out confirm' says.",
3567
+ "Use `SettingsLayout` for the side nav. From `md` the nav sits beside the area. On a phone the nav is the page, and choosing an item opens that area alone.",
3568
+ "Show a 'Back to Settings' Button above the area on a phone, and nothing at `md` and up. It goes back to the nav.",
3569
+ "Show a setting a person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
3570
+ ],
3571
+ "dont": [
3572
+ "Do not use tabs for more than four areas. They run off a phone screen.",
3573
+ "Do not show the nav and the area together on a phone.",
3574
+ "Do not leave a phone with no way back to the nav.",
3575
+ "Do not put a Save Button for the whole page. Each group saves by itself.",
3576
+ "Do not call it 'Preferences' in one place and 'Settings' in another."
3577
+ ],
3578
+ "native": "On macOS use a `Settings` scene with one tab per area, or a `NavigationSplitView` with a sidebar `List` in `Section`s. On iPhone the list is the first screen and an item pushes its area. On Android use a list of areas that opens each one on its own screen.",
3579
+ "options": [
3580
+ {
3581
+ "id": "top-tabs",
3582
+ "title": "Tabs across the top",
3583
+ "useWhen": "Four areas or fewer, with short names that fit on a phone.",
3584
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport SettingsSection, { SettingsColumns } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = 'profile' | 'notifications' | 'billing';\n\n// Four areas or fewer, each named with one short word, so the tabs fit on a phone. Each tab is a page of its own in a real app, so it has an `href`.\nconst areas: { id: Area; label: string }[] = [\n { id: 'profile', label: 'Profile' },\n { id: 'notifications', label: 'Notifications' },\n { id: 'billing', label: 'Billing' },\n];\n\nconst invoices = ['January 2025, $40.00', 'December 2024, $40.00', 'November 2024, $40.00'];\n\nexport default function SettingsPageTopTabs() {\n const [area, setArea] = useState<Area>('profile');\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open area.\n const router = { push: (url: string) => setArea(url.split('/').pop() as Area) };\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-tabs-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-email\" title=\"Email\" description=\"Where Acme writes to you.\">\n <FormField id=\"settings-page-tabs-email-field\" label=\"Email\" help=\"Only support can change this. Write to help@acme.example.\">\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} value=\"dana@acme.example\" readOnly onChange={() => {}} />}\n </FormField>\n </SettingsSection>\n </SettingsColumns>\n );\n\n const notifications = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-email-alerts\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-tabs-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-tabs-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n </SettingsColumns>\n );\n\n const billing = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-plan\" title=\"Plan\" description=\"Team plan, 5 seats.\">\n <Paragraph size=\"body2\" measure=\"none\">Renews on January 15. Only owners can change the plan.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-invoices\" title=\"Invoices\" description=\"The last three months.\">\n <List items={invoices} size=\"body2\" />\n </SettingsSection>\n </SettingsColumns>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <TabsContainer>\n {areas.map((a) => (\n <Tab key={a.id} label={a.label} href={`/settings/${a.id}`} router={router} isSelected={area === a.id} onClickTab={() => setArea(a.id)} />\n ))}\n </TabsContainer>\n {area === 'profile' && profile}\n {area === 'notifications' && notifications}\n {area === 'billing' && billing}\n </Stack>\n </Center>\n );\n}\n",
3585
+ "uses": [
3586
+ "Button",
3587
+ "Center",
3588
+ "Cluster",
3589
+ "Form",
3590
+ "FormField",
3591
+ "Heading",
3592
+ "List",
3593
+ "Paragraph",
3594
+ "SettingsColumns",
3595
+ "SettingsSection",
3596
+ "Stack",
3597
+ "Switch",
3598
+ "Tab",
3599
+ "TabsContainer",
3600
+ "TextField"
3601
+ ]
3602
+ },
3603
+ {
3604
+ "id": "side-nav",
3605
+ "title": "Side navigation in groups",
3606
+ "useWhen": "There are more areas, and they fall into groups.",
3607
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport SettingsSection, { SettingsLayout } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = { id: string; label: string; icon: string; group: string; description: string };\n\n// Areas in groups, as the side nav lists them. Each is a page of its own in a real app, so it has an `href`.\nconst areas: Area[] = [\n { id: 'profile', label: 'Profile', icon: 'User', group: 'Account', description: 'How people see you in Acme.' },\n { id: 'notifications', label: 'Notifications', icon: 'Bell', group: 'Account', description: 'Choose what reaches you.' },\n { id: 'general', label: 'General', icon: 'Settings', group: 'Workspace', description: 'The name and defaults of the Acme workspace.' },\n { id: 'members', label: 'Members', icon: 'Users', group: 'Workspace', description: 'Who is in Acme, and what they can do.' },\n { id: 'billing', label: 'Billing', icon: 'CreditCard', group: 'Workspace', description: 'Your plan and invoices.' },\n { id: 'api-keys', label: 'API Keys', icon: 'Key', group: 'Developers', description: 'Keys for tools that use Acme.' },\n { id: 'webhooks', label: 'Webhooks', icon: 'Webhook', group: 'Developers', description: 'Send Acme events to other tools.' },\n];\n\nconst groups = ['Account', 'Workspace', 'Developers'];\n\nexport default function SettingsPageSideNav() {\n const [areaId, setAreaId] = useState('profile');\n // On a phone the nav is the page: it shows until the person opens an area, and 'Back to Settings' returns to it.\n const [opened, setOpened] = useState(false);\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n const [confirmingLogOut, setConfirmingLogOut] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n const area = areas.find((a) => a.id === areaId) ?? areas[0];\n\n function handleOpen(id: string) {\n setAreaId(id);\n setOpened(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleLogOutClose() {\n if (loggingOut) return;\n setConfirmingLogOut(false);\n }\n\n function handleLogOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n timers.current.push(setTimeout(() => {\n setLoggingOut(false);\n setConfirmingLogOut(false);\n setLoggedOut(true);\n }, 1200));\n }\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsSection id=\"settings-page-nav-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-nav-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n );\n\n const notifications = (\n <SettingsSection id=\"settings-page-nav-email\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-nav-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-nav-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n );\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => setLoggedOut(false)} />\n </Cluster>\n </Center>\n );\n }\n\n const nav = (\n <Navigation aria-label=\"Settings\">\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {areas.filter((a) => a.group === group).map((a) => (\n <MenuItem\n key={a.id}\n size=\"small\"\n label={a.label}\n iconName={a.icon}\n href={`/settings/${a.id}`}\n isSelected={a.id === area.id}\n aria-current={a.id === area.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n handleOpen(a.id);\n }}\n />\n ))}\n </NavigationGroup>\n ))}\n <NavigationGroup label=\"Session\">\n <MenuItem size=\"small\" label=\"Log Out\" iconName=\"LogOut\" role=\"button\" onClick={() => setConfirmingLogOut(true)} />\n </NavigationGroup>\n </Navigation>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <SettingsLayout\n nav={nav}\n showContent={opened}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Settings\" onClickButton={() => setOpened(false)} />}\n >\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">{area.label}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{area.description}</Paragraph>\n </Stack>\n {area.id === 'profile' && profile}\n {area.id === 'notifications' && notifications}\n {area.id !== 'profile' && area.id !== 'notifications' && (\n <Paragraph size=\"body2\" measure=\"none\">Nothing to show for {area.label} in this example.</Paragraph>\n )}\n </SettingsLayout>\n </Stack>\n <Modal\n isOpen={confirmingLogOut}\n size=\"small\"\n title=\"Log Out\"\n onClose={handleLogOutClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleLogOutClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={handleLogOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3608
+ "uses": [
3609
+ "Button",
3610
+ "Center",
3611
+ "Cluster",
3612
+ "Form",
3613
+ "FormField",
3614
+ "Heading",
3615
+ "MenuItem",
3616
+ "Modal",
3617
+ "Navigation",
3618
+ "NavigationGroup",
3619
+ "Paragraph",
3620
+ "SettingsLayout",
3621
+ "SettingsSection",
3622
+ "Stack",
3623
+ "Switch",
3624
+ "TextField"
3625
+ ]
3626
+ }
3627
+ ]
3628
+ },
3629
+ {
3630
+ "id": "settings-save",
3631
+ "title": "A setting saves in place, or with one Save Button",
3632
+ "kind": "rule",
3633
+ "level": "rule",
3634
+ "area": "settings",
3635
+ "situation": "A person changes a setting.",
3636
+ "answer": "A control that stands alone saves as soon as it changes: a `Switch`, a choice in a `RadioGroup` or a `Select`, or a picture the person chooses. It shows nothing on success, because the control already shows the new value. While the request runs it is busy: a `Switch` takes `busy`, and a `RadioGroup` or `Select` is disabled. If the save fails, the control goes back to its old value and says why next to itself: in a Switch's `error`, in the error line of its `FormField`, or in an inline error `Alert` under a control with no visible label, such as a role in a row. A group of fields that belong together, such as a name, a profile, instructions or a budget, has one Save Button for the whole group. The Button is `loading` while it saves, keeps its label, then reads 'Saved' for 2 seconds. It is disabled while nothing has changed. A group that fails to save follows the rule 'A form error shows next to the problem'. Leaving with unsaved changes follows the case 'Unsaved changes'. Never mix both in one group: a Switch beside a Save Button leaves the person unsure which one is saved. Never show a toast for a setting saved in place. The one exception is a setting chosen from a menu: the menu closes, so a failed save shows in a toast and the control goes back to its old value. A person who cannot change a setting sees it read-only, with one line that says who can change it.",
3637
+ "why": "A control that saves by itself needs no button, and a group needs one place to say it is saved. Mixing the two makes people guess what is saved and what is not.",
3638
+ "do": [
3639
+ "Save a `Switch`, a `RadioGroup` or a `Select` that stands alone as soon as it changes.",
3640
+ "Set the Switch `busy`, or disable the `RadioGroup` or `Select`, while the request runs, and show nothing when it works.",
3641
+ "Put the old value back when a save fails, and say why next to the control: 'Could not save. Try again.'",
3642
+ "Give a group of fields that belong together one Save Button.",
3643
+ "Show `loading` on the Save Button while it saves, keep its label, then show 'Saved' for 2 seconds.",
3644
+ "Keep the Save Button `state=\"disabled\"` while nothing has changed.",
3645
+ "Show a failed group save as the rule 'A form error shows next to the problem' says.",
3646
+ "Follow the case 'Unsaved changes' when the person leaves a group with changes.",
3647
+ "Show a setting the person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
3648
+ ],
3649
+ "dont": [
3650
+ "Do not mix a control that saves on change and a Save Button in one group.",
3651
+ "Do not show a toast for a setting saved in place, except a failed save of a setting chosen from a menu.",
3652
+ "Do not change the Button's label while it is loading, such as to 'Saving…'.",
3653
+ "Do not leave a failed save without a message.",
3654
+ "Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`."
3655
+ ],
3656
+ "native": "On Apple use the system `Toggle` and `Picker` that save as they change, and a `Form` with one Save Button for a group of fields. On Android use a `Switch`."
3657
+ },
1748
3658
  {
1749
3659
  "id": "sign-up-page",
1750
3660
  "title": "Sign-up page",
@@ -1771,12 +3681,7 @@
1771
3681
  "Do not replace the form with a spinner while creating the account.",
1772
3682
  "Do not say on the page whether an address already has an account."
1773
3683
  ],
1774
- "native": "On Apple, Scindo opens the web sign-up page with a `Link`. A sign-up built in the app uses `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
1775
- "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while creating the account. Neither says a password rule on its sign-up page. Their reset pages accept 6 characters and say 'Password must be at least 6 characters.' only after it is broken. Commentify asks for the first and last name in two fields.",
1776
- "seenIn": [
1777
- "Commentify",
1778
- "Scindo"
1779
- ],
3684
+ "native": "On Apple, the app opens the web sign-up page with a `Link`. A sign-up built in the app uses `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
1780
3685
  "options": [
1781
3686
  {
1782
3687
  "id": "centered",
@@ -1846,6 +3751,56 @@
1846
3751
  }
1847
3752
  ]
1848
3753
  },
3754
+ {
3755
+ "id": "slash-command-list",
3756
+ "title": "Command list",
3757
+ "kind": "design",
3758
+ "level": "organism",
3759
+ "area": "chat",
3760
+ "situation": "A person types / at the start of the message box to run a command.",
3761
+ "do": [
3762
+ "Open the list when the text starts with /. A bare / opens it, each letter after it narrows it, and a space closes it.",
3763
+ "Show at most 8 commands. Typing more letters finds the rest.",
3764
+ "Build it as a combobox. The text area gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows with `isActive` and `aria-selected`.",
3765
+ "Show each command with one line on what it does, and the argument it takes, such as '[topic]'. A menu row has no code font yet, so the command is plain text.",
3766
+ "Keep focus in the message box while the list is open, so the person keeps typing.",
3767
+ "Use the same keys as the case 'Mention list': the arrows move, Enter or Tab picks, Escape closes.",
3768
+ "Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.",
3769
+ "Close the list when the caret moves out of the command being typed, and when focus leaves the message box.",
3770
+ "Check the word at the caret again on Enter or Tab, and pick only if a command still matches. Shift+Tab picks nothing.",
3771
+ "Put the command and a space in place of the '/word' before the caret, and keep the text after it.",
3772
+ "Put the caret after that space, so the person can type the argument.",
3773
+ "Run the command when the person sends it. Every command works this way, even one that takes no argument.",
3774
+ "Close the list when no command matches."
3775
+ ],
3776
+ "dont": [
3777
+ "Do not move focus into the list. The person keeps typing in the field.",
3778
+ "Do not run a command on the Enter that picks it.",
3779
+ "Do not show an empty list.",
3780
+ "Do not open the list for a / in the middle of the text."
3781
+ ],
3782
+ "native": "On Apple the list shows above the field with the command, what it does and, when it takes an argument, its usage. Escape closes the list on a Mac.",
3783
+ "options": [
3784
+ {
3785
+ "id": "in-composer",
3786
+ "title": "List in the composer",
3787
+ "useWhen": "The default: the list opens over the text while the person types a command.",
3788
+ "source": "'use client';\nimport { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Command = { name: string; does: string; argument?: string };\nconst commands: Command[] = [\n { name: 'plan', does: 'Ask the agent for a plan before it acts' },\n { name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },\n { name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },\n { name: 'status', does: 'Show what the agent is working on' },\n];\n\nconst listId = 'slash-command-list-commands';\n// The list shows at most this many commands; typing more letters narrows it.\nconst MAX_MATCHES = 8;\nconst optionId = (c: Command) => `slash-command-list-option-${c.name}`;\n\ntype Row = { id: string; from: string; at: Date; text: string; command?: boolean };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },\n];\n\n// Opens with a / typed, so the list shows every command.\nconst firstText = '/';\n\n// The word after a / at the start of the text before the caret, or null once there is a space or no /.\nfunction commandQuery(before: string) {\n const match = before.match(/^\\/(\\S*)$/);\n return match ? match[1] : null;\n}\n\n// The query for where the caret is now.\nfunction queryAtCaret(field: HTMLTextAreaElement) {\n return commandQuery(field.value.slice(0, field.selectionStart ?? field.value.length));\n}\n\nconst matches = (query: string) => commands.filter((c) => c.name.startsWith(query.toLowerCase())).slice(0, MAX_MATCHES);\n\nexport default function SlashCommandListInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState(firstText);\n const [query, setQuery] = useState<string | null>(commandQuery(firstText));\n const [active, setActive] = useState(0);\n // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.\n const [caret, setCaret] = useState<number | null>(null);\n const field = useRef<HTMLTextAreaElement>(null);\n\n const results = query === null ? [] : matches(query);\n // No match: the list closes.\n const open = results.length > 0;\n\n // The field opens with the caret at the end, after the /.\n useEffect(() => {\n const end = field.current?.value.length ?? 0;\n field.current?.setSelectionRange(end, end);\n }, []);\n\n useEffect(() => {\n if (caret === null || !field.current) return;\n field.current.focus();\n field.current.setSelectionRange(caret, caret);\n setCaret(null);\n }, [caret]);\n\n function change(value: string) {\n setText(value);\n const at = field.current?.selectionStart ?? value.length;\n setQuery(commandQuery(value.slice(0, at)));\n setActive(0);\n }\n\n // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and\n // closes when the caret leaves it.\n function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {\n const next = queryAtCaret(e.currentTarget);\n if (next === query) return;\n setQuery(next);\n setActive(0);\n }\n\n // Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes\n // after the space, so the person can type the argument. Nothing runs yet.\n function pick(c: Command) {\n const at = field.current?.selectionStart ?? text.length;\n const insert = `/${c.name} `;\n // One space between the command and what follows, not two.\n const after = text.slice(at).replace(/^ /, '');\n setText(insert + after);\n setQuery(null);\n setCaret(insert.length);\n }\n\n // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.\n function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!open) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {\n // Check the word at the caret again before taking the key. If nothing matches now, the list\n // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.\n const now = queryAtCaret(e.currentTarget);\n const found = now === null ? [] : matches(now);\n if (found.length === 0) {\n setQuery(null);\n return;\n }\n e.preventDefault();\n pick(found[now === query ? Math.min(active, found.length - 1) : 0]);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n setQuery(null);\n }\n }\n\n // A real app runs the command here. This one shows it in the thread.\n function send() {\n const value = text.trim();\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: value, command: value.startsWith('/') }]);\n setText('');\n setQuery(null);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\" mono={m.command}>{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"slash-command-list-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team, or type / for commands\"\n value={text}\n onChange={change}\n onSubmit={send}\n onKeyDown={keyDown}\n onSelect={caretMoved}\n // A press on a row keeps focus in the field, so this runs only when focus leaves for good.\n onBlur={() => setQuery(null)}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-activedescendant={open ? optionId(results[active]) : undefined}\n above={\n open ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Commands\" width={400}>\n {results.map((c, i) => (\n <MenuItem\n key={c.name}\n id={optionId(c)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName=\"SquareSlash\"\n // MenuItem has no mono label, so the command is plain text.\n label={`/${c.name}`}\n secondLabel={c.does}\n tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined}\n onClick={() => pick(c)}\n />\n ))}\n </Menu>\n ) : undefined\n }\n />\n </Stack>\n </Center>\n );\n}\n",
3789
+ "uses": [
3790
+ "Center",
3791
+ "Composer",
3792
+ "Heading",
3793
+ "Menu",
3794
+ "MenuItem",
3795
+ "Message",
3796
+ "Paragraph",
3797
+ "Stack",
3798
+ "TimeStamp",
3799
+ "UserImage"
3800
+ ]
3801
+ }
3802
+ ]
3803
+ },
1849
3804
  {
1850
3805
  "id": "success-feedback",
1851
3806
  "title": "Success shows where the person is looking",
@@ -1853,7 +3808,7 @@
1853
3808
  "level": "rule",
1854
3809
  "area": "state",
1855
3810
  "situation": "Something the person did has worked.",
1856
- "answer": "The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.",
3811
+ "answer": "The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When Copy is a menu item, the menu closes, so a toast says 'Message copied.' instead. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.",
1857
3812
  "why": "Feedback belongs where the person is looking. A change they can see needs only a word on the Button, and a result they cannot see needs a short message that names it.",
1858
3813
  "do": [
1859
3814
  "Show `loading` on the Button while a form saves, then 'Saved' for 2 seconds.",
@@ -1869,11 +3824,66 @@
1869
3824
  "Do not build a toast from `Alert`. Use `toast()`.",
1870
3825
  "Do not make the person close a success message."
1871
3826
  ],
1872
- "native": "On Apple there is no toast. Show the result in place.",
1873
- "notBuiltYet": "Scindo on the web has no toast. It shows success in five ways: a 'Saved' Button label, a green caption, an inline Alert, a thank-you that replaces a dialog and a 'Copied' label. The timed ones clear after 1.5, 2, 3 or 4 seconds. Commentify shows toasts through `Alert`, one at a time, and many of them say 'successfully'.",
1874
- "seenIn": [
1875
- "Commentify",
1876
- "Scindo"
3827
+ "native": "On Apple there is no toast. Show the result in place."
3828
+ },
3829
+ {
3830
+ "id": "tag-filter",
3831
+ "title": "Tag filter",
3832
+ "kind": "design",
3833
+ "level": "organism",
3834
+ "area": "menu",
3835
+ "situation": "A person filters a list by a tag, and adds, renames and deletes the tags themselves.",
3836
+ "do": [
3837
+ "Use a row of `Tag` with `variant=\"contained\"` and `size=\"medium\"` in a `Cluster`. Put 'All' first, then each tag. The row wraps.",
3838
+ "Mark the chosen one with `state=\"selected\"`. A clickable `Tag` is a toggle and reports `aria-pressed`.",
3839
+ "Choose Tags over a `SegmentedControl`. A `SegmentedControl` is for a fixed set of two to four, as in the case 'Range switch'. It cannot grow, wrap or hold a field.",
3840
+ "Show one More `IconButton` after the selected tag: `ariaLabel=\"More actions for tag Design\"`. The row gets one extra stop, not one for each tag.",
3841
+ "Open a navigable menu from it: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Tag actions\">` with 'Rename', then a danger 'Delete'.",
3842
+ "Rename in place, as the case 'Rename' says. The row becomes a field with `aria-label=\"Rename tag Design\"`. Enter and a click away save, and Escape cancels.",
3843
+ "Add a tag with an 'Add Tag' Button that turns the row into the same field, with `aria-label=\"New tag name\"`. The new tag is chosen once it is added.",
3844
+ "Show a name that is taken under the field with `error` and `errorText`, and keep what the person typed.",
3845
+ "Confirm Delete in a small Modal, as the case 'Delete confirm' says: 'Cancel' first, then a danger 'Delete'.",
3846
+ "Say where the items go: 'Its 3 items stay in All, with no tag.' Name the tag in a toast when it is gone.",
3847
+ "Put focus on the More button after Rename or Cancel, and on 'Add Tag' after a delete, since the tag and its More button are gone."
3848
+ ],
3849
+ "dont": [
3850
+ "Do not use a `SegmentedControl` for tags that people add and delete.",
3851
+ "Do not delete the items with their tag.",
3852
+ "Do not say 'Are you sure?' in the confirm. Say what is deleted and where the items go.",
3853
+ "Do not add a 'Delete' that has no confirm. A tag may be on many items.",
3854
+ "Do not leave the row on a tag that was just deleted. It goes back to All."
3855
+ ],
3856
+ "native": "On Apple use a horizontal `ScrollView` of toggle `Button`s, with a `.contextMenu` on each tag: Rename, then Delete in the `.destructive` role, which asks in a `confirmationDialog`. On Android use `FilterChip`s in a `LazyRow`.",
3857
+ "options": [
3858
+ {
3859
+ "id": "tags",
3860
+ "title": "Row of toggle Tags",
3861
+ "useWhen": "The tags are made by the person, so the set is not fixed or short.",
3862
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. 'All' is not a tag: it shows every item.\ntype Item = { id: string; title: string; tagId: string | null };\nconst firstTags = [\n { id: 'design', name: 'Design' },\n { id: 'research', name: 'Research' },\n { id: 'ideas', name: 'Ideas' },\n];\nconst firstItems: Item[] = [\n { id: 'i1', title: 'Pricing page teardown', tagId: 'research' },\n { id: 'i2', title: 'Color tokens for dark mode', tagId: 'design' },\n { id: 'i3', title: 'Onboarding checklist patterns', tagId: 'design' },\n { id: 'i4', title: 'Interview notes, March', tagId: 'research' },\n { id: 'i5', title: 'A weekly digest email', tagId: 'ideas' },\n { id: 'i6', title: 'Keyboard shortcut cheat sheet', tagId: null },\n];\n\n// What the field is for: a new tag, or the selected tag's new name.\ntype Editing = 'add' | 'rename' | null;\n\nexport default function TagFilterTags() {\n const [tags, setTags] = useState(firstTags);\n const [items, setItems] = useState(firstItems);\n // null is 'All'.\n const [selected, setSelected] = useState<string | null>('design');\n const [editing, setEditing] = useState<Editing>(null);\n const [draft, setDraft] = useState('');\n const [taken, setTaken] = useState(false);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n // The tag the confirm is about, kept until the Modal is closed, so its text stays while it fades out.\n const [doomed, setDoomed] = useState<{ name: string; count: number }>({ name: '', count: 0 });\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const addButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n const tag = tags.find((t) => t.id === selected);\n const shown = selected === null ? items : items.filter((i) => i.tagId === selected);\n const nameOf = (tagId: string | null) => tags.find((t) => t.id === tagId)?.name ?? 'No tag';\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function startEditing(kind: 'add' | 'rename') {\n ended.current = false;\n setDraft(kind === 'rename' && tag ? tag.name : '');\n setTaken(false);\n setEditing(kind);\n }\n\n // Enter and a click away save. An empty or unchanged name cancels. A name that is taken stays in the field with\n // the error, so what the person typed is not lost. `byKey` is true for Enter, where focus goes back to where it was.\n function finish(byKey: boolean) {\n if (ended.current || !editing) return;\n const name = draft.trim();\n const unchanged = editing === 'rename' && name === tag?.name;\n if (!name || unchanged) return cancel(byKey);\n if (tags.some((t) => !(editing === 'rename' && t.id === selected) && t.name.toLowerCase() === name.toLowerCase())) {\n setTaken(true);\n return;\n }\n ended.current = true;\n // A real app sends the name to the server here and shows it at once.\n if (editing === 'rename') {\n setTags((list) => list.map((t) => (t.id === selected ? { ...t, name } : t)));\n } else {\n const id = `tag-${name.toLowerCase().replace(/\\s+/g, '-')}`;\n setTags((list) => [...list, { id, name }]);\n setSelected(id);\n }\n leave(byKey);\n }\n\n function cancel(byKey: boolean) {\n if (ended.current) return;\n ended.current = true;\n leave(byKey);\n }\n\n function leave(byKey: boolean) {\n const kind = editing;\n setEditing(null);\n setTaken(false);\n if (byKey) focusNext.current = () => (kind === 'rename' ? moreButton.current : addButton.current)?.focus();\n }\n\n function openMenu(anchorEl: HTMLElement) {\n setMenuAnchor(anchorEl);\n setMenuOpen((o) => !o);\n }\n\n // The menu closes on any choice. Its Popover gives focus back to the More button.\n function rename() {\n setMenuOpen(false);\n startEditing('rename');\n }\n\n function askToDelete() {\n setMenuOpen(false);\n if (tag) setDoomed({ name: tag.name, count: items.filter((i) => i.tagId === tag.id).length });\n setConfirming(true);\n }\n\n // 'Cancel' ends the confirm; the More button is still there, so focus goes back to it.\n function keepTag() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n // The items keep their place in 'All' and lose the tag. The tag and its More button are gone, so focus goes to 'Add Tag'.\n function confirmDelete() {\n if (deleting || !tag) return;\n const gone = tag;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setTags((list) => list.filter((t) => t.id !== gone.id));\n setItems((list) => list.map((i) => (i.tagId === gone.id ? { ...i, tagId: null } : i)));\n setSelected(null);\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} tag deleted.` }));\n focusNext.current = () => addButton.current?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reading list</Heading>\n {editing ? (\n // The row of tags becomes the field, as the case 'Rename' says for a name that is on screen. Enter and a click away save, Escape cancels.\n <TextField\n key={editing}\n id=\"tag-filter-name\"\n size=\"small\"\n autoFocus\n aria-label={editing === 'rename' ? `Rename tag ${tag?.name}` : 'New tag name'}\n placeholder={editing === 'add' ? 'Tag name' : undefined}\n value={draft}\n error={taken}\n errorText=\"A tag with this name already exists.\"\n onChange={(e) => {\n setDraft(e.target.value);\n setTaken(false);\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n finish(true);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel(true);\n }\n }}\n onBlur={() => finish(false)}\n />\n ) : (\n // Tags that people add, rename and delete are not a fixed short set, so they are toggle Tags in a row that wraps.\n <Cluster gap=\"small\">\n <Tag variant=\"contained\" size=\"medium\" label=\"All\" state={selected === null ? 'selected' : 'enabled'} onClick={() => setSelected(null)} />\n {tags.map((t) => (\n <Tag key={t.id} variant=\"contained\" size=\"medium\" label={t.name} state={t.id === selected ? 'selected' : 'enabled'} onClick={() => setSelected(t.id)} />\n ))}\n {/* One More button, for the tag that is selected, so the row has one extra stop and not one per tag. */}\n {tag && (\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for tag ${tag.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(e.currentTarget)}\n />\n </Tooltip>\n )}\n <Button ref={addButton} size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Add Tag\" decoIcon=\"Plus\" onClickButton={() => startEditing('add')} />\n </Cluster>\n )}\n {shown.length > 0 ? (\n <TableContainer>\n {shown.map((i) => (\n <TableRow key={i.id}>\n <TableCell>{i.title}</TableCell>\n <TableCell width=\"120px\">{nameOf(i.tagId)}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"Tag\" text={`No items tagged '${tag?.name}'`} secondText=\"Items you tag appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Tag actions\" width={180}>\n <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Rename\" onClick={rename} />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Tag\"\n onClose={keepTag}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepTag} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes the tag '${doomed.name}'.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {doomed.count === 1 ? 'Its 1 item stays in All, with no tag.' : `Its ${doomed.count} items stay in All, with no tag.`}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3863
+ "uses": [
3864
+ "Button",
3865
+ "Center",
3866
+ "Cluster",
3867
+ "EmptyBox",
3868
+ "Heading",
3869
+ "IconButton",
3870
+ "Menu",
3871
+ "MenuItem",
3872
+ "Modal",
3873
+ "Paragraph",
3874
+ "Popover",
3875
+ "Stack",
3876
+ "TableCell",
3877
+ "TableContainer",
3878
+ "TableRow",
3879
+ "Tag",
3880
+ "TextField",
3881
+ "Toaster",
3882
+ "Tooltip",
3883
+ "dismissToast",
3884
+ "toast"
3885
+ ]
3886
+ }
1877
3887
  ]
1878
3888
  },
1879
3889
  {
@@ -1898,11 +3908,6 @@
1898
3908
  "Do not show a failed request as a red caption written by hand. Use an inline error Alert."
1899
3909
  ],
1900
3910
  "native": "On Apple use an `.alert` with a `TextField` in it. Put the action in the `.destructive` role and disable it until the text matches.",
1901
- "notBuiltYet": "Commentify matches its phrase with any case and ignores spaces around it, and labels its Button 'Deleting…' while it runs. Scindo labels its Button 'Deleting...' on the web and on Apple. On the web its Delete Workspace Modal shows a failed request as a red caption written by hand.",
1902
- "seenIn": [
1903
- "Commentify",
1904
- "Scindo"
1905
- ],
1906
3911
  "options": [
1907
3912
  {
1908
3913
  "id": "modal",
@@ -1943,6 +3948,47 @@
1943
3948
  }
1944
3949
  ]
1945
3950
  },
3951
+ {
3952
+ "id": "typing-and-status",
3953
+ "title": "Typing line",
3954
+ "kind": "design",
3955
+ "level": "organism",
3956
+ "area": "chat",
3957
+ "situation": "Other people in the thread are writing a message that has not arrived yet.",
3958
+ "do": [
3959
+ "Show one line just above the Composer, in small secondary text: `<Paragraph size=\"caption\" tone=\"secondary\">`.",
3960
+ "Name one person by first name: 'Ben is typing…'.",
3961
+ "Name two people: 'Ben and Omar are typing…'.",
3962
+ "Name the first person and count the rest when three or more type: 'Ben and 2 others are typing…'.",
3963
+ "End the line with an ellipsis, one character.",
3964
+ "Remove the line a few seconds after the last keystroke, or when the message arrives.",
3965
+ "Leave out the person who is reading.",
3966
+ "Show an agent at work with its progress row, not as typing. The case 'Agent at work' has the pattern.",
3967
+ "Keep the line out of a live region. It changes too often to read aloud."
3968
+ ],
3969
+ "dont": [
3970
+ "Do not say an agent is typing.",
3971
+ "Do not list every name when three or more people type."
3972
+ ],
3973
+ "options": [
3974
+ {
3975
+ "id": "line",
3976
+ "title": "Line above the composer",
3977
+ "useWhen": "The default: one line just above the Composer while someone types.",
3978
+ "source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Omar Reyes', at: new Date('2025-01-15T11:38:00Z'), text: 'Is the launch email going out today?' },\n { id: 'm2', from: me, at: new Date('2025-01-15T11:40:00Z'), text: 'Ben has the final copy. Ben, can you confirm?' },\n];\n\nexport default function TypingAndStatusLine() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Stack gap=\"small\">\n {/* One person typing. Two: 'Ben and Omar are typing…'. Three or more: 'Ben and 2 others are typing…'.\n A real app removes the line a few seconds after the last keystroke. It is not a live region. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Ben is typing…</Paragraph>\n <Composer\n id=\"typing-and-status-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3979
+ "uses": [
3980
+ "Center",
3981
+ "Composer",
3982
+ "Heading",
3983
+ "Message",
3984
+ "Paragraph",
3985
+ "Stack",
3986
+ "TimeStamp",
3987
+ "UserImage"
3988
+ ]
3989
+ }
3990
+ ]
3991
+ },
1946
3992
  {
1947
3993
  "id": "unsaved-changes-guard",
1948
3994
  "title": "Unsaved changes",
@@ -1965,10 +4011,6 @@
1965
4011
  "Do not title the Modal 'Are you sure?'."
1966
4012
  ],
1967
4013
  "native": "On macOS a document window that closes with changes asks with the system alert: 'Save', 'Don't Save' and 'Cancel'. When the product cannot save, use a `confirmationDialog` with 'Discard' in the `.destructive` role and 'Keep Editing' in the `.cancel` role.",
1968
- "notBuiltYet": "Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.",
1969
- "seenIn": [
1970
- "Scindo"
1971
- ],
1972
4014
  "options": [
1973
4015
  {
1974
4016
  "id": "save-or-discard",
@@ -2030,11 +4072,6 @@
2030
4072
  "Do not build the overlay by hand. Use `Modal`, which closes on Escape."
2031
4073
  ],
2032
4074
  "native": "On Apple show the notice in place, with an Upgrade Button only for admins. It opens the plan sheet in the app, never a link to a web page.",
2033
- "notBuiltYet": "Scindo's upgrade prompt on the web is an overlay built by hand that does not close on Escape, is titled 'Upgrade Required' and shows Upgrade to everyone. Commentify's upgrade Modal labels its Buttons 'Maybe Later' and 'Upgrade'.",
2034
- "seenIn": [
2035
- "Commentify",
2036
- "Scindo"
2037
- ],
2038
4075
  "options": [
2039
4076
  {
2040
4077
  "id": "modal",