@swisper.ai/web-chat-ui 0.0.2 → 0.0.4

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 (355) hide show
  1. package/README.md +9 -12
  2. package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
  3. package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
  4. package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
  5. package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
  6. package/dist/components/chat-card/chat-card.d.ts +1 -0
  7. package/dist/components/chat-card/chat-card.d.ts.map +1 -1
  8. package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
  9. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  10. package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
  11. package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
  12. package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
  13. package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
  14. package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
  15. package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
  16. package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
  17. package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
  18. package/dist/components/chat-card/contexts.d.ts +2 -0
  19. package/dist/components/chat-card/contexts.d.ts.map +1 -1
  20. package/dist/components/chat-card/hooks.d.ts +1 -0
  21. package/dist/components/chat-card/hooks.d.ts.map +1 -1
  22. package/dist/components/chat-card/types.d.ts +3 -0
  23. package/dist/components/chat-card/types.d.ts.map +1 -1
  24. package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
  25. package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
  26. package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
  27. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  28. package/dist/components/chat-container/chat-container.d.ts.map +1 -1
  29. package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
  30. package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
  31. package/dist/components/chat-input/chat-input.d.ts +27 -2
  32. package/dist/components/chat-input/chat-input.d.ts.map +1 -1
  33. package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
  34. package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
  35. package/dist/components/chat-list/chat-list-item.d.ts +6 -0
  36. package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
  37. package/dist/components/chat-list/chat-list-items.d.ts +12 -1
  38. package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
  39. package/dist/components/chat-list/chat-list.d.ts +36 -2
  40. package/dist/components/chat-list/chat-list.d.ts.map +1 -1
  41. package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
  42. package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
  43. package/dist/components/chat-message/chat-message.d.ts +12 -1
  44. package/dist/components/chat-message/chat-message.d.ts.map +1 -1
  45. package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
  46. package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
  47. package/dist/components/chat-message/index.d.ts +1 -1
  48. package/dist/components/chat-message/index.d.ts.map +1 -1
  49. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
  50. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
  51. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
  52. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
  53. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
  54. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
  55. package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
  56. package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
  57. package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
  58. package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
  59. package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
  60. package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
  61. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
  62. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
  63. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
  64. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
  65. package/dist/components/chat-message-toolbar/index.d.ts +1 -1
  66. package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
  67. package/dist/components/chat-messages/chat-messages.d.ts +34 -2
  68. package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
  69. package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
  70. package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
  71. package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
  72. package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
  73. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
  74. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
  75. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
  76. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
  77. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
  78. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
  79. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
  80. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
  81. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
  82. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
  83. package/dist/components/chat-reply/chat-reply.d.ts +11 -0
  84. package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
  85. package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
  86. package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
  87. package/dist/components/chat-reply/index.d.ts +1 -1
  88. package/dist/components/chat-reply/index.d.ts.map +1 -1
  89. package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
  90. package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
  91. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
  92. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
  93. package/dist/components/chat-suggestion/index.d.ts +2 -1
  94. package/dist/components/chat-suggestion/index.d.ts.map +1 -1
  95. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
  96. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  97. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
  98. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  99. package/dist/components/chat-thread/chat-thread.d.ts +17 -2
  100. package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
  101. package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
  102. package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
  103. package/dist/components/index.d.ts +1 -3
  104. package/dist/components/index.d.ts.map +1 -1
  105. package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
  106. package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
  107. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
  108. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
  109. package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
  110. package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
  111. package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
  112. package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
  113. package/dist/components/rich-text-area/styled.d.ts +6 -2
  114. package/dist/components/rich-text-area/styled.d.ts.map +1 -1
  115. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
  116. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
  117. package/dist/components/rich-text-field/components/index.d.ts +5 -5
  118. package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
  119. package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
  120. package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
  121. package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
  122. package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
  123. package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
  124. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  125. package/dist/components/topmenu/index.d.ts +2 -0
  126. package/dist/components/topmenu/index.d.ts.map +1 -0
  127. package/dist/components/topmenu/topmenu.d.ts +22 -0
  128. package/dist/components/topmenu/topmenu.d.ts.map +1 -0
  129. package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
  130. package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
  131. package/dist/docs/agent.stories.d.ts.map +1 -1
  132. package/dist/docs/chat-panel.d.ts +7 -5
  133. package/dist/docs/chat-panel.d.ts.map +1 -1
  134. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  135. package/dist/docs/chatbot.stories.d.ts.map +1 -1
  136. package/dist/index.css +1 -1
  137. package/dist/index.es.js +1227 -1260
  138. package/dist/index.es.js.map +1 -1
  139. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
  140. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
  141. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
  142. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
  143. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
  144. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
  145. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
  146. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
  147. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
  148. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
  149. package/package.json +15 -9
  150. package/src/__storybook__/parent-block.tsx +21 -0
  151. package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
  152. package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
  153. package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
  154. package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
  155. package/src/components/canvas-shell/__stories__/types.ts +47 -0
  156. package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
  157. package/src/components/canvas-shell/canvas-shell.json +24 -0
  158. package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
  159. package/src/components/canvas-shell/canvas-shell.tsx +44 -17
  160. package/src/components/chat-card/__stories__/fixtures.ts +119 -0
  161. package/src/components/chat-card/__stories__/types.ts +44 -0
  162. package/src/components/chat-card/chat-card.json +67 -3
  163. package/src/components/chat-card/chat-card.stories.tsx +872 -148
  164. package/src/components/chat-card/chat-card.tsx +2 -0
  165. package/src/components/chat-card/components/chat-card-body.tsx +12 -0
  166. package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
  167. package/src/components/chat-card/components/chat-card-form.tsx +21 -2
  168. package/src/components/chat-card/components/chat-card-header.tsx +39 -2
  169. package/src/components/chat-card/contexts.tsx +2 -0
  170. package/src/components/chat-card/hooks.ts +1 -0
  171. package/src/components/chat-card/types.ts +3 -0
  172. package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
  173. package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
  174. package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
  175. package/src/components/chat-card-container/__stories__/types.ts +16 -0
  176. package/src/components/chat-card-container/chat-card-container.json +7 -0
  177. package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
  178. package/src/components/chat-card-container/chat-card-container.tsx +5 -0
  179. package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
  180. package/src/components/chat-container/__stories__/fixtures.ts +27 -0
  181. package/src/components/chat-container/__stories__/measure.ts +22 -0
  182. package/src/components/chat-container/__stories__/types.ts +7 -0
  183. package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
  184. package/src/components/chat-container/chat-container.json +9 -1
  185. package/src/components/chat-container/chat-container.stories.tsx +538 -106
  186. package/src/components/chat-container/chat-container.tsx +3 -0
  187. package/src/components/chat-input/__stories__/fixtures.ts +31 -0
  188. package/src/components/chat-input/chat-input.json +10 -2
  189. package/src/components/chat-input/chat-input.stories.tsx +660 -197
  190. package/src/components/chat-input/chat-input.tsx +32 -2
  191. package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
  192. package/src/components/chat-list/__stories__/fixtures.ts +94 -0
  193. package/src/components/chat-list/__stories__/types.ts +13 -0
  194. package/src/components/chat-list/chat-list-item.tsx +6 -0
  195. package/src/components/chat-list/chat-list-items.tsx +16 -0
  196. package/src/components/chat-list/chat-list.json +24 -2
  197. package/src/components/chat-list/chat-list.stories.tsx +631 -215
  198. package/src/components/chat-list/chat-list.tsx +51 -4
  199. package/src/components/chat-message/__stories__/fixtures.ts +53 -0
  200. package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
  201. package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
  202. package/src/components/chat-message/chat-message.json +10 -1
  203. package/src/components/chat-message/chat-message.stories.tsx +282 -20
  204. package/src/components/chat-message/chat-message.tsx +16 -1
  205. package/src/components/chat-message/index.ts +8 -1
  206. package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
  207. package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
  208. package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
  209. package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
  210. package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
  211. package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
  212. package/src/components/chat-message-attachment-card/index.ts +6 -0
  213. package/src/components/chat-message-attachment-card/utils.ts +1 -0
  214. package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
  215. package/src/components/chat-message-response/chat-message-response.json +5 -0
  216. package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
  217. package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
  218. package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
  219. package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
  220. package/src/components/chat-message-toolbar/index.ts +4 -0
  221. package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
  222. package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
  223. package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
  224. package/src/components/chat-messages/__stories__/types.ts +5 -0
  225. package/src/components/chat-messages/chat-messages.json +30 -12
  226. package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
  227. package/src/components/chat-messages/chat-messages.tsx +46 -3
  228. package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
  229. package/src/components/chat-notification-card/__stories__/types.ts +13 -0
  230. package/src/components/chat-notification-card/chat-notification-card.json +52 -2
  231. package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
  232. package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
  233. package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
  234. package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
  235. package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
  236. package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
  237. package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
  238. package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
  239. package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
  240. package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
  241. package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
  242. package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
  243. package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
  244. package/src/components/chat-reply/chat-reply.json +10 -0
  245. package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
  246. package/src/components/chat-reply/chat-reply.tsx +15 -0
  247. package/src/components/chat-reply/index.ts +10 -1
  248. package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
  249. package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
  250. package/src/components/chat-suggestion/chat-suggestion.json +62 -20
  251. package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
  252. package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
  253. package/src/components/chat-suggestion/index.ts +9 -0
  254. package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
  255. package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
  256. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
  257. package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
  258. package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
  259. package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
  260. package/src/components/chat-thread/__stories__/snippets.ts +129 -0
  261. package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
  262. package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
  263. package/src/components/chat-thread/__stories__/types.ts +12 -0
  264. package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
  265. package/src/components/chat-thread/chat-thread.json +23 -3
  266. package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
  267. package/src/components/chat-thread/chat-thread.tsx +64 -16
  268. package/src/components/index.ts +1 -3
  269. package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
  270. package/src/components/markdown-viewer/markdown-viewer.json +7 -1
  271. package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
  272. package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
  273. package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
  274. package/src/components/rich-text-area/rich-text-area.json +6 -4
  275. package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
  276. package/src/components/rich-text-area/rich-text-area.tsx +22 -1
  277. package/src/components/rich-text-area/styled.tsx +11 -5
  278. package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
  279. package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
  280. package/src/components/rich-text-field/components/index.ts +8 -5
  281. package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
  282. package/src/components/rich-text-field/rich-text-field.json +3 -1
  283. package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
  284. package/src/components/rich-text-field/rich-text-field.tsx +23 -0
  285. package/src/components/topmenu/index.ts +1 -0
  286. package/src/components/topmenu/topmenu.json +107 -0
  287. package/src/components/topmenu/topmenu.stories.tsx +334 -0
  288. package/src/components/topmenu/topmenu.tsx +71 -0
  289. package/src/docs/agent.stories.tsx +16 -16
  290. package/src/docs/chat-panel.tsx +37 -32
  291. package/src/docs/chatbot-panel.tsx +11 -2
  292. package/src/docs/chatbot.mdx +17 -12
  293. package/src/docs/chatbot.stories.tsx +7 -8
  294. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
  295. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
  296. package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
  297. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
  298. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
  299. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
  300. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
  301. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
  302. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
  303. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
  304. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
  305. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
  306. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
  307. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
  308. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
  309. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
  310. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
  311. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
  312. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
  313. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
  314. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
  315. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
  316. package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
  317. package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
  318. package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
  319. package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
  320. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
  321. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
  322. package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
  323. package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
  324. package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
  325. package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
  326. package/dist/components/card-item-picker/index.d.ts +0 -9
  327. package/dist/components/card-item-picker/index.d.ts.map +0 -1
  328. package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
  329. package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
  330. package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
  331. package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
  332. package/dist/components/chat-message-history/index.d.ts +0 -2
  333. package/dist/components/chat-message-history/index.d.ts.map +0 -1
  334. package/dist/components/spinner/index.d.ts +0 -2
  335. package/dist/components/spinner/index.d.ts.map +0 -1
  336. package/dist/components/spinner/spinner.d.ts +0 -9
  337. package/dist/components/spinner/spinner.d.ts.map +0 -1
  338. package/dist/components/spinner/spinner.stories.d.ts +0 -8
  339. package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
  340. package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
  341. package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
  342. package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
  343. package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
  344. package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
  345. package/src/components/card-item-picker/card-item-picker.json +0 -147
  346. package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
  347. package/src/components/card-item-picker/index.ts +0 -24
  348. package/src/components/chat-message-history/chat-message-history.json +0 -99
  349. package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
  350. package/src/components/chat-message-history/chat-message-history.tsx +0 -277
  351. package/src/components/chat-message-history/index.ts +0 -13
  352. package/src/components/spinner/index.ts +0 -1
  353. package/src/components/spinner/spinner.json +0 -73
  354. package/src/components/spinner/spinner.stories.tsx +0 -41
  355. package/src/components/spinner/spinner.tsx +0 -32
