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,182 @@
1
+ 'use client';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ import { useEffect, useRef, useState } from 'react';
23
+ import { Bot } from 'lucide-react';
24
+ import Message from '../../components/message';
25
+ import UserImage from '../../components/userImage';
26
+ import Tag from '../../components/tag';
27
+ import TimeStamp from '../../components/timeStamp';
28
+ import Heading from '../../components/heading';
29
+ import Paragraph from '../../components/paragraph';
30
+ import Composer from '../../components/composer';
31
+ import FileChip from '../../components/fileChip';
32
+ import Button from '../../components/button';
33
+ import IconButton from '../../components/iconButton';
34
+ import Tooltip from '../../components/tooltip';
35
+ import StepList from '../../components/stepList';
36
+ import { Center, Cluster, Stack } from '../../components/layout';
37
+ // A real app reads this from the session.
38
+ var me = 'Dana Lee';
39
+ var agentName = 'Acme Agent';
40
+ var sampleFile = { name: 'Launch email.pdf', kind: 'PDF', size: '240 KB' };
41
+ var firstThread = [
42
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },
43
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },
44
+ ];
45
+ var FIVE_MINUTES = 5 * 60 * 1000;
46
+ // A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.
47
+ function followsOn(rows, i) {
48
+ var prev = rows[i - 1];
49
+ return (!!prev &&
50
+ prev.from === rows[i].from &&
51
+ rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&
52
+ rows[i].at.toDateString() === prev.at.toDateString());
53
+ }
54
+ function secondsLine(seconds) {
55
+ return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
56
+ }
57
+ // The agent's marks, as the rule 'An agent says what it is' says.
58
+ function agentMeta(at) {
59
+ return (<>
60
+ <Tag variant="contained" size="small" label="Agent"/>
61
+ <TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
62
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
63
+ </>);
64
+ }
65
+ export default function MessageComposerWithTools() {
66
+ var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
67
+ // A real app keeps the draft per thread, so it is still there when the person comes back.
68
+ var _b = useState(''), text = _b[0], setText = _b[1];
69
+ var _c = useState(null), file = _c[0], setFile = _c[1];
70
+ var _d = useState(false), mentionAgent = _d[0], setMentionAgent = _d[1];
71
+ // The agent's run while it works: the id of its row in the thread, and whether a stop has been asked for.
72
+ var _e = useState(null), run = _e[0], setRun = _e[1];
73
+ var _f = useState(0), seconds = _f[0], setSeconds = _f[1];
74
+ var runTimer = useRef();
75
+ var cancel = useRef();
76
+ var tick = useRef();
77
+ var field = useRef(null);
78
+ // On unmount it stops the agent's run, its clock and the cancel request.
79
+ useEffect(function () { return function () {
80
+ clearTimeout(runTimer.current);
81
+ clearTimeout(cancel.current);
82
+ clearInterval(tick.current);
83
+ }; }, []);
84
+ // The run is over: its own row, in the same place and with the same time, now holds the reply or the note.
85
+ function endRun(rowId, text) {
86
+ clearTimeout(runTimer.current);
87
+ clearInterval(tick.current);
88
+ setRun(null);
89
+ setThread(function (rows) { return rows.map(function (m) { return (m.id === rowId ? __assign(__assign({}, m), { text: text, progress: false }) : m); }); });
90
+ }
91
+ function addRow(row) {
92
+ setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [__assign(__assign({}, row), { id: "m".concat(rows.length + 1) })], false); });
93
+ }
94
+ // A real app opens the file picker here; this one attaches a sample file.
95
+ function attach() {
96
+ setFile(sampleFile);
97
+ }
98
+ function removeFile() {
99
+ var _a;
100
+ setFile(null);
101
+ (_a = field.current) === null || _a === void 0 ? void 0 : _a.focus();
102
+ }
103
+ // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is something to send.
104
+ function send() {
105
+ // A real app sends the message to the server here and shows it at once.
106
+ addRow({ from: me, at: new Date(), text: text.trim(), file: file !== null && file !== void 0 ? file : undefined });
107
+ setText('');
108
+ setFile(null);
109
+ // One run at a time: a real app queues a second call to the agent.
110
+ if (!mentionAgent || run)
111
+ return;
112
+ // The run gets one row, added now where the reply will appear. Messages sent during the run go below it.
113
+ var startedAt = new Date();
114
+ var rowId = "run-".concat(startedAt.getTime());
115
+ setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: rowId, from: agentName, agent: true, at: startedAt, text: '', progress: true }], false); });
116
+ setRun({ rowId: rowId, stopping: false });
117
+ setSeconds(0);
118
+ tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
119
+ // Stands in for the agent's run.
120
+ runTimer.current = setTimeout(function () {
121
+ endRun(rowId, 'The email reads well. The pricing link in the second paragraph points to last year\'s page.');
122
+ }, 3000);
123
+ }
124
+ // Stop asks the server to end the run, and shows loading until it has. Only then does the note that it
125
+ // stopped replace the progress row, in the same row. Stop is gone, so focus goes to the message box.
126
+ function stop() {
127
+ if (!run || run.stopping)
128
+ return;
129
+ clearTimeout(runTimer.current);
130
+ setRun(__assign(__assign({}, run), { stopping: true }));
131
+ // Stands in for the request to the server.
132
+ cancel.current = setTimeout(function () {
133
+ var _a;
134
+ endRun(run.rowId, 'Stopped. Nothing was changed.');
135
+ (_a = field.current) === null || _a === void 0 ? void 0 : _a.focus();
136
+ }, 1200);
137
+ }
138
+ return (<Center width="page">
139
+ <Stack gap="large">
140
+ <Heading level={1} size="h5">Launch plan</Heading>
141
+ {/* A real app gives the list that holds the rows role="log". */}
142
+ <Stack gap="small">
143
+ {thread.map(function (m, i) {
144
+ return m.progress && (run === null || run === void 0 ? void 0 : run.rowId) === m.id ? (
145
+ // While the agent works, its row shows where the reply will appear: the seconds so far,
146
+ // the steps, and the only Stop. The case 'Agent at work' has the full pattern.
147
+ <Message key={m.id} aria-label={"".concat(m.from, ", agent")} avatar={<UserImage userHandle={m.from} icon={Bot} decorative/>} name={m.from} meta={agentMeta(m.at)} footer={
148
+ // It shows loading while the run is stopping.
149
+ <Cluster>
150
+ <Button size="small" type="secondary" state="enabled" label="Stop" loading={run.stopping} onClickButton={stop}/>
151
+ </Cluster>}>
152
+ {/* A real app wraps this part in a polite live region, since StepList has none. */}
153
+ <Stack gap="medium">
154
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
155
+ <StepList aria-label="Acme Agent's steps" steps={[
156
+ { label: 'Read the thread', status: 'done' },
157
+ { label: 'Checking the links in the email', status: 'running' },
158
+ ]}/>
159
+ </Stack>
160
+ </Message>) : (<Message key={m.id} aria-label={m.agent ? "".concat(m.from, ", agent") : m.from} compact={followsOn(thread, i)} avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative/> : <UserImage userHandle={m.from} decorative/>} name={m.from} meta={m.agent ? agentMeta(m.at) : <TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}
161
+ // A sent file opens when its chip is pressed. A real app links to the stored file.
162
+ footer={m.file ? <FileChip name={m.file.name} kind={m.file.kind} meta={m.file.size} href="/files/launch-email.pdf" openInNewTab/> : undefined}>
163
+ {m.text && <Paragraph measure="none">{m.text}</Paragraph>}
164
+ </Message>);
165
+ })}
166
+ </Stack>
167
+ {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}
168
+ <Composer ref={field} id="message-composer-tools-message" aria-label="Message"
169
+ // The placeholder says who will read the message.
170
+ placeholder={mentionAgent ? "Message ".concat(agentName) : 'Message the team'} value={text} onChange={setText} onSubmit={send} canSubmit={text.trim() !== '' || file !== null}
171
+ // The Composer keeps Send while the agent works, so a message to people still goes. Stop is on the agent's row.
172
+ above={file ? <FileChip name={file.name} kind={file.kind} meta={file.size} onRemove={removeFile}/> : undefined} tools={<>
173
+ <Tooltip title="Attach files">
174
+ <IconButton color="iconOnly" state="enabled" size="small" iconName="Paperclip" ariaLabel="Attach files" onClick={attach}/>
175
+ </Tooltip>
176
+ <Tooltip title="Mention the agent">
177
+ <IconButton color="iconOnly" state={mentionAgent ? 'selected' : 'enabled'} size="small" icon={Bot} ariaLabel="Mention the agent" aria-pressed={mentionAgent} onClick={function () { return setMentionAgent(function (on) { return !on; }); }}/>
178
+ </Tooltip>
179
+ </>}/>
180
+ </Stack>
181
+ </Center>);
182
+ }
@@ -0,0 +1,356 @@
1
+ # Message composer
2
+
3
+ A person writes a message at the bottom of a thread.
4
+
5
+ **Not built yet:** Scindo's Apple app shows only 'Message' as its placeholder when the agent is not called, so it does not say who will read the message.
6
+
7
+ ## Do
8
+
9
+ - Use `Composer` under the thread, with an `aria-label`, since it has no visible label.
10
+ - 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.
11
+ - Say who will read the message in the placeholder: 'Message the team', or 'Message Acme Agent' while the agent is called.
12
+ - Add the sent message to the thread at once, and set the Composer's `value` to an empty string.
13
+ - Put the tools in `tools`: an attach `IconButton`, and a toggle that calls the agent, `state="selected"` and `aria-pressed` while it is on.
14
+ - Pass `canSubmit` when a file alone can be sent.
15
+ - 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.
16
+ - Pass `onStop` in a conversation with the agent only, so Send becomes Stop.
17
+ - 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.
18
+ - Show 'Working for 12 seconds' in the progress row's body, above the steps.
19
+ - Show 'Stop' as `loading` until the run has ended. Then 'Stopped. Nothing was changed.' replaces the progress row in the same place.
20
+ - Move focus to the message box when Stop goes away.
21
+ - Announce the progress row politely to screen readers: the app wraps the changing part in a polite live region, since the row has none.
22
+ - 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.
23
+ - Keep the draft when the person leaves the thread, and show it again when they come back.
24
+
25
+ ## Don't
26
+
27
+ - Do not clear the field before the message is in the thread.
28
+ - Do not write a placeholder that does not say who reads the message, such as 'Type here'.
29
+ - Do not send on Return on a touch screen.
30
+ - Do not hide the Stop on the agent's row while the agent works.
31
+ - Do not turn Send into Stop in a thread that people also write in.
32
+
33
+ ## Option: Plain composer
34
+
35
+ Use when: Only people read the thread.
36
+
37
+ Uses: `Center`, `Composer`, `Heading`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
38
+
39
+ ```tsx
40
+ 'use client';
41
+ import { useState } from 'react';
42
+ import Message from 'oneslash-design-system/components/message';
43
+ import UserImage from 'oneslash-design-system/components/userImage';
44
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
45
+ import Heading from 'oneslash-design-system/components/heading';
46
+ import Paragraph from 'oneslash-design-system/components/paragraph';
47
+ import Composer from 'oneslash-design-system/components/composer';
48
+ import { Center, Stack } from 'oneslash-design-system/components/layout';
49
+
50
+ // A real app reads this from the session.
51
+ const me = 'Dana Lee';
52
+
53
+ type Row = { id: string; from: string; at: Date; text: string };
54
+
55
+ const firstThread: Row[] = [
56
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },
57
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },
58
+ ];
59
+
60
+ const FIVE_MINUTES = 5 * 60 * 1000;
61
+
62
+ // A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.
63
+ function followsOn(rows: Row[], i: number) {
64
+ const prev = rows[i - 1];
65
+ return (
66
+ !!prev &&
67
+ prev.from === rows[i].from &&
68
+ rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&
69
+ rows[i].at.toDateString() === prev.at.toDateString()
70
+ );
71
+ }
72
+
73
+ export default function MessageComposerPlain() {
74
+ const [thread, setThread] = useState(firstThread);
75
+ // A real app keeps the draft per thread, so it is still there when the person comes back.
76
+ const [text, setText] = useState('');
77
+
78
+ // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is text.
79
+ function send() {
80
+ // A real app sends the message to the server here and shows it at once.
81
+ setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);
82
+ setText('');
83
+ }
84
+
85
+ return (
86
+ <Center width="page">
87
+ <Stack gap="large">
88
+ <Heading level={1} size="h5">Launch plan</Heading>
89
+ {/* A real app gives the list that holds the rows role="log". */}
90
+ <Stack gap="small">
91
+ {thread.map((m, i) => (
92
+ <Message
93
+ key={m.id}
94
+ aria-label={m.from}
95
+ compact={followsOn(thread, i)}
96
+ avatar={<UserImage userHandle={m.from} decorative />}
97
+ name={m.from}
98
+ meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
99
+ >
100
+ <Paragraph measure="none">{m.text}</Paragraph>
101
+ </Message>
102
+ ))}
103
+ </Stack>
104
+ {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}
105
+ <Composer
106
+ id="message-composer-message"
107
+ aria-label="Message"
108
+ placeholder="Message the team"
109
+ value={text}
110
+ onChange={setText}
111
+ onSubmit={send}
112
+ />
113
+ </Stack>
114
+ </Center>
115
+ );
116
+ }
117
+ ```
118
+
119
+ ## Option: Composer with tools
120
+
121
+ Use when: The person can attach files and call the agent.
122
+
123
+ Uses: `Button`, `Center`, `Cluster`, `Composer`, `FileChip`, `Heading`, `IconButton`, `Message`, `Paragraph`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `Tooltip`, `UserImage`
124
+
125
+ ```tsx
126
+ 'use client';
127
+ import { useEffect, useRef, useState } from 'react';
128
+ import { Bot } from 'lucide-react';
129
+ import Message from 'oneslash-design-system/components/message';
130
+ import UserImage from 'oneslash-design-system/components/userImage';
131
+ import Tag from 'oneslash-design-system/components/tag';
132
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
133
+ import Heading from 'oneslash-design-system/components/heading';
134
+ import Paragraph from 'oneslash-design-system/components/paragraph';
135
+ import Composer from 'oneslash-design-system/components/composer';
136
+ import FileChip from 'oneslash-design-system/components/fileChip';
137
+ import Button from 'oneslash-design-system/components/button';
138
+ import IconButton from 'oneslash-design-system/components/iconButton';
139
+ import Tooltip from 'oneslash-design-system/components/tooltip';
140
+ import StepList from 'oneslash-design-system/components/stepList';
141
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
142
+
143
+ // A real app reads this from the session.
144
+ const me = 'Dana Lee';
145
+ const agentName = 'Acme Agent';
146
+
147
+ type Attachment = { name: string; kind: string; size: string };
148
+ // `progress` marks the agent's row while its run is live. The same row later holds the note or the reply.
149
+ type Row = { id: string; from: string; agent?: boolean; at: Date; text: string; file?: Attachment; progress?: boolean };
150
+
151
+ const sampleFile: Attachment = { name: 'Launch email.pdf', kind: 'PDF', size: '240 KB' };
152
+
153
+ const firstThread: Row[] = [
154
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },
155
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },
156
+ ];
157
+
158
+ const FIVE_MINUTES = 5 * 60 * 1000;
159
+
160
+ // A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.
161
+ function followsOn(rows: Row[], i: number) {
162
+ const prev = rows[i - 1];
163
+ return (
164
+ !!prev &&
165
+ prev.from === rows[i].from &&
166
+ rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&
167
+ rows[i].at.toDateString() === prev.at.toDateString()
168
+ );
169
+ }
170
+
171
+ function secondsLine(seconds: number) {
172
+ return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
173
+ }
174
+
175
+ // The agent's marks, as the rule 'An agent says what it is' says.
176
+ function agentMeta(at: Date) {
177
+ return (
178
+ <>
179
+ <Tag variant="contained" size="small" label="Agent" />
180
+ <TimeStamp createdAt={at} dateFormat="absolute" data="time" />
181
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
182
+ </>
183
+ );
184
+ }
185
+
186
+ export default function MessageComposerWithTools() {
187
+ const [thread, setThread] = useState(firstThread);
188
+ // A real app keeps the draft per thread, so it is still there when the person comes back.
189
+ const [text, setText] = useState('');
190
+ const [file, setFile] = useState<Attachment | null>(null);
191
+ const [mentionAgent, setMentionAgent] = useState(false);
192
+ // The agent's run while it works: the id of its row in the thread, and whether a stop has been asked for.
193
+ const [run, setRun] = useState<{ rowId: string; stopping: boolean } | null>(null);
194
+ const [seconds, setSeconds] = useState(0);
195
+ const runTimer = useRef<ReturnType<typeof setTimeout>>();
196
+ const cancel = useRef<ReturnType<typeof setTimeout>>();
197
+ const tick = useRef<ReturnType<typeof setInterval>>();
198
+ const field = useRef<HTMLTextAreaElement>(null);
199
+
200
+ // On unmount it stops the agent's run, its clock and the cancel request.
201
+ useEffect(() => () => {
202
+ clearTimeout(runTimer.current);
203
+ clearTimeout(cancel.current);
204
+ clearInterval(tick.current);
205
+ }, []);
206
+
207
+ // The run is over: its own row, in the same place and with the same time, now holds the reply or the note.
208
+ function endRun(rowId: string, text: string) {
209
+ clearTimeout(runTimer.current);
210
+ clearInterval(tick.current);
211
+ setRun(null);
212
+ setThread((rows) => rows.map((m) => (m.id === rowId ? { ...m, text, progress: false } : m)));
213
+ }
214
+
215
+ function addRow(row: Omit<Row, 'id'>) {
216
+ setThread((rows) => [...rows, { ...row, id: `m${rows.length + 1}` }]);
217
+ }
218
+
219
+ // A real app opens the file picker here; this one attaches a sample file.
220
+ function attach() {
221
+ setFile(sampleFile);
222
+ }
223
+
224
+ function removeFile() {
225
+ setFile(null);
226
+ field.current?.focus();
227
+ }
228
+
229
+ // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is something to send.
230
+ function send() {
231
+ // A real app sends the message to the server here and shows it at once.
232
+ addRow({ from: me, at: new Date(), text: text.trim(), file: file ?? undefined });
233
+ setText('');
234
+ setFile(null);
235
+ // One run at a time: a real app queues a second call to the agent.
236
+ if (!mentionAgent || run) return;
237
+ // The run gets one row, added now where the reply will appear. Messages sent during the run go below it.
238
+ const startedAt = new Date();
239
+ const rowId = `run-${startedAt.getTime()}`;
240
+ setThread((rows) => [...rows, { id: rowId, from: agentName, agent: true, at: startedAt, text: '', progress: true }]);
241
+ setRun({ rowId, stopping: false });
242
+ setSeconds(0);
243
+ tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);
244
+ // Stands in for the agent's run.
245
+ runTimer.current = setTimeout(() => {
246
+ endRun(rowId, 'The email reads well. The pricing link in the second paragraph points to last year\'s page.');
247
+ }, 3000);
248
+ }
249
+
250
+ // Stop asks the server to end the run, and shows loading until it has. Only then does the note that it
251
+ // stopped replace the progress row, in the same row. Stop is gone, so focus goes to the message box.
252
+ function stop() {
253
+ if (!run || run.stopping) return;
254
+ clearTimeout(runTimer.current);
255
+ setRun({ ...run, stopping: true });
256
+ // Stands in for the request to the server.
257
+ cancel.current = setTimeout(() => {
258
+ endRun(run.rowId, 'Stopped. Nothing was changed.');
259
+ field.current?.focus();
260
+ }, 1200);
261
+ }
262
+
263
+ return (
264
+ <Center width="page">
265
+ <Stack gap="large">
266
+ <Heading level={1} size="h5">Launch plan</Heading>
267
+ {/* A real app gives the list that holds the rows role="log". */}
268
+ <Stack gap="small">
269
+ {thread.map((m, i) =>
270
+ m.progress && run?.rowId === m.id ? (
271
+ // While the agent works, its row shows where the reply will appear: the seconds so far,
272
+ // the steps, and the only Stop. The case 'Agent at work' has the full pattern.
273
+ <Message
274
+ key={m.id}
275
+ aria-label={`${m.from}, agent`}
276
+ avatar={<UserImage userHandle={m.from} icon={Bot} decorative />}
277
+ name={m.from}
278
+ meta={agentMeta(m.at)}
279
+ footer={
280
+ // It shows loading while the run is stopping.
281
+ <Cluster>
282
+ <Button size="small" type="secondary" state="enabled" label="Stop" loading={run.stopping} onClickButton={stop} />
283
+ </Cluster>
284
+ }
285
+ >
286
+ {/* A real app wraps this part in a polite live region, since StepList has none. */}
287
+ <Stack gap="medium">
288
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
289
+ <StepList
290
+ aria-label="Acme Agent's steps"
291
+ steps={[
292
+ { label: 'Read the thread', status: 'done' },
293
+ { label: 'Checking the links in the email', status: 'running' },
294
+ ]}
295
+ />
296
+ </Stack>
297
+ </Message>
298
+ ) : (
299
+ <Message
300
+ key={m.id}
301
+ aria-label={m.agent ? `${m.from}, agent` : m.from}
302
+ compact={followsOn(thread, i)}
303
+ avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}
304
+ name={m.from}
305
+ meta={m.agent ? agentMeta(m.at) : <TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
306
+ // A sent file opens when its chip is pressed. A real app links to the stored file.
307
+ footer={m.file ? <FileChip name={m.file.name} kind={m.file.kind} meta={m.file.size} href="/files/launch-email.pdf" openInNewTab /> : undefined}
308
+ >
309
+ {m.text && <Paragraph measure="none">{m.text}</Paragraph>}
310
+ </Message>
311
+ ),
312
+ )}
313
+ </Stack>
314
+ {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}
315
+ <Composer
316
+ ref={field}
317
+ id="message-composer-tools-message"
318
+ aria-label="Message"
319
+ // The placeholder says who will read the message.
320
+ placeholder={mentionAgent ? `Message ${agentName}` : 'Message the team'}
321
+ value={text}
322
+ onChange={setText}
323
+ onSubmit={send}
324
+ canSubmit={text.trim() !== '' || file !== null}
325
+ // The Composer keeps Send while the agent works, so a message to people still goes. Stop is on the agent's row.
326
+ above={file ? <FileChip name={file.name} kind={file.kind} meta={file.size} onRemove={removeFile} /> : undefined}
327
+ tools={
328
+ <>
329
+ <Tooltip title="Attach files">
330
+ <IconButton color="iconOnly" state="enabled" size="small" iconName="Paperclip" ariaLabel="Attach files" onClick={attach} />
331
+ </Tooltip>
332
+ <Tooltip title="Mention the agent">
333
+ <IconButton
334
+ color="iconOnly"
335
+ state={mentionAgent ? 'selected' : 'enabled'}
336
+ size="small"
337
+ icon={Bot}
338
+ ariaLabel="Mention the agent"
339
+ aria-pressed={mentionAgent}
340
+ onClick={() => setMentionAgent((on) => !on)}
341
+ />
342
+ </Tooltip>
343
+ </>
344
+ }
345
+ />
346
+ </Stack>
347
+ </Center>
348
+ );
349
+ }
350
+ ```
351
+
352
+ ## Native
353
+
354
+ 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.
355
+
356
+ Seen in: Commentify, Scindo.
@@ -0,0 +1 @@
1
+ export default function MessageEditInPlace(): import("react").JSX.Element;
@@ -0,0 +1,99 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Message from '../../components/message';
4
+ import UserImage from '../../components/userImage';
5
+ import TimeStamp from '../../components/timeStamp';
6
+ import Heading from '../../components/heading';
7
+ import Paragraph from '../../components/paragraph';
8
+ import Composer from '../../components/composer';
9
+ import Button from '../../components/button';
10
+ import IconButton from '../../components/iconButton';
11
+ import Tooltip from '../../components/tooltip';
12
+ import { Center, Cluster, Stack } from '../../components/layout';
13
+ // A real app reads this from the session.
14
+ var me = 'Dana Lee';
15
+ var question = { from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'When does the launch email go out?' };
16
+ var mine = { from: me, at: new Date('2025-01-15T11:42:00Z') };
17
+ export default function MessageEditInPlace() {
18
+ var _a = useState('Thursday at 9:00.'), text = _a[0], setText = _a[1];
19
+ var _b = useState(false), edited = _b[0], setEdited = _b[1];
20
+ // Opens with the message in edit mode, as if the person just chose Edit.
21
+ var _c = useState(true), editing = _c[0], setEditing = _c[1];
22
+ var _d = useState('Thursday at 9:00.'), draft = _d[0], setDraft = _d[1];
23
+ var _e = useState(false), saving = _e[0], setSaving = _e[1];
24
+ var timer = useRef();
25
+ var field = useRef(null);
26
+ var editButton = useRef(null);
27
+ // On unmount it stops the request.
28
+ useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
29
+ // Set when the person presses Edit. The example opens in edit mode without it, so nothing takes focus on load.
30
+ var pressedEdit = useRef(false);
31
+ // When the person opens the field, focus it with the caret after the text. When it closes, the field
32
+ // that had focus is gone, so focus goes to the row's Edit button.
33
+ useEffect(function () {
34
+ var _a;
35
+ if (!editing) {
36
+ (_a = editButton.current) === null || _a === void 0 ? void 0 : _a.focus();
37
+ return;
38
+ }
39
+ if (!pressedEdit.current || !field.current)
40
+ return;
41
+ var end = field.current.value.length;
42
+ field.current.focus();
43
+ field.current.setSelectionRange(end, end);
44
+ }, [editing]);
45
+ // An empty or unchanged text has nothing to save.
46
+ var canSave = draft.trim() !== '' && draft.trim() !== text;
47
+ function startEditing() {
48
+ pressedEdit.current = true;
49
+ setDraft(text);
50
+ setEditing(true);
51
+ }
52
+ function cancel() {
53
+ if (saving)
54
+ return;
55
+ setEditing(false);
56
+ }
57
+ function save() {
58
+ if (saving || !canSave)
59
+ return;
60
+ setSaving(true);
61
+ // Stands in for the request to the server.
62
+ timer.current = setTimeout(function () {
63
+ setSaving(false);
64
+ setText(draft.trim());
65
+ setEdited(true);
66
+ setEditing(false);
67
+ }, 1200);
68
+ }
69
+ return (<Center width="page">
70
+ <Stack gap="large">
71
+ <Heading level={1} size="h5">Launch plan</Heading>
72
+ {/* A real app gives the list that holds the rows role="log". */}
73
+ <Stack gap="small">
74
+ <Message aria-label={question.from} avatar={<UserImage userHandle={question.from} decorative/>} name={question.from} meta={<TimeStamp createdAt={question.at} dateFormat="absolute" data="time"/>}>
75
+ <Paragraph measure="none">{question.text}</Paragraph>
76
+ </Message>
77
+ <Message aria-label={mine.from} avatar={<UserImage userHandle={mine.from} decorative/>} name={mine.from} meta={<>
78
+ <TimeStamp createdAt={mine.at} dateFormat="absolute" data="time"/>
79
+ {edited && <Paragraph size="caption" tone="secondary" measure="none">(edited)</Paragraph>}
80
+ </>} actions={editing ? undefined : (<Tooltip title="Edit">
81
+ <IconButton ref={editButton} color="iconOnly" state="enabled" size="small" iconName="Pencil" ariaLabel="Edit your message" onClick={startEditing}/>
82
+ </Tooltip>)}>
83
+ {editing ? (
84
+ // The body becomes a Composer in place. Enter saves and Escape cancels.
85
+ <Composer ref={field} id="message-edit-text" aria-label="Edit message" value={draft} onChange={setDraft} onSubmit={save} canSubmit={canSave} disabled={saving} onKeyDown={function (e) {
86
+ if (e.key === 'Escape') {
87
+ e.preventDefault();
88
+ e.stopPropagation();
89
+ cancel();
90
+ }
91
+ }} actions={<Cluster gap="small">
92
+ <Button size="small" type="tertiary" state={saving ? 'disabled' : 'enabled'} label="Cancel" onClickButton={cancel}/>
93
+ <Button size="small" type="primary" state={canSave ? 'enabled' : 'disabled'} label="Save" loading={saving} onClickButton={save}/>
94
+ </Cluster>}/>) : (<Paragraph measure="none">{text}</Paragraph>)}
95
+ </Message>
96
+ </Stack>
97
+ </Stack>
98
+ </Center>);
99
+ }