oneslash-design-system 2.15.0 → 2.17.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 (331) hide show
  1. package/README.md +6 -1
  2. package/dist/DESIGN.md +100 -73
  3. package/dist/cases/accept-invite/signed-in.d.ts +1 -0
  4. package/dist/cases/accept-invite/signed-in.jsx +57 -0
  5. package/dist/cases/accept-invite/signed-out.d.ts +1 -0
  6. package/dist/cases/accept-invite/signed-out.jsx +33 -0
  7. package/dist/cases/accept-invite.md +161 -0
  8. package/dist/cases/agent-asks-before-risky-action.md +1 -1
  9. package/dist/cases/agent-cancels-when-unanswered.md +1 -1
  10. package/dist/cases/agent-options/cards.d.ts +1 -0
  11. package/dist/cases/agent-options/cards.jsx +91 -0
  12. package/dist/cases/agent-options.md +168 -0
  13. package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
  14. package/dist/cases/agent-pending-reply/steps.jsx +149 -0
  15. package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
  16. package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
  17. package/dist/cases/agent-pending-reply.md +432 -0
  18. package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
  19. package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
  20. package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
  21. package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
  22. package/dist/cases/agent-plan-proposal.md +656 -0
  23. package/dist/cases/agent-question/choices.d.ts +1 -0
  24. package/dist/cases/agent-question/choices.jsx +132 -0
  25. package/dist/cases/agent-question/free-text.d.ts +1 -0
  26. package/dist/cases/agent-question/free-text.jsx +81 -0
  27. package/dist/cases/agent-question.md +338 -0
  28. package/dist/cases/agent-shows-sources.md +2 -2
  29. package/dist/cases/artifact-card/card.d.ts +1 -0
  30. package/dist/cases/artifact-card/card.jsx +45 -0
  31. package/dist/cases/artifact-card.md +103 -0
  32. package/dist/cases/auth-gate-loading/spinner-with-line.d.ts +1 -0
  33. package/dist/cases/auth-gate-loading/spinner-with-line.jsx +10 -0
  34. package/dist/cases/auth-gate-loading/spinner.d.ts +1 -0
  35. package/dist/cases/auth-gate-loading/spinner.jsx +10 -0
  36. package/dist/cases/auth-gate-loading.md +70 -0
  37. package/dist/cases/check-your-email/alert-on-login.d.ts +1 -0
  38. package/dist/cases/check-your-email/alert-on-login.jsx +78 -0
  39. package/dist/cases/check-your-email/page.d.ts +1 -0
  40. package/dist/cases/check-your-email/page.jsx +49 -0
  41. package/dist/cases/check-your-email.md +184 -0
  42. package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
  43. package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
  44. package/dist/cases/composer-limit/notice.d.ts +1 -0
  45. package/dist/cases/composer-limit/notice.jsx +84 -0
  46. package/dist/cases/composer-limit.md +286 -0
  47. package/dist/cases/confirm-destructive-action/inline.d.ts +1 -0
  48. package/dist/cases/confirm-destructive-action/inline.jsx +69 -0
  49. package/dist/cases/confirm-destructive-action/modal.d.ts +1 -0
  50. package/dist/cases/confirm-destructive-action/modal.jsx +66 -0
  51. package/dist/cases/confirm-destructive-action.md +211 -0
  52. package/dist/cases/confirm-dialogs.md +36 -0
  53. package/dist/cases/conversation-starters/chips.d.ts +1 -0
  54. package/dist/cases/conversation-starters/chips.jsx +69 -0
  55. package/dist/cases/conversation-starters/none.d.ts +1 -0
  56. package/dist/cases/conversation-starters/none.jsx +45 -0
  57. package/dist/cases/conversation-starters.md +208 -0
  58. package/dist/cases/create-modal/quick.d.ts +1 -0
  59. package/dist/cases/create-modal/quick.jsx +80 -0
  60. package/dist/cases/create-modal/with-settings.d.ts +1 -0
  61. package/dist/cases/create-modal/with-settings.jsx +99 -0
  62. package/dist/cases/create-modal.md +244 -0
  63. package/dist/cases/device-login/popup.d.ts +1 -0
  64. package/dist/cases/device-login/popup.jsx +14 -0
  65. package/dist/cases/device-login/provider-first.d.ts +1 -0
  66. package/dist/cases/device-login/provider-first.jsx +98 -0
  67. package/dist/cases/device-login.md +171 -0
  68. package/dist/cases/email-confirmed/alert-on-login.d.ts +1 -0
  69. package/dist/cases/email-confirmed/alert-on-login.jsx +78 -0
  70. package/dist/cases/email-confirmed/page.d.ts +1 -0
  71. package/dist/cases/email-confirmed/page.jsx +21 -0
  72. package/dist/cases/email-confirmed.md +151 -0
  73. package/dist/cases/empty-list/region.d.ts +1 -0
  74. package/dist/cases/empty-list/region.jsx +13 -0
  75. package/dist/cases/empty-list/section.d.ts +1 -0
  76. package/dist/cases/empty-list/section.jsx +17 -0
  77. package/dist/cases/empty-list.md +77 -0
  78. package/dist/cases/empty-lists.md +35 -0
  79. package/dist/cases/empty-not-set-up/action.d.ts +1 -0
  80. package/dist/cases/empty-not-set-up/action.jsx +16 -0
  81. package/dist/cases/empty-not-set-up/pointer.d.ts +1 -0
  82. package/dist/cases/empty-not-set-up/pointer.jsx +13 -0
  83. package/dist/cases/empty-not-set-up.md +88 -0
  84. package/dist/cases/empty-search/clear-search.d.ts +1 -0
  85. package/dist/cases/empty-search/clear-search.jsx +29 -0
  86. package/dist/cases/empty-search.md +77 -0
  87. package/dist/cases/error-page/full-page.d.ts +1 -0
  88. package/dist/cases/error-page/full-page.jsx +19 -0
  89. package/dist/cases/error-page/in-shell.d.ts +1 -0
  90. package/dist/cases/error-page/in-shell.jsx +39 -0
  91. package/dist/cases/error-page.md +107 -0
  92. package/dist/cases/feedback-form/modal.d.ts +1 -0
  93. package/dist/cases/feedback-form/modal.jsx +89 -0
  94. package/dist/cases/feedback-form.md +139 -0
  95. package/dist/cases/forgot-password/in-place.d.ts +1 -0
  96. package/dist/cases/forgot-password/in-place.jsx +155 -0
  97. package/dist/cases/forgot-password/own-page.d.ts +1 -0
  98. package/dist/cases/forgot-password/own-page.jsx +99 -0
  99. package/dist/cases/forgot-password.md +328 -0
  100. package/dist/cases/form-errors.md +32 -0
  101. package/dist/cases/import-checklist/modal.d.ts +1 -0
  102. package/dist/cases/import-checklist/modal.jsx +125 -0
  103. package/dist/cases/import-checklist.md +188 -0
  104. package/dist/cases/inline-form-feedback/button-label.d.ts +1 -0
  105. package/dist/cases/inline-form-feedback/button-label.jsx +54 -0
  106. package/dist/cases/inline-form-feedback/inline-alert.d.ts +1 -0
  107. package/dist/cases/inline-form-feedback/inline-alert.jsx +49 -0
  108. package/dist/cases/inline-form-feedback/toast.d.ts +1 -0
  109. package/dist/cases/inline-form-feedback/toast.jsx +66 -0
  110. package/dist/cases/inline-form-feedback.md +237 -0
  111. package/dist/cases/invite-member/by-email.d.ts +1 -0
  112. package/dist/cases/invite-member/by-email.jsx +98 -0
  113. package/dist/cases/invite-member/by-link.d.ts +1 -0
  114. package/dist/cases/invite-member/by-link.jsx +122 -0
  115. package/dist/cases/invite-member.md +321 -0
  116. package/dist/cases/load-failure/inline.d.ts +1 -0
  117. package/dist/cases/load-failure/inline.jsx +52 -0
  118. package/dist/cases/load-failure/region.d.ts +1 -0
  119. package/dist/cases/load-failure/region.jsx +34 -0
  120. package/dist/cases/load-failure.md +155 -0
  121. package/dist/cases/log-out-confirm/modal.d.ts +1 -0
  122. package/dist/cases/log-out-confirm/modal.jsx +57 -0
  123. package/dist/cases/log-out-confirm.md +106 -0
  124. package/dist/cases/login-page/centered.jsx +10 -7
  125. package/dist/cases/login-page/email-only.jsx +11 -8
  126. package/dist/cases/login-page/provider-first.jsx +12 -9
  127. package/dist/cases/login-page/split.jsx +11 -8
  128. package/dist/cases/login-page.md +58 -41
  129. package/dist/cases/mention-list/in-composer.d.ts +1 -0
  130. package/dist/cases/mention-list/in-composer.jsx +169 -0
  131. package/dist/cases/mention-list.md +252 -0
  132. package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
  133. package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
  134. package/dist/cases/message-actions/menu.d.ts +1 -0
  135. package/dist/cases/message-actions/menu.jsx +258 -0
  136. package/dist/cases/message-actions.md +651 -0
  137. package/dist/cases/message-attachments/in-composer.d.ts +1 -0
  138. package/dist/cases/message-attachments/in-composer.jsx +134 -0
  139. package/dist/cases/message-attachments/in-message.d.ts +1 -0
  140. package/dist/cases/message-attachments/in-message.jsx +46 -0
  141. package/dist/cases/message-attachments.md +310 -0
  142. package/dist/cases/message-composer/plain.d.ts +1 -0
  143. package/dist/cases/message-composer/plain.jsx +57 -0
  144. package/dist/cases/message-composer/with-tools.d.ts +1 -0
  145. package/dist/cases/message-composer/with-tools.jsx +182 -0
  146. package/dist/cases/message-composer.md +356 -0
  147. package/dist/cases/message-edit/in-place.d.ts +1 -0
  148. package/dist/cases/message-edit/in-place.jsx +99 -0
  149. package/dist/cases/message-edit.md +179 -0
  150. package/dist/cases/message-reactions/chips.d.ts +1 -0
  151. package/dist/cases/message-reactions/chips.jsx +118 -0
  152. package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
  153. package/dist/cases/message-reactions/quick-pick.jsx +155 -0
  154. package/dist/cases/message-reactions.md +371 -0
  155. package/dist/cases/message-row/grouped.d.ts +1 -0
  156. package/dist/cases/message-row/grouped.jsx +56 -0
  157. package/dist/cases/message-row/person-and-agent.d.ts +1 -0
  158. package/dist/cases/message-row/person-and-agent.jsx +41 -0
  159. package/dist/cases/message-row.md +189 -0
  160. package/dist/cases/not-found-page/full-page.d.ts +1 -0
  161. package/dist/cases/not-found-page/full-page.jsx +16 -0
  162. package/dist/cases/not-found-page/in-shell.d.ts +1 -0
  163. package/dist/cases/not-found-page/in-shell.jsx +36 -0
  164. package/dist/cases/not-found-page.md +98 -0
  165. package/dist/cases/oauth-consent/simple.d.ts +1 -0
  166. package/dist/cases/oauth-consent/simple.jsx +73 -0
  167. package/dist/cases/oauth-consent/with-scope.d.ts +1 -0
  168. package/dist/cases/oauth-consent/with-scope.jsx +89 -0
  169. package/dist/cases/oauth-consent.md +233 -0
  170. package/dist/cases/rename/inline.d.ts +1 -0
  171. package/dist/cases/rename/inline.jsx +58 -0
  172. package/dist/cases/rename/modal.d.ts +1 -0
  173. package/dist/cases/rename/modal.jsx +70 -0
  174. package/dist/cases/rename.md +205 -0
  175. package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
  176. package/dist/cases/reply-feedback/thumbs.jsx +191 -0
  177. package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
  178. package/dist/cases/reply-feedback/with-reason.jsx +221 -0
  179. package/dist/cases/reply-feedback.md +552 -0
  180. package/dist/cases/reply-sources/cards.d.ts +1 -0
  181. package/dist/cases/reply-sources/cards.jsx +83 -0
  182. package/dist/cases/reply-sources/tag-only.d.ts +1 -0
  183. package/dist/cases/reply-sources/tag-only.jsx +45 -0
  184. package/dist/cases/reply-sources.md +247 -0
  185. package/dist/cases/route-loading/full-screen.d.ts +1 -0
  186. package/dist/cases/route-loading/full-screen.jsx +8 -0
  187. package/dist/cases/route-loading/region.d.ts +1 -0
  188. package/dist/cases/route-loading/region.jsx +26 -0
  189. package/dist/cases/route-loading.md +84 -0
  190. package/dist/cases/set-new-password/form.d.ts +1 -0
  191. package/dist/cases/set-new-password/form.jsx +130 -0
  192. package/dist/cases/set-new-password/invalid-link.d.ts +1 -0
  193. package/dist/cases/set-new-password/invalid-link.jsx +50 -0
  194. package/dist/cases/set-new-password.md +247 -0
  195. package/dist/cases/sign-up-page/centered.d.ts +1 -0
  196. package/dist/cases/sign-up-page/centered.jsx +124 -0
  197. package/dist/cases/sign-up-page/provider-first.d.ts +1 -0
  198. package/dist/cases/sign-up-page/provider-first.jsx +124 -0
  199. package/dist/cases/sign-up-page/split.d.ts +1 -0
  200. package/dist/cases/sign-up-page/split.jsx +134 -0
  201. package/dist/cases/sign-up-page.md +478 -0
  202. package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
  203. package/dist/cases/slash-command-list/in-composer.jsx +162 -0
  204. package/dist/cases/slash-command-list.md +247 -0
  205. package/dist/cases/success-feedback.md +35 -0
  206. package/dist/cases/type-to-confirm/inline.d.ts +1 -0
  207. package/dist/cases/type-to-confirm/inline.jsx +69 -0
  208. package/dist/cases/type-to-confirm/modal.d.ts +1 -0
  209. package/dist/cases/type-to-confirm/modal.jsx +73 -0
  210. package/dist/cases/type-to-confirm.md +222 -0
  211. package/dist/cases/typing-and-status/line.d.ts +1 -0
  212. package/dist/cases/typing-and-status/line.jsx +50 -0
  213. package/dist/cases/typing-and-status.md +96 -0
  214. package/dist/cases/unsaved-changes-guard/discard.d.ts +1 -0
  215. package/dist/cases/unsaved-changes-guard/discard.jsx +81 -0
  216. package/dist/cases/unsaved-changes-guard/save-or-discard.d.ts +1 -0
  217. package/dist/cases/unsaved-changes-guard/save-or-discard.jsx +85 -0
  218. package/dist/cases/unsaved-changes-guard.md +239 -0
  219. package/dist/cases/upgrade-prompt/inline.d.ts +1 -0
  220. package/dist/cases/upgrade-prompt/inline.jsx +52 -0
  221. package/dist/cases/upgrade-prompt/modal.d.ts +1 -0
  222. package/dist/cases/upgrade-prompt/modal.jsx +43 -0
  223. package/dist/cases/upgrade-prompt.md +174 -0
  224. package/dist/cases.json +3138 -59
  225. package/dist/components/alert.d.ts +3 -1
  226. package/dist/components/alert.jsx +6 -4
  227. package/dist/components/button.d.ts +3 -2
  228. package/dist/components/button.jsx +9 -7
  229. package/dist/components/composer.d.ts +74 -0
  230. package/dist/components/composer.jsx +122 -0
  231. package/dist/components/emptyBox.d.ts +6 -1
  232. package/dist/components/emptyBox.jsx +4 -2
  233. package/dist/components/fileChip.d.ts +33 -0
  234. package/dist/components/fileChip.jsx +61 -0
  235. package/dist/components/heading.d.ts +2 -2
  236. package/dist/components/iconButton.d.ts +3 -3
  237. package/dist/components/iconButton.jsx +9 -7
  238. package/dist/components/layout.d.ts +7 -1
  239. package/dist/components/layout.jsx +5 -2
  240. package/dist/components/loadingScreen.d.ts +5 -1
  241. package/dist/components/loadingScreen.jsx +4 -2
  242. package/dist/components/menu.d.ts +21 -0
  243. package/dist/components/menu.jsx +27 -3
  244. package/dist/components/menuItem.d.ts +9 -1
  245. package/dist/components/menuItem.jsx +5 -4
  246. package/dist/components/message.d.ts +28 -0
  247. package/dist/components/message.jsx +25 -0
  248. package/dist/components/modal.d.ts +2 -1
  249. package/dist/components/modal.jsx +20 -8
  250. package/dist/components/paragraph.d.ts +3 -1
  251. package/dist/components/paragraph.jsx +2 -2
  252. package/dist/components/popover.d.ts +7 -1
  253. package/dist/components/popover.jsx +35 -9
  254. package/dist/components/radioGroup.d.ts +9 -1
  255. package/dist/components/radioGroup.jsx +20 -9
  256. package/dist/components/select.d.ts +2 -1
  257. package/dist/components/select.jsx +4 -2
  258. package/dist/components/sourceCard.d.ts +23 -0
  259. package/dist/components/sourceCard.jsx +56 -0
  260. package/dist/components/stepList.d.ts +17 -0
  261. package/dist/components/stepList.jsx +79 -0
  262. package/dist/components/tab.jsx +3 -2
  263. package/dist/components/tabsContainer.d.ts +4 -1
  264. package/dist/components/tabsContainer.jsx +7 -3
  265. package/dist/components/tag.d.ts +9 -1
  266. package/dist/components/tag.jsx +6 -4
  267. package/dist/components/textField.d.ts +5 -1
  268. package/dist/components/textField.jsx +7 -3
  269. package/dist/components/textarea.jsx +3 -18
  270. package/dist/components/toaster.d.ts +12 -0
  271. package/dist/components/toaster.jsx +103 -0
  272. package/dist/components/userImage.d.ts +9 -1
  273. package/dist/components/userImage.jsx +10 -3
  274. package/dist/internal/alert.d.ts +4 -0
  275. package/dist/internal/alert.js +6 -0
  276. package/dist/internal/autoGrow.d.ts +11 -0
  277. package/dist/internal/autoGrow.js +28 -0
  278. package/dist/internal/composer.d.ts +16 -0
  279. package/dist/internal/composer.js +18 -0
  280. package/dist/internal/menu.d.ts +6 -0
  281. package/dist/internal/menu.js +31 -0
  282. package/dist/internal/modal.d.ts +2 -0
  283. package/dist/internal/modal.js +21 -0
  284. package/dist/internal/toaster.d.ts +19 -0
  285. package/dist/internal/toaster.js +50 -0
  286. package/dist/native-mapping.json +38 -1
  287. package/dist/stories/Alert.stories.d.ts +1 -0
  288. package/dist/stories/Alert.stories.jsx +16 -0
  289. package/dist/stories/Button.stories.d.ts +1 -0
  290. package/dist/stories/Button.stories.jsx +17 -1
  291. package/dist/stories/Cases.generated.stories.d.ts +82 -0
  292. package/dist/stories/Cases.generated.stories.jsx +164 -0
  293. package/dist/stories/Composer.stories.d.ts +23 -0
  294. package/dist/stories/Composer.stories.jsx +121 -0
  295. package/dist/stories/EmptyBox.stories.d.ts +2 -0
  296. package/dist/stories/EmptyBox.stories.jsx +16 -0
  297. package/dist/stories/FileChip.stories.d.ts +7 -0
  298. package/dist/stories/FileChip.stories.jsx +35 -0
  299. package/dist/stories/Heading.stories.d.ts +6 -0
  300. package/dist/stories/Heading.stories.jsx +10 -0
  301. package/dist/stories/IconButton.stories.d.ts +1 -0
  302. package/dist/stories/IconButton.stories.jsx +18 -1
  303. package/dist/stories/LoadingScreen.stories.d.ts +1 -0
  304. package/dist/stories/LoadingScreen.stories.jsx +8 -0
  305. package/dist/stories/Menu.stories.d.ts +4 -0
  306. package/dist/stories/Menu.stories.jsx +46 -1
  307. package/dist/stories/MenuItem.stories.d.ts +1 -0
  308. package/dist/stories/MenuItem.stories.jsx +8 -0
  309. package/dist/stories/Message.stories.d.ts +10 -0
  310. package/dist/stories/Message.stories.jsx +77 -0
  311. package/dist/stories/Modal.stories.d.ts +2 -0
  312. package/dist/stories/Modal.stories.jsx +36 -0
  313. package/dist/stories/PageComponents.stories.d.ts +1 -0
  314. package/dist/stories/PageComponents.stories.jsx +21 -0
  315. package/dist/stories/RadioGroup.stories.d.ts +3 -0
  316. package/dist/stories/RadioGroup.stories.jsx +54 -1
  317. package/dist/stories/Select.stories.d.ts +1 -0
  318. package/dist/stories/Select.stories.jsx +14 -0
  319. package/dist/stories/SourceCard.stories.d.ts +8 -0
  320. package/dist/stories/SourceCard.stories.jsx +33 -0
  321. package/dist/stories/StepList.stories.d.ts +8 -0
  322. package/dist/stories/StepList.stories.jsx +35 -0
  323. package/dist/stories/TabsContainer.stories.d.ts +1 -0
  324. package/dist/stories/TabsContainer.stories.jsx +12 -0
  325. package/dist/stories/TextField.stories.d.ts +2 -0
  326. package/dist/stories/TextField.stories.jsx +22 -0
  327. package/dist/stories/Toaster.stories.d.ts +6 -0
  328. package/dist/stories/Toaster.stories.jsx +29 -0
  329. package/dist/stories/UserImage.stories.d.ts +2 -0
  330. package/dist/stories/UserImage.stories.jsx +19 -0
  331. package/package.json +4 -3