@@ -1,90 +1,45 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useEffect, useState, type ReactNode } from 'react';
3
+ import { expect, fn, waitFor, within } from 'storybook/test';
3
4
 
4
5
  import { ChatConversationProvider } from '@/contexts';
6
+ import { ArrowDownIcon } from '@swisper.ai/icons';
7
+ import { Button, Typography, withTooltip } from '@swisper.ai/ui';
5
8
 
9
+ import { ParentBlock } from '../../__storybook__/parent-block';
10
+ import {
11
+ CanvasShell,
12
+ CanvasShellCloseTrigger,
13
+ CanvasShellContent,
14
+ CanvasShellHeader,
15
+ CanvasShellTitle,
16
+ } from '../canvas-shell';
6
17
  import { ChatMessage, ChatMessageContent } from '../chat-message';
7
18
 
19
+ import { ConversationFrame } from './__stories__/conversation-frame';
20
+ import { ConversationGroup } from './__stories__/conversation-group';
21
+ import { ALL_TURNS, CONVERSATION, FOLLOW_UP_TURNS, SCROLL_TOOLTIP } from './__stories__/fixtures';
22
+ import type { ConversationTurn } from './__stories__/types';
8
23
  import {
9
24
  ChatMessageListGroup,
10
25
  ChatMessages,
11
26
  ChatMessagesList,
12
27
  ChatMessagesScrollButton,
28
+ type ChatMessagesProps,
13
29
  } from './chat-messages';
14
30
 
15
- interface DemoMessage {
16
- isQuestion: boolean;
17
- text: string;
18
- }
19
-
20
- const defaultMessages: DemoMessage[] = [
21
- { isQuestion: true, text: 'What are my recent transactions?' },
22
- { isQuestion: false, text: 'Here is the history of your recent transactions.' },
23
- { isQuestion: true, text: 'Can you show the largest one?' },
24
- {
25
- isQuestion: false,
26
- text: 'Your largest transaction this month was $1,240.50 at Acme Corp on May 12.',
27
- },
28
- { isQuestion: true, text: 'How does that compare to last month?' },
29
- {
30
- isQuestion: false,
31
- text: 'Last month your largest transaction was $980.20, so spending is up about 27%.',
32
- },
33
- { isQuestion: true, text: 'Break down my spending by category this month.' },
34
- {
35
- isQuestion: false,
36
- text: 'Groceries: $412.30, Dining: $286.15, Transport: $154.00, Subscriptions: $89.99.',
37
- },
38
- { isQuestion: true, text: 'Which subscriptions am I paying for?' },
39
- {
40
- isQuestion: false,
41
- text: 'You have four active subscriptions: StreamPlus, Cloud Storage, Fitness App, and News Daily.',
42
- },
43
- ];
44
-
45
- const addedMessages: DemoMessage[] = [
46
- { isQuestion: true, text: 'Can I set a budget alert for dining?' },
47
- { isQuestion: false, text: 'Yes. What monthly cap would you like?' },
48
- { isQuestion: true, text: 'Set it to $300.' },
49
- { isQuestion: false, text: 'Done. You will get an alert when dining spending hits $300.' },
50
- ];
51
-
52
- const loremIpsumParagraph =
53
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
54
-
55
- const streamingAnswers = [
56
- Array.from({ length: 8 }, () => loremIpsumParagraph).join(' '),
57
- Array.from({ length: 10 }, () => loremIpsumParagraph).join(' '),
58
- Array.from({ length: 12 }, () => loremIpsumParagraph).join(' '),
59
- ];
60
-
61
- const streamingQuestions = [
62
- 'Summarize my financial activity.',
63
- 'What are my largest expenses this month?',
64
- 'How can I reduce my subscription spending?',
65
- 'Break down my cash flow for the last quarter.',
66
- 'What is the weather in Tokyo?',
67
- 'Compare my dining spend to last month.',
68
- ];
69
-
70
- function pickRandomItem<T>(items: T[]): T {
71
- return items[Math.floor(Math.random() * items.length)];
72
- }
73
-
74
31
  const meta: Meta<typeof ChatMessages> = {
75
- title: 'Chatbot/ChatMessages',
32
+ title: 'Chat/ChatMessages',
76
33
  component: ChatMessages,
77
- parameters: { layout: 'padded' },
34
+ parameters: {
35
+ layout: 'padded',
36
+ // Each story scrolls its last row into view, which would also scroll the docs page; an
37
+ // iframe per story keeps that scrolling inside the story.
38
+ docs: { story: { inline: false, height: '560px' } },
39
+ },
78
40
  tags: ['autodocs'],
79
- decorators: [
80
- (Story) => (
81
- <ChatConversationProvider chatId="storybook-chat">
82
- <div className="relative h-[480px] w-[700px] bg-paper-1">
83
- <Story />
84
- </div>
85
- </ChatConversationProvider>
86
- ),
87
- ],
41
+ // `ChatMessagesScrollButton` renders a tooltip, which needs a `TooltipProvider` above it.
42
+ decorators: [withTooltip],
88
43
  argTypes: {
89
44
  messageCount: {
90
45
  control: 'number',
@@ -107,178 +62,450 @@ const meta: Meta<typeof ChatMessages> = {
107
62
  description: 'Extra classes merged onto the root.',
108
63
  },
109
64
  },
110
- args: {
111
- messageCount: 0,
112
- gap: 16,
113
- },
114
65
  };
115
66
 
116
- function useGroupMessages(messages: DemoMessage[]) {
117
- return useMemo(() => {
118
- const groups: DemoMessage[][] = [];
119
-
120
- for (let i = 0; i < messages.length; i += 2) {
121
- groups.push(messages.slice(i, i + 2));
122
- }
123
-
124
- return groups;
125
- }, [messages]);
126
- }
127
-
128
67
  export default meta;
129
68
  type Story = StoryObj<typeof ChatMessages>;
130
69
 
70
+ /** A finished conversation in a fixed-height panel: one row per question with its answer, opened at the latest one. Raise `messageCount` to add the next question. */
131
71
  export const Default: Story = {
132
- render: () => {
133
- const [messages, setMessages] = useState(defaultMessages);
134
- const groupedMessages = useGroupMessages(messages);
135
-
136
- function handleAddMessage() {
137
- setMessages((currentMessages) => [
138
- ...currentMessages,
139
- addedMessages[currentMessages.length % addedMessages.length],
140
- ]);
141
- }
142
-
143
- return (
144
- <div className="flex h-full flex-col gap-12">
145
- <ChatMessages messageCount={groupedMessages.length} className="min-h-0">
146
- <ChatMessagesList className="px-16 py-16">
147
- {(groupIndex) => {
148
- const group = groupedMessages[groupIndex];
149
-
150
- return (
151
- <ChatMessageListGroup>
152
- {group.map((message, messageIndex) => (
153
- <ChatMessage
154
- key={`${groupIndex}-${messageIndex}`}
155
- isQuestion={message.isQuestion}
156
- >
157
- <ChatMessageContent>{message.text}</ChatMessageContent>
158
- </ChatMessage>
159
- ))}
160
- </ChatMessageListGroup>
161
- );
162
- }}
72
+ args: { messageCount: 4, gap: 16 },
73
+ argTypes: {
74
+ messageCount: { control: { type: 'number', min: 0, max: CONVERSATION.length } },
75
+ },
76
+ render: (args) => (
77
+ <ChatConversationProvider chatId="chat_spending_may">
78
+ <ConversationFrame>
79
+ <ChatMessages {...args}>
80
+ <ChatMessagesList className="p-16">
81
+ {(index) => (
82
+ <ChatMessageListGroup>
83
+ <ChatMessage isQuestion>
84
+ <ChatMessageContent>{CONVERSATION[index]?.question}</ChatMessageContent>
85
+ </ChatMessage>
86
+ <ChatMessage>
87
+ <ChatMessageContent>{CONVERSATION[index]?.answer}</ChatMessageContent>
88
+ </ChatMessage>
89
+ </ChatMessageListGroup>
90
+ )}
163
91
  </ChatMessagesList>
164
- <ChatMessagesScrollButton />
92
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
165
93
  </ChatMessages>
94
+ </ConversationFrame>
95
+ </ChatConversationProvider>
96
+ ),
97
+ };
166
98
 
167
- <button type="button" onClick={handleAddMessage}>
168
- Add message
169
- </button>
170
- </div>
171
- );
99
+ /** The viewport that scrolls the `role="log"` list. */
100
+ function getViewport(log: HTMLElement): HTMLElement {
101
+ const viewport = log.closest<HTMLElement>('[data-slot="chat-messages-viewport"]');
102
+
103
+ if (!viewport) {
104
+ throw new Error('The message list is not inside a chat-messages-viewport');
105
+ }
106
+
107
+ return viewport;
108
+ }
109
+
110
+ function distanceFromBottom(viewport: HTMLElement): number {
111
+ return viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;
112
+ }
113
+
114
+ /** Scrolls up through the history, which shows the scroll button, then clicks it to return to the end. */
115
+ export const DefaultScrollToLatest: Story = {
116
+ ...Default,
117
+ tags: ['e2e', '!autodocs'],
118
+ play: async ({ canvas, userEvent, step }) => {
119
+ const log = canvas.getByRole('log', { name: 'Message list' });
120
+ const viewport = getViewport(log);
121
+
122
+ await step('Opens at the latest question with the button hidden', async () => {
123
+ await waitFor(() => expect(distanceFromBottom(viewport)).toBeLessThanOrEqual(1));
124
+ await expect(within(log).getAllByRole('listitem')).toHaveLength(4);
125
+ await expect(canvas.getByText('Which subscriptions am I paying for?')).toBeVisible();
126
+ await expect(canvas.queryByRole('button', { name: SCROLL_TOOLTIP })).toBeNull();
127
+ });
128
+
129
+ await step('Scrolling up shows the button', async () => {
130
+ // A wheel event is what tells the list the reader took over; the scroll alone could be its own.
131
+ viewport.dispatchEvent(new WheelEvent('wheel', { deltaY: -240, bubbles: true }));
132
+ viewport.scrollTop = 0;
133
+
134
+ const button = await canvas.findByRole('button', { name: SCROLL_TOOLTIP });
135
+ await waitFor(() => expect(button).toBeVisible());
136
+ await expect(viewport.scrollTop).toBe(0);
137
+ });
138
+
139
+ await step('Clicking it returns to the end and hides it again', async () => {
140
+ await userEvent.click(canvas.getByRole('button', { name: SCROLL_TOOLTIP }));
141
+ await waitFor(() => expect(distanceFromBottom(viewport)).toBeLessThanOrEqual(1), {
142
+ timeout: 3000,
143
+ });
144
+ await waitFor(() =>
145
+ expect(canvas.queryByRole('button', { name: SCROLL_TOOLTIP })).toBeNull(),
146
+ );
147
+ });
172
148
  },
173
149
  };
174
150
 
175
- export const Streaming: Story = {
176
- render: () => {
177
- const [messages, setMessages] = useState<DemoMessage[]>([
178
- { isQuestion: true, text: streamingQuestions[0] },
179
- { isQuestion: false, text: streamingAnswers[0] },
180
- ]);
181
- const [activeAnswer, setActiveAnswer] = useState('');
182
- const streamIndexRef = useRef(0);
183
- const answerIndexRef = useRef(0);
184
- const activeAnswerRef = useRef('');
185
- const intervalRef = useRef<number | null>(null);
186
-
187
- function clearStreamInterval() {
188
- if (intervalRef.current === null) {
189
- return;
190
- }
151
+ const STREAM_STEP = 4;
152
+ const STREAM_INTERVAL_MS = 40;
191
153
 
192
- window.clearInterval(intervalRef.current);
193
- intervalRef.current = null;
194
- }
195
-
196
- useEffect(() => () => clearStreamInterval(), []);
154
+ interface AssistantConversationProps {
155
+ initialTurns: ConversationTurn[];
156
+ followUps: ConversationTurn[];
157
+ onAsk: (question: string) => void;
158
+ }
197
159
 
198
- function setStreamingAnswer(value: string) {
199
- activeAnswerRef.current = value;
200
- setActiveAnswer(value);
160
+ function AssistantConversation({ initialTurns, followUps, onAsk }: AssistantConversationProps) {
161
+ const [turns, setTurns] = useState(initialTurns);
162
+ const lastIndex = turns.length - 1;
163
+ const lastAnswer = turns[lastIndex]?.answer ?? '';
164
+ // How much of the last answer has arrived; earlier answers are complete.
165
+ const [streamedLength, setStreamedLength] = useState(lastAnswer.length);
166
+ const isStreaming = streamedLength < lastAnswer.length;
167
+
168
+ useEffect(() => {
169
+ if (!isStreaming) {
170
+ return undefined;
201
171
  }
202
172
 
203
- function startNextStream() {
204
- clearStreamInterval();
173
+ const interval = window.setInterval(() => {
174
+ setStreamedLength((length) => length + STREAM_STEP);
175
+ }, STREAM_INTERVAL_MS);
205
176
 
206
- const answer = streamingAnswers[answerIndexRef.current % streamingAnswers.length];
207
- streamIndexRef.current = 1;
208
- setStreamingAnswer(answer.slice(0, streamIndexRef.current));
177
+ return () => window.clearInterval(interval);
178
+ }, [isStreaming]);
209
179
 
210
- intervalRef.current = window.setInterval(() => {
211
- streamIndexRef.current += 3;
212
- const nextValue = answer.slice(0, streamIndexRef.current);
180
+ function handleAsk() {
181
+ const next = followUps[(turns.length - initialTurns.length) % followUps.length];
213
182
 
214
- setStreamingAnswer(nextValue);
215
-
216
- if (nextValue.length >= answer.length) {
217
- clearStreamInterval();
218
- }
219
- }, 40);
183
+ if (!next) {
184
+ return;
220
185
  }
221
186
 
222
- function finishCurrentStream() {
223
- if (!activeAnswerRef.current) {
224
- return;
225
- }
187
+ setTurns((currentTurns) => [...currentTurns, next]);
188
+ setStreamedLength(0);
189
+ onAsk(next.question);
190
+ }
191
+
192
+ return (
193
+ <ChatConversationProvider chatId="chat_spending_may">
194
+ <div className="flex flex-col items-start gap-12">
195
+ <ConversationFrame>
196
+ <ChatMessages messageCount={turns.length}>
197
+ <ChatMessagesList className="p-16">
198
+ {(index) => {
199
+ const turn = turns[index];
200
+
201
+ if (!turn) {
202
+ return null;
203
+ }
204
+
205
+ return (
206
+ <ConversationGroup
207
+ turn={
208
+ index === lastIndex
209
+ ? { ...turn, answer: turn.answer.slice(0, streamedLength) }
210
+ : turn
211
+ }
212
+ />
213
+ );
214
+ }}
215
+ </ChatMessagesList>
216
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
217
+ </ChatMessages>
218
+ </ConversationFrame>
219
+
220
+ <Button variant="secondary" onClick={handleAsk}>
221
+ Ask a follow-up
222
+ </Button>
223
+ </div>
224
+ </ChatConversationProvider>
225
+ );
226
+ }
226
227
 
227
- clearStreamInterval();
228
+ type StreamingStory = StoryObj<typeof AssistantConversation>;
228
229
 
229
- const answer = streamingAnswers[answerIndexRef.current % streamingAnswers.length];
230
+ /** A new question settles at the top of the view and its answer streams in below it, past the end of the viewport. */
231
+ export const Streaming: StreamingStory = {
232
+ args: {
233
+ initialTurns: CONVERSATION.slice(0, 1),
234
+ followUps: FOLLOW_UP_TURNS,
235
+ onAsk: fn(),
236
+ },
237
+ argTypes: {
238
+ initialTurns: { control: 'object', description: 'The turns the conversation opens with.' },
239
+ followUps: {
240
+ control: 'object',
241
+ description: 'The questions "Ask a follow-up" sends, in order, with their streamed answers.',
242
+ },
243
+ onAsk: { description: 'Called with the question that was sent.' },
244
+ },
245
+ render: (args) => <AssistantConversation {...args} />,
246
+ };
230
247
 
231
- setMessages((currentMessages) => [...currentMessages, { isQuestion: false, text: answer }]);
232
- setStreamingAnswer('');
233
- streamIndexRef.current = 0;
234
- answerIndexRef.current += 1;
235
- }
248
+ /** Sends a follow-up and checks that the new question's group fills the viewport and settles at its top. */
249
+ export const StreamingNewQuestion: StreamingStory = {
250
+ ...Streaming,
251
+ tags: ['e2e', '!autodocs'],
252
+ args: {
253
+ initialTurns: CONVERSATION.slice(0, 1),
254
+ followUps: FOLLOW_UP_TURNS,
255
+ onAsk: fn(),
256
+ },
257
+ play: async ({ args, canvas, userEvent, step }) => {
258
+ const log = canvas.getByRole('log', { name: 'Message list' });
259
+ const viewport = getViewport(log);
260
+ const question = 'Why was May so much more expensive than April?';
261
+
262
+ await step('Starts with one row', async () => {
263
+ await expect(within(log).getAllByRole('listitem')).toHaveLength(1);
264
+ });
265
+
266
+ await step('A follow-up adds a row for the new question', async () => {
267
+ await userEvent.click(canvas.getByRole('button', { name: 'Ask a follow-up' }));
268
+ await expect(args.onAsk).toHaveBeenCalledWith(question);
269
+ await expect(within(log).getAllByRole('listitem')).toHaveLength(2);
270
+ await expect(await canvas.findByText(question)).toBeVisible();
271
+ });
272
+
273
+ await step('The new group is as tall as the viewport and settles at its top', async () => {
274
+ const group = canvas.getByText(question).closest('[data-slot="chat-message-list-group"]');
275
+
276
+ if (!group) {
277
+ throw new Error('The question is not inside a ChatMessageListGroup');
278
+ }
236
279
 
237
- function handleAddMessage() {
238
- finishCurrentStream();
280
+ await expect(group).toHaveAttribute('data-is-last', 'true');
281
+ // The group's minimum height is the viewport's height minus one 16px gap.
282
+ await expect(group.getBoundingClientRect().height).toBeGreaterThanOrEqual(
283
+ viewport.clientHeight - 17,
284
+ );
285
+ await waitFor(
286
+ () =>
287
+ expect(
288
+ Math.abs(group.getBoundingClientRect().top - viewport.getBoundingClientRect().top),
289
+ ).toBeLessThanOrEqual(2),
290
+ { timeout: 3000 },
291
+ );
292
+ });
293
+
294
+ await step('The answer streams in below the question', async () => {
295
+ await expect(await canvas.findByText(/^May came to CHF 4,218\.40/)).toBeVisible();
296
+ });
297
+ },
298
+ };
239
299
 
240
- setMessages((currentMessages) => [
241
- ...currentMessages,
242
- { isQuestion: true, text: pickRandomItem(streamingQuestions) },
243
- ]);
300
+ /** The conversation in each place it's allowed: under its provider, in a canvas shell, in an assistant side panel and on a full-page chat. */
301
+ export const Examples: Story = {
302
+ parameters: {
303
+ controls: { disable: true },
304
+ docs: { story: { height: '860px' } },
305
+ },
306
+ render: () => (
307
+ <div className="grid gap-24 md:grid-cols-2">
308
+ <ParentBlock parent="web-chat-ui/ChatConversationProvider">
309
+ <ChatConversationProvider chatId="chat_spending_may">
310
+ <ConversationFrame className="h-90 max-w-none">
311
+ <ChatMessages messageCount={2}>
312
+ <ChatMessagesList className="p-16">
313
+ {(index) => {
314
+ const turn = CONVERSATION[index];
315
+
316
+ return turn ? <ConversationGroup turn={turn} /> : null;
317
+ }}
318
+ </ChatMessagesList>
319
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
320
+ </ChatMessages>
321
+ </ConversationFrame>
322
+ </ChatConversationProvider>
323
+ </ParentBlock>
324
+
325
+ <ParentBlock parent="web-chat-ui/CanvasShellContent">
326
+ <ChatConversationProvider chatId="chat_subscriptions">
327
+ <div className="h-90 rounded-10 border border-divider-border-base">
328
+ <CanvasShell>
329
+ <CanvasShellHeader>
330
+ <CanvasShellTitle>Subscriptions</CanvasShellTitle>
331
+ <CanvasShellCloseTrigger onClick={fn()} />
332
+ </CanvasShellHeader>
333
+ {/* The list scrolls itself and pads itself, so the shell does neither. */}
334
+ <CanvasShellContent hasScroll={false} hasPadding={false}>
335
+ <ChatMessages messageCount={FOLLOW_UP_TURNS.length - 1} className="h-full">
336
+ <ChatMessagesList className="px-16">
337
+ {(index) => {
338
+ const turn = FOLLOW_UP_TURNS[index + 1];
339
+
340
+ return turn ? <ConversationGroup turn={turn} /> : null;
341
+ }}
342
+ </ChatMessagesList>
343
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
344
+ </ChatMessages>
345
+ </CanvasShellContent>
346
+ </CanvasShell>
347
+ </div>
348
+ </ChatConversationProvider>
349
+ </ParentBlock>
350
+
351
+ <ParentBlock parent="assistant side panel">
352
+ <ChatConversationProvider chatId="chat_assistant_panel">
353
+ <aside
354
+ aria-label="Assistant"
355
+ className="flex h-90 max-w-90 flex-col border-l border-divider-border-base"
356
+ >
357
+ <Typography
358
+ variant="body-small-high"
359
+ fontWeight="medium"
360
+ className="border-b border-divider-border-base px-12 py-8"
361
+ >
362
+ Assistant
363
+ </Typography>
364
+ <ChatMessages messageCount={3} gap={12}>
365
+ <ChatMessagesList className="p-12">
366
+ {(index) => {
367
+ const turn = CONVERSATION[index + 2];
368
+
369
+ return turn ? <ConversationGroup turn={turn} /> : null;
370
+ }}
371
+ </ChatMessagesList>
372
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
373
+ </ChatMessages>
374
+ </aside>
375
+ </ChatConversationProvider>
376
+ </ParentBlock>
377
+
378
+ <ParentBlock parent="full-page chat">
379
+ <ChatConversationProvider chatId="chat_full_page">
380
+ <section aria-label="Chat" className="flex h-90 flex-col">
381
+ <ChatMessages messageCount={CONVERSATION.length} gap={24}>
382
+ {/* The list spans the page so the scrollbar sits at its edge; the column is centred. */}
383
+ <ChatMessagesList className="mx-auto w-full max-w-120 px-16 py-24">
384
+ {(index) => {
385
+ const turn = CONVERSATION[index];
386
+
387
+ return turn ? <ConversationGroup turn={turn} /> : null;
388
+ }}
389
+ </ChatMessagesList>
390
+ <ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
391
+ </ChatMessages>
392
+ </section>
393
+ </ChatConversationProvider>
394
+ </ParentBlock>
395
+ </div>
396
+ ),
397
+ };
244
398
 
245
- startNextStream();
246
- }
399
+ interface ChatMessagesPlaygroundProps extends Omit<ChatMessagesProps, 'children'> {
400
+ listClassName: string;
401
+ scrollAreaClassName: string;
402
+ viewportClassName: string;
403
+ bottomTriggerClassName: string;
404
+ hasScrollButton: boolean;
405
+ tooltip: string;
406
+ scrollButtonClassName: string;
407
+ buttonClassName: string;
408
+ icon: ReactNode;
409
+ }
247
410
 
248
- const visibleMessages = activeAnswer
249
- ? [...messages, { isQuestion: false, text: activeAnswer }]
250
- : messages;
251
-
252
- const groupedMessages = useGroupMessages(visibleMessages);
253
-
254
- return (
255
- <div className="flex h-full flex-col gap-12">
256
- <ChatMessages messageCount={groupedMessages.length} className="min-h-0">
257
- <ChatMessagesList className="px-16 py-16">
258
- {(groupIndex) => {
259
- const group = groupedMessages[groupIndex];
260
-
261
- return (
262
- <ChatMessageListGroup>
263
- {group.map((message, messageIndex) => (
264
- <ChatMessage
265
- key={`${groupIndex}-${messageIndex}`}
266
- isQuestion={message.isQuestion}
267
- >
268
- <ChatMessageContent>{message.text}</ChatMessageContent>
269
- </ChatMessage>
270
- ))}
271
- </ChatMessageListGroup>
272
- );
411
+ function ChatMessagesPlayground({
412
+ listClassName,
413
+ scrollAreaClassName,
414
+ viewportClassName,
415
+ bottomTriggerClassName,
416
+ hasScrollButton,
417
+ tooltip,
418
+ scrollButtonClassName,
419
+ buttonClassName,
420
+ icon,
421
+ ...rest
422
+ }: ChatMessagesPlaygroundProps) {
423
+ return (
424
+ <ChatConversationProvider chatId="chat_playground">
425
+ <ConversationFrame>
426
+ <ChatMessages {...rest}>
427
+ <ChatMessagesList
428
+ className={listClassName}
429
+ scrollAreaClassName={scrollAreaClassName}
430
+ viewportClassName={viewportClassName}
431
+ bottomTriggerClassName={bottomTriggerClassName}
432
+ >
433
+ {(index) => {
434
+ const turn = ALL_TURNS[index];
435
+
436
+ return turn ? <ConversationGroup turn={turn} /> : null;
273
437
  }}
274
438
  </ChatMessagesList>
275
- <ChatMessagesScrollButton />
439
+ {hasScrollButton && (
440
+ <ChatMessagesScrollButton
441
+ tooltip={tooltip}
442
+ className={scrollButtonClassName}
443
+ buttonClassName={buttonClassName}
444
+ >
445
+ {icon}
446
+ </ChatMessagesScrollButton>
447
+ )}
276
448
  </ChatMessages>
449
+ </ConversationFrame>
450
+ </ChatConversationProvider>
451
+ );
452
+ }
277
453
 
278
- <button type="button" onClick={handleAddMessage}>
279
- Add message
280
- </button>
281
- </div>
282
- );
454
+ /** Every part at once, with each prop of the root, the list and the scroll button on the Controls panel. */
455
+ export const Playground: StoryObj<typeof ChatMessagesPlayground> = {
456
+ tags: ['!autodocs'],
457
+ args: {
458
+ messageCount: ALL_TURNS.length,
459
+ gap: 16,
460
+ className: '',
461
+ listClassName: 'p-16',
462
+ scrollAreaClassName: '',
463
+ viewportClassName: '',
464
+ bottomTriggerClassName: '',
465
+ hasScrollButton: true,
466
+ tooltip: SCROLL_TOOLTIP,
467
+ scrollButtonClassName: '',
468
+ buttonClassName: '',
469
+ icon: 'Chevron (default)',
470
+ },
471
+ argTypes: {
472
+ messageCount: { control: { type: 'number', min: 0, max: ALL_TURNS.length } },
473
+ listClassName: {
474
+ control: 'text',
475
+ description: '`className` on `ChatMessagesList`: the padding and width of the list.',
476
+ },
477
+ scrollAreaClassName: {
478
+ control: 'text',
479
+ description: '`scrollAreaClassName` on `ChatMessagesList`: the scroll container.',
480
+ },
481
+ viewportClassName: {
482
+ control: 'text',
483
+ description: '`viewportClassName` on `ChatMessagesList`: the scrolling viewport.',
484
+ },
485
+ bottomTriggerClassName: {
486
+ control: 'text',
487
+ description:
488
+ '`bottomTriggerClassName` on `ChatMessagesList`: the hidden sentinel after the last row, e.g. `h-24` to count as "at the bottom" sooner.',
489
+ },
490
+ hasScrollButton: { control: 'boolean', description: 'Renders `ChatMessagesScrollButton`.' },
491
+ tooltip: {
492
+ control: 'text',
493
+ description: '`tooltip` on `ChatMessagesScrollButton`: its tooltip and accessible name.',
494
+ },
495
+ scrollButtonClassName: {
496
+ control: 'text',
497
+ description: '`className` on `ChatMessagesScrollButton`: the wrapper that positions it.',
498
+ },
499
+ buttonClassName: {
500
+ control: 'text',
501
+ description: '`buttonClassName` on `ChatMessagesScrollButton`: the icon button itself.',
502
+ },
503
+ icon: {
504
+ control: 'select',
505
+ options: ['Chevron (default)', 'Arrow'],
506
+ mapping: { 'Chevron (default)': undefined, Arrow: <ArrowDownIcon /> },
507
+ description: 'Children of `ChatMessagesScrollButton`; they replace the chevron.',
508
+ },
283
509
  },
510
+ render: (args) => <ChatMessagesPlayground {...args} />,
284
511
  };