@@ -0,0 +1,478 @@
1
+ # Sign-up page
2
+
3
+ A person who has no account yet opens the product and wants one.
4
+
5
+ **Not built yet:** 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.
6
+
7
+ ## Do
8
+
9
+ - Ask only for what the account needs: name, email and password.
10
+ - Say the product's password rule before the person breaks it, such as 'Use at least 8 characters.'
11
+ - Put the rule in the password field's `helperText`, so it is tied to the field.
12
+ - Check the rule on the server too, and show its refusal under the field.
13
+ - Show a problem with one field under that field.
14
+ - Show a failed request in an inline Alert above the fields.
15
+ - Show the loading state on the submit Button while creating the account, and keep the form in place.
16
+ - Show the check-your-email view in place of the form when the email must be confirmed, for every address, even one that already has an account. Tell that person by email that they can log in.
17
+ - Keep the submit Button loading until the check-your-email view shows.
18
+ - Name the provider on its button: 'Continue with Google'.
19
+ - Link or tab to login for people who already have an account.
20
+
21
+ ## Don't
22
+
23
+ - Do not ask for anything the account can do without, such as a username or the password twice.
24
+ - Do not clear the email field after a failed attempt.
25
+ - Do not replace the form with a spinner while creating the account.
26
+ - Do not say on the page whether an address already has an account.
27
+
28
+ ## Option: Centered column
29
+
30
+ Use when: The product has one way in, and most people sign up with email and a password.
31
+
32
+ Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Form`, `Heading`, `Icon`, `Image`, `Line`, `Paragraph`, `Stack`, `Tab`, `TabsContainer`, `TextField`
33
+
34
+ ```tsx
35
+ 'use client';
36
+ import { useEffect, useRef, useState } from 'react';
37
+ import { Mail } from 'lucide-react';
38
+ import Image from 'oneslash-design-system/components/image';
39
+ import TabsContainer from 'oneslash-design-system/components/tabsContainer';
40
+ import Tab from 'oneslash-design-system/components/tab';
41
+ import Form from 'oneslash-design-system/components/form';
42
+ import Alert from 'oneslash-design-system/components/alert';
43
+ import TextField from 'oneslash-design-system/components/textField';
44
+ import Paragraph from 'oneslash-design-system/components/paragraph';
45
+ import Heading from 'oneslash-design-system/components/heading';
46
+ import Icon from 'oneslash-design-system/components/icon';
47
+ import Button from 'oneslash-design-system/components/button';
48
+ import Line from 'oneslash-design-system/components/line';
49
+ import BrandIcon from 'oneslash-design-system/components/brandIcon';
50
+ import { Center, Stack } from 'oneslash-design-system/components/layout';
51
+
52
+ // The product's mark. A real app passes its own file.
53
+ const productMark =
54
+ "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";
55
+
56
+ // A real app passes the router from its framework, such as Next's useRouter().
57
+ const router = { push: (url: string) => console.info(`Go to ${url}`) };
58
+
59
+ // A small check: some text, an @, then some text.
60
+ function looksLikeEmail(value: string) {
61
+ return /^[^@\s]+@[^@\s]+$/.test(value);
62
+ }
63
+
64
+ export default function SignUpCentered() {
65
+ const [name, setName] = useState('Ada Lovelace');
66
+ const [email, setEmail] = useState('ada@example.com');
67
+ const [password, setPassword] = useState('');
68
+ const [error, setError] = useState('');
69
+ const [nameError, setNameError] = useState('');
70
+ const [emailError, setEmailError] = useState('');
71
+ const [passwordError, setPasswordError] = useState('');
72
+ const [loading, setLoading] = useState(false);
73
+ // The address the link went to. Set once the account request ends, which shows the check-your-email view.
74
+ const [sentTo, setSentTo] = useState('');
75
+ const [resending, setResending] = useState(false);
76
+ const [resent, setResent] = useState(false);
77
+ const timer = useRef<ReturnType<typeof setTimeout>>();
78
+
79
+ // Stops the request if the example goes away before it ends.
80
+ useEffect(() => () => clearTimeout(timer.current), []);
81
+
82
+ // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
83
+ useEffect(() => {
84
+ if (!resent) return;
85
+ const timer = setTimeout(() => setResent(false), 2000);
86
+ return () => clearTimeout(timer);
87
+ }, [resent]);
88
+
89
+ function handleSubmit() {
90
+ if (loading) return;
91
+ setError('');
92
+ setNameError('');
93
+ setEmailError('');
94
+ setPasswordError('');
95
+ if (!name.trim()) {
96
+ setNameError('Enter your name.');
97
+ return;
98
+ }
99
+ if (!email.trim()) {
100
+ setEmailError('Enter your email.');
101
+ return;
102
+ }
103
+ if (!looksLikeEmail(email.trim())) {
104
+ setEmailError('Enter an email address, like name@example.com.');
105
+ return;
106
+ }
107
+ if (password.length < 8) {
108
+ setPasswordError('Use at least 8 characters.');
109
+ return;
110
+ }
111
+ setLoading(true);
112
+ const address = email.trim();
113
+ // Stands in for the request to the server.
114
+ // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'
115
+ timer.current = setTimeout(() => {
116
+ // Every address goes on to the same view, so the page never says whether it has an account.
117
+ // The Button stays loading until the view changes.
118
+ setLoading(false);
119
+ setSentTo(address);
120
+ }, 1200);
121
+ }
122
+
123
+ function handleSendAgain() {
124
+ // One click sends one email: clicks while it sends or reads 'Sent' do nothing.
125
+ if (resending || resent) return;
126
+ setResending(true);
127
+ // Stands in for the request to the server.
128
+ // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'
129
+ timer.current = setTimeout(() => {
130
+ setResending(false);
131
+ setResent(true);
132
+ }, 1200);
133
+ }
134
+
135
+ // The same view as the 'Check your email' case, in place of the form.
136
+ if (sentTo) {
137
+ return (
138
+ <Center fill>
139
+ <Icon icon={Mail} size="large" color="secondary" />
140
+ <Stack gap="medium">
141
+ <Heading level={1} size="h5">Check your email</Heading>
142
+ <Paragraph tone="secondary" measure="none">We sent a link to {sentTo}. Open it to continue.</Paragraph>
143
+ </Stack>
144
+ <Stack gap="large">
145
+ <Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />
146
+ <Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={() => router.push('/login')} />
147
+ </Stack>
148
+ </Center>
149
+ );
150
+ }
151
+
152
+ return (
153
+ <Center fill>
154
+ <Image src={productMark} alt="Acme" width={40} height={40} />
155
+ <TabsContainer fill>
156
+ <Tab label="Log In" isSelected={false} href="/login" router={router} onClickTab={() => {}} />
157
+ <Tab label="Sign Up" isSelected onClickTab={() => {}} />
158
+ </TabsContainer>
159
+ <Form aria-label="Sign up" onSubmit={handleSubmit}>
160
+ {error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
161
+ <TextField id="sign-up-page-centered-name" label="Name" autoComplete="name" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />
162
+ <TextField id="sign-up-page-centered-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
163
+ <TextField id="sign-up-page-centered-password" label="Password" type="password" autoComplete="new-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText="Use at least 8 characters." onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
164
+ <Button size="medium" type="primary" state="enabled" label="Sign Up" htmlType="submit" loading={loading} />
165
+ </Form>
166
+ <Line label="or" />
167
+ <Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
168
+ </Center>
169
+ );
170
+ }
171
+ ```
172
+
173
+ ## Option: Brand beside the form
174
+
175
+ Use when: People arrive from an ad or an invite and need one line on what the product is.
176
+
177
+ Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Cluster`, `Form`, `Heading`, `Icon`, `Image`, `Line`, `Link`, `Paragraph`, `Split`, `Stack`, `TextField`
178
+
179
+ ```tsx
180
+ 'use client';
181
+ import { useEffect, useRef, useState } from 'react';
182
+ import { Mail } from 'lucide-react';
183
+ import Image from 'oneslash-design-system/components/image';
184
+ import Heading from 'oneslash-design-system/components/heading';
185
+ import Paragraph from 'oneslash-design-system/components/paragraph';
186
+ import Form from 'oneslash-design-system/components/form';
187
+ import Alert from 'oneslash-design-system/components/alert';
188
+ import TextField from 'oneslash-design-system/components/textField';
189
+ import Icon from 'oneslash-design-system/components/icon';
190
+ import Button from 'oneslash-design-system/components/button';
191
+ import Line from 'oneslash-design-system/components/line';
192
+ import Link from 'oneslash-design-system/components/link';
193
+ import BrandIcon from 'oneslash-design-system/components/brandIcon';
194
+ import { Center, Cluster, Split, Stack } from 'oneslash-design-system/components/layout';
195
+
196
+ // The product's mark. A real app passes its own file.
197
+ const productMark =
198
+ "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";
199
+
200
+ // A real app passes the router from its framework, such as Next's useRouter().
201
+ const router = { push: (url: string) => console.info(`Go to ${url}`) };
202
+
203
+ // A small check: some text, an @, then some text.
204
+ function looksLikeEmail(value: string) {
205
+ return /^[^@\s]+@[^@\s]+$/.test(value);
206
+ }
207
+
208
+ export default function SignUpSplit() {
209
+ const [name, setName] = useState('Ada Lovelace');
210
+ const [email, setEmail] = useState('ada@example.com');
211
+ const [password, setPassword] = useState('');
212
+ const [error, setError] = useState('');
213
+ const [nameError, setNameError] = useState('');
214
+ const [emailError, setEmailError] = useState('');
215
+ const [passwordError, setPasswordError] = useState('');
216
+ const [loading, setLoading] = useState(false);
217
+ // The address the link went to. Set once the account request ends, which shows the check-your-email view.
218
+ const [sentTo, setSentTo] = useState('');
219
+ const [resending, setResending] = useState(false);
220
+ const [resent, setResent] = useState(false);
221
+ const timer = useRef<ReturnType<typeof setTimeout>>();
222
+
223
+ // Stops the request if the example goes away before it ends.
224
+ useEffect(() => () => clearTimeout(timer.current), []);
225
+
226
+ // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
227
+ useEffect(() => {
228
+ if (!resent) return;
229
+ const timer = setTimeout(() => setResent(false), 2000);
230
+ return () => clearTimeout(timer);
231
+ }, [resent]);
232
+
233
+ const aside = (
234
+ <Stack gap="large">
235
+ <Image src={productMark} alt="Acme" width={40} height={40} />
236
+ <Heading level={2} size="h4">Plan the week with your whole team.</Heading>
237
+ <Paragraph tone="secondary" measure="lede">
238
+ Acme keeps tasks, notes and decisions in one place.
239
+ </Paragraph>
240
+ </Stack>
241
+ );
242
+
243
+ function handleSubmit() {
244
+ if (loading) return;
245
+ setError('');
246
+ setNameError('');
247
+ setEmailError('');
248
+ setPasswordError('');
249
+ if (!name.trim()) {
250
+ setNameError('Enter your name.');
251
+ return;
252
+ }
253
+ if (!email.trim()) {
254
+ setEmailError('Enter your email.');
255
+ return;
256
+ }
257
+ if (!looksLikeEmail(email.trim())) {
258
+ setEmailError('Enter an email address, like name@example.com.');
259
+ return;
260
+ }
261
+ if (password.length < 8) {
262
+ setPasswordError('Use at least 8 characters.');
263
+ return;
264
+ }
265
+ setLoading(true);
266
+ const address = email.trim();
267
+ // Stands in for the request to the server.
268
+ // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'
269
+ timer.current = setTimeout(() => {
270
+ // Every address goes on to the same view, so the page never says whether it has an account.
271
+ // The Button stays loading until the view changes.
272
+ setLoading(false);
273
+ setSentTo(address);
274
+ }, 1200);
275
+ }
276
+
277
+ function handleSendAgain() {
278
+ // One click sends one email: clicks while it sends or reads 'Sent' do nothing.
279
+ if (resending || resent) return;
280
+ setResending(true);
281
+ // Stands in for the request to the server.
282
+ // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'
283
+ timer.current = setTimeout(() => {
284
+ setResending(false);
285
+ setResent(true);
286
+ }, 1200);
287
+ }
288
+
289
+ // The same view as the 'Check your email' case, in place of the form.
290
+ if (sentTo) {
291
+ return (
292
+ <Split fill aside={aside}>
293
+ <Center fill>
294
+ <Icon icon={Mail} size="large" color="secondary" />
295
+ <Stack gap="medium">
296
+ <Heading level={1} size="h5">Check your email</Heading>
297
+ <Paragraph tone="secondary" measure="none">We sent a link to {sentTo}. Open it to continue.</Paragraph>
298
+ </Stack>
299
+ <Stack gap="large">
300
+ <Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />
301
+ <Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={() => router.push('/login')} />
302
+ </Stack>
303
+ </Center>
304
+ </Split>
305
+ );
306
+ }
307
+
308
+ return (
309
+ <Split fill aside={aside}>
310
+ <Center fill>
311
+ <Heading level={1} size="h5">Create your Acme account</Heading>
312
+ <Form aria-label="Sign up" onSubmit={handleSubmit}>
313
+ {error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
314
+ <TextField id="sign-up-page-split-name" label="Name" autoComplete="name" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />
315
+ <TextField id="sign-up-page-split-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
316
+ <TextField id="sign-up-page-split-password" label="Password" type="password" autoComplete="new-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText="Use at least 8 characters." onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
317
+ <Button size="medium" type="primary" state="enabled" label="Sign Up" htmlType="submit" loading={loading} />
318
+ </Form>
319
+ <Line label="or" />
320
+ <Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
321
+ <Cluster gap="small">
322
+ <Paragraph tone="secondary" size="body2" measure="none">Already have an account?</Paragraph>
323
+ <Link href="/login" size="body2">Log in</Link>
324
+ </Cluster>
325
+ </Center>
326
+ </Split>
327
+ );
328
+ }
329
+ ```
330
+
331
+ ## Option: Provider first
332
+
333
+ Use when: Most people sign up with Google, GitHub or Apple; email is the fallback.
334
+
335
+ Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Cluster`, `Form`, `Heading`, `Icon`, `Line`, `Link`, `Paragraph`, `Stack`, `TextField`
336
+
337
+ ```tsx
338
+ 'use client';
339
+ import { useEffect, useRef, useState } from 'react';
340
+ import { Mail } from 'lucide-react';
341
+ import Heading from 'oneslash-design-system/components/heading';
342
+ import Paragraph from 'oneslash-design-system/components/paragraph';
343
+ import Form from 'oneslash-design-system/components/form';
344
+ import Alert from 'oneslash-design-system/components/alert';
345
+ import TextField from 'oneslash-design-system/components/textField';
346
+ import Icon from 'oneslash-design-system/components/icon';
347
+ import Button from 'oneslash-design-system/components/button';
348
+ import Line from 'oneslash-design-system/components/line';
349
+ import Link from 'oneslash-design-system/components/link';
350
+ import BrandIcon from 'oneslash-design-system/components/brandIcon';
351
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
352
+
353
+ // A real app passes the router from its framework, such as Next's useRouter().
354
+ const router = { push: (url: string) => console.info(`Go to ${url}`) };
355
+
356
+ // A small check: some text, an @, then some text.
357
+ function looksLikeEmail(value: string) {
358
+ return /^[^@\s]+@[^@\s]+$/.test(value);
359
+ }
360
+
361
+ export default function SignUpProviderFirst() {
362
+ const [name, setName] = useState('Ada Lovelace');
363
+ const [email, setEmail] = useState('ada@example.com');
364
+ const [password, setPassword] = useState('');
365
+ const [error, setError] = useState('');
366
+ const [nameError, setNameError] = useState('');
367
+ const [emailError, setEmailError] = useState('');
368
+ const [passwordError, setPasswordError] = useState('');
369
+ const [loading, setLoading] = useState(false);
370
+ // The address the link went to. Set once the account request ends, which shows the check-your-email view.
371
+ const [sentTo, setSentTo] = useState('');
372
+ const [resending, setResending] = useState(false);
373
+ const [resent, setResent] = useState(false);
374
+ const timer = useRef<ReturnType<typeof setTimeout>>();
375
+
376
+ // Stops the request if the example goes away before it ends.
377
+ useEffect(() => () => clearTimeout(timer.current), []);
378
+
379
+ // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
380
+ useEffect(() => {
381
+ if (!resent) return;
382
+ const timer = setTimeout(() => setResent(false), 2000);
383
+ return () => clearTimeout(timer);
384
+ }, [resent]);
385
+
386
+ function handleSubmit() {
387
+ if (loading) return;
388
+ setError('');
389
+ setNameError('');
390
+ setEmailError('');
391
+ setPasswordError('');
392
+ if (!name.trim()) {
393
+ setNameError('Enter your name.');
394
+ return;
395
+ }
396
+ if (!email.trim()) {
397
+ setEmailError('Enter your email.');
398
+ return;
399
+ }
400
+ if (!looksLikeEmail(email.trim())) {
401
+ setEmailError('Enter an email address, like name@example.com.');
402
+ return;
403
+ }
404
+ if (password.length < 8) {
405
+ setPasswordError('Use at least 8 characters.');
406
+ return;
407
+ }
408
+ setLoading(true);
409
+ const address = email.trim();
410
+ // Stands in for the request to the server.
411
+ // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'
412
+ timer.current = setTimeout(() => {
413
+ // Every address goes on to the same view, so the page never says whether it has an account.
414
+ // The Button stays loading until the view changes.
415
+ setLoading(false);
416
+ setSentTo(address);
417
+ }, 1200);
418
+ }
419
+
420
+ function handleSendAgain() {
421
+ // One click sends one email: clicks while it sends or reads 'Sent' do nothing.
422
+ if (resending || resent) return;
423
+ setResending(true);
424
+ // Stands in for the request to the server.
425
+ // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'
426
+ timer.current = setTimeout(() => {
427
+ setResending(false);
428
+ setResent(true);
429
+ }, 1200);
430
+ }
431
+
432
+ // The same view as the 'Check your email' case, in place of the form.
433
+ if (sentTo) {
434
+ return (
435
+ <Center fill>
436
+ <Icon icon={Mail} size="large" color="secondary" />
437
+ <Stack gap="medium">
438
+ <Heading level={1} size="h5">Check your email</Heading>
439
+ <Paragraph tone="secondary" measure="none">We sent a link to {sentTo}. Open it to continue.</Paragraph>
440
+ </Stack>
441
+ <Stack gap="large">
442
+ <Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />
443
+ <Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={() => router.push('/login')} />
444
+ </Stack>
445
+ </Center>
446
+ );
447
+ }
448
+
449
+ return (
450
+ <Center fill>
451
+ <Heading level={1} size="h5">Sign up for Acme</Heading>
452
+ <Stack gap="medium">
453
+ <Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
454
+ <Button size="medium" type="secondary" state="enabled" label="Continue with GitHub" decoIcon={<BrandIcon name="github" />} />
455
+ <Button size="medium" type="secondary" state="enabled" label="Continue with Apple" decoIcon={<BrandIcon name="apple" />} />
456
+ </Stack>
457
+ <Line label="or" />
458
+ <Form aria-label="Sign up with email" onSubmit={handleSubmit}>
459
+ {error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
460
+ <TextField id="sign-up-page-provider-name" label="Name" autoComplete="name" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />
461
+ <TextField id="sign-up-page-provider-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
462
+ <TextField id="sign-up-page-provider-password" label="Password" type="password" autoComplete="new-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText="Use at least 8 characters." onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
463
+ <Button size="medium" type="primary" state="enabled" label="Sign Up with Email" htmlType="submit" loading={loading} />
464
+ </Form>
465
+ <Cluster gap="small">
466
+ <Paragraph tone="secondary" size="body2" measure="none">Already have an account?</Paragraph>
467
+ <Link href="/login" size="body2">Log in</Link>
468
+ </Cluster>
469
+ </Center>
470
+ );
471
+ }
472
+ ```
473
+
474
+ ## Native
475
+
476
+ 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.
477
+
478
+ Seen in: Commentify, Scindo.
@@ -0,0 +1 @@
1
+ export default function SlashCommandListInComposer(): import("react").JSX.Element;
@@ -0,0 +1,162 @@
1
+ 'use client';
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ import { useEffect, useRef, useState } from 'react';
12
+ import Message from '../../components/message';
13
+ import UserImage from '../../components/userImage';
14
+ import TimeStamp from '../../components/timeStamp';
15
+ import Heading from '../../components/heading';
16
+ import Paragraph from '../../components/paragraph';
17
+ import Composer from '../../components/composer';
18
+ import Menu from '../../components/menu';
19
+ import MenuItem from '../../components/menuItem';
20
+ import { Center, Stack } from '../../components/layout';
21
+ // A real app reads this from the session.
22
+ var me = 'Dana Lee';
23
+ var commands = [
24
+ { name: 'plan', does: 'Ask the agent for a plan before it acts' },
25
+ { name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },
26
+ { name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },
27
+ { name: 'status', does: 'Show what the agent is working on' },
28
+ ];
29
+ var listId = 'slash-command-list-commands';
30
+ // The list shows at most this many commands; typing more letters narrows it.
31
+ var MAX_MATCHES = 8;
32
+ var optionId = function (c) { return "slash-command-list-option-".concat(c.name); };
33
+ var firstThread = [
34
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
35
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },
36
+ ];
37
+ // Opens with a / typed, so the list shows every command.
38
+ var firstText = '/';
39
+ // The word after a / at the start of the text before the caret, or null once there is a space or no /.
40
+ function commandQuery(before) {
41
+ var match = before.match(/^\/(\S*)$/);
42
+ return match ? match[1] : null;
43
+ }
44
+ // The query for where the caret is now.
45
+ function queryAtCaret(field) {
46
+ var _a;
47
+ return commandQuery(field.value.slice(0, (_a = field.selectionStart) !== null && _a !== void 0 ? _a : field.value.length));
48
+ }
49
+ var matches = function (query) { return commands.filter(function (c) { return c.name.startsWith(query.toLowerCase()); }).slice(0, MAX_MATCHES); };
50
+ export default function SlashCommandListInComposer() {
51
+ var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
52
+ var _b = useState(firstText), text = _b[0], setText = _b[1];
53
+ var _c = useState(commandQuery(firstText)), query = _c[0], setQuery = _c[1];
54
+ var _d = useState(0), active = _d[0], setActive = _d[1];
55
+ // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
56
+ var _e = useState(null), caret = _e[0], setCaret = _e[1];
57
+ var field = useRef(null);
58
+ var results = query === null ? [] : matches(query);
59
+ // No match: the list closes.
60
+ var open = results.length > 0;
61
+ // The field opens with the caret at the end, after the /.
62
+ useEffect(function () {
63
+ var _a, _b, _c;
64
+ var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
65
+ (_c = field.current) === null || _c === void 0 ? void 0 : _c.setSelectionRange(end, end);
66
+ }, []);
67
+ useEffect(function () {
68
+ if (caret === null || !field.current)
69
+ return;
70
+ field.current.focus();
71
+ field.current.setSelectionRange(caret, caret);
72
+ setCaret(null);
73
+ }, [caret]);
74
+ function change(value) {
75
+ var _a, _b;
76
+ setText(value);
77
+ var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length;
78
+ setQuery(commandQuery(value.slice(0, at)));
79
+ setActive(0);
80
+ }
81
+ // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
82
+ // closes when the caret leaves it.
83
+ function caretMoved(e) {
84
+ var next = queryAtCaret(e.currentTarget);
85
+ if (next === query)
86
+ return;
87
+ setQuery(next);
88
+ setActive(0);
89
+ }
90
+ // Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes
91
+ // after the space, so the person can type the argument. Nothing runs yet.
92
+ function pick(c) {
93
+ var _a, _b;
94
+ var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : text.length;
95
+ var insert = "/".concat(c.name, " ");
96
+ // One space between the command and what follows, not two.
97
+ var after = text.slice(at).replace(/^ /, '');
98
+ setText(insert + after);
99
+ setQuery(null);
100
+ setCaret(insert.length);
101
+ }
102
+ // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
103
+ function keyDown(e) {
104
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
105
+ if (e.nativeEvent.isComposing || e.keyCode === 229)
106
+ return;
107
+ if (!open)
108
+ return;
109
+ if (e.key === 'ArrowDown') {
110
+ e.preventDefault();
111
+ setActive(function (i) { return Math.min(i + 1, results.length - 1); });
112
+ }
113
+ else if (e.key === 'ArrowUp') {
114
+ e.preventDefault();
115
+ setActive(function (i) { return Math.max(i - 1, 0); });
116
+ }
117
+ else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
118
+ // Check the word at the caret again before taking the key. If nothing matches now, the list
119
+ // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
120
+ var now = queryAtCaret(e.currentTarget);
121
+ var found = now === null ? [] : matches(now);
122
+ if (found.length === 0) {
123
+ setQuery(null);
124
+ return;
125
+ }
126
+ e.preventDefault();
127
+ pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
128
+ }
129
+ else if (e.key === 'Escape') {
130
+ e.preventDefault();
131
+ e.stopPropagation();
132
+ setQuery(null);
133
+ }
134
+ }
135
+ // A real app runs the command here. This one shows it in the thread.
136
+ function send() {
137
+ var value = text.trim();
138
+ setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: value, command: value.startsWith('/') }], false); });
139
+ setText('');
140
+ setQuery(null);
141
+ }
142
+ return (<Center width="page">
143
+ <Stack gap="large">
144
+ <Heading level={1} size="h5">Launch plan</Heading>
145
+ {/* A real app gives the list that holds the rows role="log". */}
146
+ <Stack gap="small">
147
+ {thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
148
+ <Paragraph measure="none" mono={m.command}>{m.text}</Paragraph>
149
+ </Message>); })}
150
+ </Stack>
151
+ <Composer ref={field} id="slash-command-list-message" aria-label="Message" placeholder="Message the team, or type / for commands" value={text} onChange={change} onSubmit={send} onKeyDown={keyDown} onSelect={caretMoved}
152
+ // A press on a row keeps focus in the field, so this runs only when focus leaves for good.
153
+ onBlur={function () { return setQuery(null); }}
154
+ // Focus stays in the field; the field points at the list and at the highlighted row.
155
+ role="combobox" aria-autocomplete="list" aria-expanded={open} aria-controls={open ? listId : undefined} aria-activedescendant={open ? optionId(results[active]) : undefined} above={open ? (<Menu role="listbox" id={listId} aria-label="Commands" width={400}>
156
+ {results.map(function (c, i) { return (<MenuItem key={c.name} id={optionId(c)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small" iconName="SquareSlash"
157
+ // MenuItem has no mono label, so the command is plain text.
158
+ label={"/".concat(c.name)} secondLabel={c.does} tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined} onClick={function () { return pick(c); }}/>); })}
159
+ </Menu>) : undefined}/>
160
+ </Stack>
161
+ </Center>);
162
+ }