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

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 (369) 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 +30 -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-input/plugins/controlled-value-plugin.d.ts +4 -1
  36. package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -1
  37. package/dist/components/chat-input/plugins/value-plugin.d.ts +4 -1
  38. package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -1
  39. package/dist/components/chat-list/chat-list-item.d.ts +6 -0
  40. package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
  41. package/dist/components/chat-list/chat-list-items.d.ts +12 -1
  42. package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
  43. package/dist/components/chat-list/chat-list.d.ts +36 -2
  44. package/dist/components/chat-list/chat-list.d.ts.map +1 -1
  45. package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
  46. package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
  47. package/dist/components/chat-message/chat-message.d.ts +12 -1
  48. package/dist/components/chat-message/chat-message.d.ts.map +1 -1
  49. package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
  50. package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
  51. package/dist/components/chat-message/index.d.ts +1 -1
  52. package/dist/components/chat-message/index.d.ts.map +1 -1
  53. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
  54. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
  55. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
  56. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
  57. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
  58. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
  59. package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
  60. package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
  61. package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
  62. package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
  63. package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
  64. package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
  65. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
  66. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
  67. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
  68. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
  69. package/dist/components/chat-message-toolbar/index.d.ts +1 -1
  70. package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
  71. package/dist/components/chat-messages/chat-messages.d.ts +34 -2
  72. package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
  73. package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
  74. package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
  75. package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
  76. package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
  77. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
  78. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
  79. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
  80. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
  81. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
  82. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
  83. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
  84. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
  85. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
  86. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
  87. package/dist/components/chat-reply/chat-reply.d.ts +11 -0
  88. package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
  89. package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
  90. package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
  91. package/dist/components/chat-reply/index.d.ts +1 -1
  92. package/dist/components/chat-reply/index.d.ts.map +1 -1
  93. package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
  94. package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
  95. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
  96. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
  97. package/dist/components/chat-suggestion/index.d.ts +2 -1
  98. package/dist/components/chat-suggestion/index.d.ts.map +1 -1
  99. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
  100. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  101. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
  102. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  103. package/dist/components/chat-thread/chat-thread.d.ts +17 -2
  104. package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
  105. package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
  106. package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
  107. package/dist/components/index.d.ts +1 -3
  108. package/dist/components/index.d.ts.map +1 -1
  109. package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
  110. package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
  111. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
  112. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
  113. package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +4 -1
  114. package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -1
  115. package/dist/components/rich-text-area/plugins/value-plugin.d.ts +4 -1
  116. package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -1
  117. package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
  118. package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
  119. package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
  120. package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
  121. package/dist/components/rich-text-area/styled.d.ts +6 -2
  122. package/dist/components/rich-text-area/styled.d.ts.map +1 -1
  123. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
  124. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
  125. package/dist/components/rich-text-field/components/index.d.ts +5 -5
  126. package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
  127. package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
  128. package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
  129. package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
  130. package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
  131. package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
  132. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  133. package/dist/components/topmenu/index.d.ts +2 -0
  134. package/dist/components/topmenu/index.d.ts.map +1 -0
  135. package/dist/components/topmenu/topmenu.d.ts +22 -0
  136. package/dist/components/topmenu/topmenu.d.ts.map +1 -0
  137. package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
  138. package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
  139. package/dist/docs/agent.stories.d.ts.map +1 -1
  140. package/dist/docs/chat-panel.d.ts +7 -5
  141. package/dist/docs/chat-panel.d.ts.map +1 -1
  142. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  143. package/dist/docs/chatbot.stories.d.ts.map +1 -1
  144. package/dist/index.css +1 -1
  145. package/dist/index.es.js +1801 -1806
  146. package/dist/index.es.js.map +1 -1
  147. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
  148. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
  149. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
  150. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
  151. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
  152. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
  153. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
  154. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
  155. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
  156. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
  157. package/package.json +16 -10
  158. package/src/__storybook__/parent-block.tsx +21 -0
  159. package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
  160. package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
  161. package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
  162. package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
  163. package/src/components/canvas-shell/__stories__/types.ts +47 -0
  164. package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
  165. package/src/components/canvas-shell/canvas-shell.json +24 -0
  166. package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
  167. package/src/components/canvas-shell/canvas-shell.tsx +44 -17
  168. package/src/components/chat-card/__stories__/fixtures.ts +119 -0
  169. package/src/components/chat-card/__stories__/types.ts +44 -0
  170. package/src/components/chat-card/chat-card.json +67 -3
  171. package/src/components/chat-card/chat-card.stories.tsx +872 -148
  172. package/src/components/chat-card/chat-card.tsx +2 -0
  173. package/src/components/chat-card/components/chat-card-body.tsx +12 -0
  174. package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
  175. package/src/components/chat-card/components/chat-card-form.tsx +21 -2
  176. package/src/components/chat-card/components/chat-card-header.tsx +39 -2
  177. package/src/components/chat-card/contexts.tsx +2 -0
  178. package/src/components/chat-card/hooks.ts +1 -0
  179. package/src/components/chat-card/types.ts +3 -0
  180. package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
  181. package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
  182. package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
  183. package/src/components/chat-card-container/__stories__/types.ts +16 -0
  184. package/src/components/chat-card-container/chat-card-container.json +7 -0
  185. package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
  186. package/src/components/chat-card-container/chat-card-container.tsx +5 -0
  187. package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
  188. package/src/components/chat-container/__stories__/fixtures.ts +27 -0
  189. package/src/components/chat-container/__stories__/measure.ts +22 -0
  190. package/src/components/chat-container/__stories__/types.ts +7 -0
  191. package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
  192. package/src/components/chat-container/chat-container.json +9 -1
  193. package/src/components/chat-container/chat-container.stories.tsx +538 -106
  194. package/src/components/chat-container/chat-container.tsx +3 -0
  195. package/src/components/chat-input/__stories__/fixtures.ts +31 -0
  196. package/src/components/chat-input/__tests__/chat-input.spec.tsx +100 -0
  197. package/src/components/chat-input/chat-input.json +11 -2
  198. package/src/components/chat-input/chat-input.stories.tsx +660 -197
  199. package/src/components/chat-input/chat-input.tsx +39 -5
  200. package/src/components/chat-input/plugins/controlled-value-plugin.tsx +16 -3
  201. package/src/components/chat-input/plugins/value-plugin.tsx +19 -4
  202. package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
  203. package/src/components/chat-list/__stories__/fixtures.ts +94 -0
  204. package/src/components/chat-list/__stories__/types.ts +13 -0
  205. package/src/components/chat-list/chat-list-item.tsx +6 -0
  206. package/src/components/chat-list/chat-list-items.tsx +16 -0
  207. package/src/components/chat-list/chat-list.json +24 -2
  208. package/src/components/chat-list/chat-list.stories.tsx +631 -215
  209. package/src/components/chat-list/chat-list.tsx +51 -4
  210. package/src/components/chat-message/__stories__/fixtures.ts +53 -0
  211. package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
  212. package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
  213. package/src/components/chat-message/chat-message.json +10 -1
  214. package/src/components/chat-message/chat-message.stories.tsx +282 -20
  215. package/src/components/chat-message/chat-message.tsx +16 -1
  216. package/src/components/chat-message/index.ts +8 -1
  217. package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
  218. package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
  219. package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
  220. package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
  221. package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
  222. package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
  223. package/src/components/chat-message-attachment-card/index.ts +6 -0
  224. package/src/components/chat-message-attachment-card/utils.ts +1 -0
  225. package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
  226. package/src/components/chat-message-response/chat-message-response.json +5 -0
  227. package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
  228. package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
  229. package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
  230. package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
  231. package/src/components/chat-message-toolbar/index.ts +4 -0
  232. package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
  233. package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
  234. package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
  235. package/src/components/chat-messages/__stories__/types.ts +5 -0
  236. package/src/components/chat-messages/chat-messages.json +30 -12
  237. package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
  238. package/src/components/chat-messages/chat-messages.tsx +46 -3
  239. package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
  240. package/src/components/chat-notification-card/__stories__/types.ts +13 -0
  241. package/src/components/chat-notification-card/chat-notification-card.json +52 -2
  242. package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
  243. package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
  244. package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
  245. package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
  246. package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
  247. package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
  248. package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
  249. package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
  250. package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
  251. package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
  252. package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
  253. package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
  254. package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
  255. package/src/components/chat-reply/chat-reply.json +10 -0
  256. package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
  257. package/src/components/chat-reply/chat-reply.tsx +15 -0
  258. package/src/components/chat-reply/index.ts +10 -1
  259. package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
  260. package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
  261. package/src/components/chat-suggestion/chat-suggestion.json +62 -20
  262. package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
  263. package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
  264. package/src/components/chat-suggestion/index.ts +9 -0
  265. package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
  266. package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
  267. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
  268. package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
  269. package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
  270. package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
  271. package/src/components/chat-thread/__stories__/snippets.ts +129 -0
  272. package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
  273. package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
  274. package/src/components/chat-thread/__stories__/types.ts +12 -0
  275. package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
  276. package/src/components/chat-thread/chat-thread.json +23 -3
  277. package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
  278. package/src/components/chat-thread/chat-thread.tsx +64 -16
  279. package/src/components/index.ts +1 -3
  280. package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
  281. package/src/components/markdown-viewer/markdown-viewer.json +7 -1
  282. package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
  283. package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
  284. package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
  285. package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +114 -0
  286. package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +20 -3
  287. package/src/components/rich-text-area/plugins/value-plugin.tsx +16 -3
  288. package/src/components/rich-text-area/rich-text-area.json +7 -4
  289. package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
  290. package/src/components/rich-text-area/rich-text-area.tsx +27 -4
  291. package/src/components/rich-text-area/styled.tsx +11 -5
  292. package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
  293. package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
  294. package/src/components/rich-text-field/components/index.ts +8 -5
  295. package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
  296. package/src/components/rich-text-field/rich-text-field.json +3 -1
  297. package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
  298. package/src/components/rich-text-field/rich-text-field.tsx +23 -0
  299. package/src/components/topmenu/index.ts +1 -0
  300. package/src/components/topmenu/topmenu.json +107 -0
  301. package/src/components/topmenu/topmenu.stories.tsx +334 -0
  302. package/src/components/topmenu/topmenu.tsx +71 -0
  303. package/src/docs/agent.stories.tsx +16 -16
  304. package/src/docs/chat-panel.tsx +37 -32
  305. package/src/docs/chatbot-panel.tsx +11 -2
  306. package/src/docs/chatbot.mdx +17 -12
  307. package/src/docs/chatbot.stories.tsx +7 -8
  308. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
  309. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
  310. package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
  311. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
  312. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
  313. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
  314. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
  315. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
  316. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
  317. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
  318. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
  319. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
  320. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
  321. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
  322. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
  323. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
  324. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
  325. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
  326. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
  327. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
  328. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
  329. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
  330. package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
  331. package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
  332. package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
  333. package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
  334. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
  335. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
  336. package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
  337. package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
  338. package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
  339. package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
  340. package/dist/components/card-item-picker/index.d.ts +0 -9
  341. package/dist/components/card-item-picker/index.d.ts.map +0 -1
  342. package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
  343. package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
  344. package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
  345. package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
  346. package/dist/components/chat-message-history/index.d.ts +0 -2
  347. package/dist/components/chat-message-history/index.d.ts.map +0 -1
  348. package/dist/components/spinner/index.d.ts +0 -2
  349. package/dist/components/spinner/index.d.ts.map +0 -1
  350. package/dist/components/spinner/spinner.d.ts +0 -9
  351. package/dist/components/spinner/spinner.d.ts.map +0 -1
  352. package/dist/components/spinner/spinner.stories.d.ts +0 -8
  353. package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
  354. package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
  355. package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
  356. package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
  357. package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
  358. package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
  359. package/src/components/card-item-picker/card-item-picker.json +0 -147
  360. package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
  361. package/src/components/card-item-picker/index.ts +0 -24
  362. package/src/components/chat-message-history/chat-message-history.json +0 -99
  363. package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
  364. package/src/components/chat-message-history/chat-message-history.tsx +0 -277
  365. package/src/components/chat-message-history/index.ts +0 -13
  366. package/src/components/spinner/index.ts +0 -1
  367. package/src/components/spinner/spinner.json +0 -73
  368. package/src/components/spinner/spinner.stories.tsx +0 -41
  369. package/src/components/spinner/spinner.tsx +0 -32
@@ -1,167 +1,42 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { useCallback, useEffect, useState } from 'react';
3
- import { fn } from 'storybook/test';
1
+ import type { Decorator, Meta, StoryObj } from '@storybook/react-vite';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { expect, fn, waitFor } from 'storybook/test';
4
4
 
5
- import { cn } from '@swisper.ai/web-core';
5
+ import { CloseIcon, NewChatIcon } from '@swisper.ai/icons';
6
+ import { IconButton, Typography } from '@swisper.ai/ui';
7
+
8
+ import { ParentBlock } from '../../__storybook__/parent-block';
9
+
10
+ import { ChatRow } from './__stories__/chat-row';
11
+ import {
12
+ ALL_CHATS_PAGE,
13
+ CHAT_PAGE_SIZE,
14
+ CHATS,
15
+ FIRST_CHAT_PAGE,
16
+ getChatPage,
17
+ NO_CHATS_PAGE,
18
+ SHORT_CHAT_PAGE,
19
+ } from './__stories__/fixtures';
20
+ import type { Chat, ChatPage } from './__stories__/types';
6
21
 
7
22
  import {
8
23
  ChatList,
9
24
  ChatListEmptyState,
10
25
  ChatListError,
11
- ChatListItem,
12
- type ChatListItemProps,
13
26
  ChatListItems,
14
27
  ChatListLoadMore,
28
+ type ChatListProps,
15
29
  ChatListSkeleton,
16
30
  } from './index';
17
31
 
18
- interface MockChat {
19
- id: string;
20
- title: string;
21
- preview: string;
22
- }
23
-
24
- const TOTAL_CHATS = 80;
25
- const PAGE_SIZE = 20;
26
-
27
- function createMockChats(count: number, offset = 0): MockChat[] {
28
- return Array.from({ length: count }, (_, index) => {
29
- const n = offset + index + 1;
30
-
31
- return {
32
- id: `chat-${n}`,
33
- title: `Conversation ${n}`,
34
- preview: `Last message preview for chat ${n}`,
35
- };
36
- });
37
- }
38
-
39
- function ListItem({
40
- chat: { title, preview },
41
- className,
42
- ...rest
43
- }: ChatListItemProps & { chat: MockChat; className?: string }) {
44
- return (
45
- <div
46
- className={cn(
47
- 'flex min-w-0 flex-1 flex-col gap-4',
48
- 'rounded-[12px] px-12 py-8',
49
- 'hover:bg-avatar-background-hover',
50
- 'data-[selected=true]:bg-avatar-background',
51
- className,
52
- )}
53
- {...rest}
54
- >
55
- <span className="truncate text-sm font-medium text-text-primary">{title}</span>
56
- <span className="truncate text-xs text-text-secondary">{preview}</span>
57
- </div>
58
- );
59
- }
60
-
61
- const ALL_CHATS = createMockChats(TOTAL_CHATS);
62
-
63
- function ChatListDemo({
64
- initialCount = PAGE_SIZE,
65
- totalCount = TOTAL_CHATS,
66
- isLoading = false,
67
- hasError = false,
68
- selectedId,
69
- }: {
70
- initialCount?: number;
71
- totalCount?: number;
72
- isLoading?: boolean;
73
- hasError?: boolean;
74
- selectedId?: string;
75
- }) {
76
- const [chats, setChats] = useState(() => ALL_CHATS.slice(0, initialCount));
77
- const [isLoadingMore, setIsLoadingMore] = useState(false);
78
- const [selected, setSelected] = useState(selectedId);
79
-
80
- const getItemKey = useCallback((index: number) => chats[index].id, [chats]);
81
-
82
- const handleLoadMore = useCallback(() => {
83
- if (isLoadingMore || chats.length >= totalCount) {
84
- return;
85
- }
86
-
87
- setIsLoadingMore(true);
88
-
89
- window.setTimeout(() => {
90
- setChats((current) => {
91
- const next = ALL_CHATS.slice(current.length, current.length + PAGE_SIZE);
92
- return [...current, ...next];
93
- });
94
- setIsLoadingMore(false);
95
- }, 600);
96
- }, [chats.length, isLoadingMore, totalCount]);
97
-
98
- return (
99
- <ChatList
100
- className="h-full"
101
- loadedCount={chats.length}
102
- totalCount={totalCount}
103
- isLoading={isLoading}
104
- isLoadingMore={isLoadingMore}
105
- hasError={hasError}
106
- onLoadMore={handleLoadMore}
107
- getItemKey={getItemKey}
108
- >
109
- <ChatListItems>
110
- {(index) => {
111
- const chat = chats[index];
112
-
113
- return (
114
- <ChatListItem
115
- isSelected={selected === chat.id}
116
- onClick={() => setSelected(chat.id)}
117
- asChild
118
- >
119
- <ListItem chat={chat} />
120
- </ChatListItem>
121
- );
122
- }}
123
- </ChatListItems>
124
-
125
- <ChatListSkeleton />
126
-
127
- <ChatListLoadMore>
128
- <div className="flex items-center justify-center py-3 text-xs text-text-secondary">
129
- Loading more…
130
- </div>
131
- </ChatListLoadMore>
132
-
133
- <ChatListEmptyState>
134
- <div className="flex flex-col items-center gap-2 px-6 text-center">
135
- <p className="text-sm font-medium text-text-primary">No conversations yet</p>
136
- <p className="text-xs text-text-secondary">Start a new chat to see it here.</p>
137
- </div>
138
- </ChatListEmptyState>
139
-
140
- <ChatListError>
141
- <div className="flex flex-col items-center gap-2 px-6 text-center">
142
- <p className="text-sm font-medium text-text-error-main">Failed to load chats</p>
143
- <p className="text-xs text-text-secondary">Please try again later.</p>
144
- </div>
145
- </ChatListError>
146
- </ChatList>
147
- );
148
- }
149
-
150
32
  const meta: Meta<typeof ChatList> = {
151
- title: 'Chatbot/ChatList',
33
+ title: 'Chat/ChatList',
152
34
  component: ChatList,
153
35
  parameters: { layout: 'padded' },
154
36
  tags: ['autodocs'],
155
- decorators: [
156
- (Story) => (
157
- <div className="relative h-[480px] w-[320px] overflow-hidden bg-paper-elevation-2">
158
- <Story />
159
- </div>
160
- ),
161
- ],
162
37
  argTypes: {
163
38
  loadedCount: {
164
- control: { type: 'number', min: 0 },
39
+ control: { type: 'number', min: 0, max: CHATS.length },
165
40
  description: 'Number of chats already loaded; `ChatListItems` renders this many rows.',
166
41
  },
167
42
  totalCount: {
@@ -176,17 +51,19 @@ const meta: Meta<typeof ChatList> = {
176
51
  },
177
52
  isLoading: {
178
53
  control: 'boolean',
179
- description: 'First page is loading: shows `ChatListSkeleton` instead of the rows.',
54
+ description:
55
+ 'First page is loading: with no chats loaded, shows `ChatListSkeleton` instead of the rows.',
180
56
  table: { defaultValue: { summary: 'false' } },
181
57
  },
182
58
  isLoadingMore: {
183
59
  control: 'boolean',
184
- description: 'The next page is loading: shows `ChatListLoadMore` under the rows.',
60
+ description:
61
+ 'The next page is loading: marks the load-more row busy and holds `onLoadMore` back.',
185
62
  table: { defaultValue: { summary: 'false' } },
186
63
  },
187
64
  hasError: {
188
65
  control: 'boolean',
189
- description: 'Loading failed: shows `ChatListError` instead of the rows.',
66
+ description: 'Loading failed: with no chats loaded, shows `ChatListError`.',
190
67
  table: { defaultValue: { summary: 'false' } },
191
68
  },
192
69
  onLoadMore: {
@@ -212,76 +89,124 @@ const meta: Meta<typeof ChatList> = {
212
89
  description: 'Extra classes merged onto the root.',
213
90
  },
214
91
  },
215
- args: {
216
- loadedCount: PAGE_SIZE,
217
- totalCount: TOTAL_CHATS,
218
- isLoading: false,
219
- isLoadingMore: false,
220
- hasError: false,
221
- onLoadMore: fn(),
222
- 'aria-label': 'Chat list',
223
- },
224
92
  };
225
93
 
226
94
  export default meta;
227
- type Story = StoryObj<typeof ChatList>;
228
95
 
229
- export const Playground: Story = {
230
- render: () => <ChatListDemo selectedId="chat-1" />,
231
- };
232
-
233
- export const Empty: Story = {
234
- render: () => <ChatListDemo initialCount={0} totalCount={0} />,
235
- };
96
+ function delay(ms: number) {
97
+ return new Promise<void>((resolve) => setTimeout(resolve, ms));
98
+ }
236
99
 
237
- export const ErrorState: Story = {
238
- render: () => <ChatListDemo initialCount={0} totalCount={0} hasError />,
239
- };
100
+ /** A request that stays in flight, to hold a loading state on screen. */
101
+ function pending() {
102
+ return new Promise<ChatPage>(() => {});
103
+ }
240
104
 
241
- export const InitialSkeleton: Story = {
242
- render: () => <ChatListDemo initialCount={0} isLoading />,
243
- };
105
+ // The list fills its parent, so every story gives it a column the size of a sidebar.
106
+ const sidebarFrame: Decorator = (Story) => (
107
+ <div className="h-120 w-80 overflow-hidden bg-paper-elevation-2">
108
+ <Story />
109
+ </div>
110
+ );
111
+
112
+ interface SidebarChatListProps {
113
+ /** The first page when it is already cached. Leave it out to request it with `onLoadPage`. */
114
+ initialPage?: ChatPage;
115
+ pageSize: number;
116
+ initialChatId?: string;
117
+ className?: string;
118
+ 'aria-label'?: string;
119
+ onLoadPage: (offset: number, limit: number) => Promise<ChatPage>;
120
+ onOpenChat: (chatId: string) => void;
121
+ }
244
122
 
245
- function ChatListInitialLongLoadDemo({ delayMs = 30_000 }: { delayMs?: number }) {
246
- const [chats, setChats] = useState<MockChat[]>([]);
247
- const [isLoading, setIsLoading] = useState(true);
123
+ function SidebarChatList({
124
+ initialPage,
125
+ pageSize,
126
+ initialChatId,
127
+ className,
128
+ 'aria-label': ariaLabel,
129
+ onLoadPage,
130
+ onOpenChat,
131
+ }: SidebarChatListProps) {
132
+ const [chats, setChats] = useState<Chat[]>(initialPage?.chats ?? []);
133
+ const [totalCount, setTotalCount] = useState(initialPage?.count);
134
+ const [status, setStatus] = useState<'pending' | 'success' | 'error'>(
135
+ initialPage ? 'success' : 'pending',
136
+ );
248
137
  const [isLoadingMore, setIsLoadingMore] = useState(false);
249
- const [selected, setSelected] = useState<string>();
138
+ const [currentChatId, setCurrentChatId] = useState(initialChatId);
250
139
 
251
140
  useEffect(() => {
252
- const timeoutId = window.setTimeout(() => {
253
- setChats(ALL_CHATS.slice(0, PAGE_SIZE));
254
- setIsLoading(false);
255
- }, delayMs);
141
+ if (initialPage) {
142
+ return;
143
+ }
256
144
 
257
- return () => window.clearTimeout(timeoutId);
258
- }, [delayMs]);
145
+ let isCurrent = true;
146
+
147
+ onLoadPage(0, pageSize).then(
148
+ (page) => {
149
+ if (isCurrent) {
150
+ setChats(page.chats);
151
+ setTotalCount(page.count);
152
+ setStatus('success');
153
+ }
154
+ },
155
+ () => {
156
+ if (isCurrent) {
157
+ setStatus('error');
158
+ }
159
+ },
160
+ );
161
+
162
+ return () => {
163
+ isCurrent = false;
164
+ };
165
+ }, [initialPage, onLoadPage, pageSize]);
259
166
 
260
- const getItemKey = useCallback((index: number) => chats[index].id, [chats]);
167
+ // `onLoadMore` can fire again before `isLoadingMore` reaches the list, so the request guards itself.
168
+ const isRequestingRef = useRef(false);
261
169
 
262
170
  const handleLoadMore = useCallback(() => {
263
- if (isLoadingMore || chats.length >= TOTAL_CHATS) {
171
+ if (isRequestingRef.current) {
264
172
  return;
265
173
  }
266
174
 
175
+ isRequestingRef.current = true;
267
176
  setIsLoadingMore(true);
268
177
 
269
- window.setTimeout(() => {
270
- setChats((current) => {
271
- const next = ALL_CHATS.slice(current.length, current.length + PAGE_SIZE);
272
- return [...current, ...next];
178
+ onLoadPage(chats.length, pageSize)
179
+ .then(
180
+ (page) => {
181
+ setChats((current) => [...current, ...page.chats]);
182
+ setTotalCount(page.count);
183
+ },
184
+ // The loaded chats stay; `hasMore` turns false below, so the list stops asking.
185
+ () => setStatus('error'),
186
+ )
187
+ .finally(() => {
188
+ isRequestingRef.current = false;
189
+ setIsLoadingMore(false);
273
190
  });
274
- setIsLoadingMore(false);
275
- }, 600);
276
- }, [chats.length, isLoadingMore]);
191
+ }, [chats.length, onLoadPage, pageSize]);
192
+
193
+ const getItemKey = useCallback((index: number) => chats[index].chatId, [chats]);
194
+
195
+ const handleOpenChat = (chatId: string) => {
196
+ setCurrentChatId(chatId);
197
+ onOpenChat(chatId);
198
+ };
277
199
 
278
200
  return (
279
201
  <ChatList
280
- className="h-full"
202
+ className={className ?? 'h-full'}
203
+ aria-label={ariaLabel}
281
204
  loadedCount={chats.length}
282
- totalCount={TOTAL_CHATS}
283
- isLoading={isLoading}
205
+ totalCount={totalCount}
206
+ hasMore={status === 'success' && totalCount != null && chats.length < totalCount}
207
+ isLoading={status === 'pending'}
284
208
  isLoadingMore={isLoadingMore}
209
+ hasError={status === 'error'}
285
210
  onLoadMore={handleLoadMore}
286
211
  getItemKey={getItemKey}
287
212
  >
@@ -290,43 +215,534 @@ function ChatListInitialLongLoadDemo({ delayMs = 30_000 }: { delayMs?: number })
290
215
  const chat = chats[index];
291
216
 
292
217
  return (
293
- <ChatListItem
294
- isSelected={selected === chat.id}
295
- onClick={() => setSelected(chat.id)}
296
- asChild
297
- >
298
- <ListItem chat={chat} />
299
- </ChatListItem>
218
+ <ChatRow
219
+ chat={chat}
220
+ isSelected={chat.chatId === currentChatId}
221
+ onOpen={handleOpenChat}
222
+ />
300
223
  );
301
224
  }}
302
225
  </ChatListItems>
303
226
 
304
- <ChatListSkeleton />
227
+ <ChatListSkeleton rows={pageSize} />
305
228
 
306
229
  <ChatListLoadMore>
307
- <div className="flex items-center justify-center py-3 text-xs text-text-secondary">
230
+ <Typography variant="caption-md" className="block py-12 text-center text-text-secondary">
308
231
  Loading more…
309
- </div>
232
+ </Typography>
310
233
  </ChatListLoadMore>
311
234
 
312
- <ChatListEmptyState>
313
- <div className="flex flex-col items-center gap-2 px-6 text-center">
314
- <p className="text-sm font-medium text-text-primary">No conversations yet</p>
315
- <p className="text-xs text-text-secondary">Start a new chat to see it here.</p>
235
+ {/* The rows keep their share of the height even when there are none, so the empty and
236
+ error states cover the root to sit in its middle. */}
237
+ <ChatListEmptyState className="absolute inset-0">
238
+ <div className="flex flex-col items-center gap-8 px-24 text-center">
239
+ <Typography variant="body-small-high">No conversations yet</Typography>
240
+ <Typography variant="caption-md" className="text-text-secondary">
241
+ Start a new chat to see it here.
242
+ </Typography>
316
243
  </div>
317
244
  </ChatListEmptyState>
245
+
246
+ <ChatListError className="absolute inset-0">
247
+ <div className="flex flex-col items-center gap-8 px-24 text-center">
248
+ <Typography variant="body-small-high" className="text-text-error-main">
249
+ Failed to load chats
250
+ </Typography>
251
+ <Typography variant="caption-md" className="text-text-secondary">
252
+ Please try again later.
253
+ </Typography>
254
+ </div>
255
+ </ChatListError>
318
256
  </ChatList>
319
257
  );
320
258
  }
321
259
 
322
- export const InitialLongLoad: Story = {
323
- render: () => <ChatListInitialLongLoadDemo />,
260
+ type SidebarStory = StoryObj<typeof SidebarChatList>;
261
+
262
+ // The consumer keeps the root's props in state, so the Controls panel has nothing to drive here;
263
+ // `Playground` puts every prop on it.
264
+ const sidebarStory = {
265
+ decorators: [sidebarFrame],
266
+ parameters: { controls: { disable: true } },
267
+ render: (args) => <SidebarChatList {...args} />,
268
+ } satisfies SidebarStory;
269
+
270
+ /** The first page of a chat history with the open chat marked; scrolling to the end loads the next page. */
271
+ export const Default: SidebarStory = {
272
+ ...sidebarStory,
273
+ args: {
274
+ initialPage: FIRST_CHAT_PAGE,
275
+ pageSize: CHAT_PAGE_SIZE,
276
+ initialChatId: CHATS[1].chatId,
277
+ onLoadPage: fn(async (offset: number, limit: number) => {
278
+ await delay(600);
279
+ return getChatPage(offset, limit);
280
+ }),
281
+ onOpenChat: fn(),
282
+ },
324
283
  };
325
284
 
326
- export const LoadingMore: Story = {
327
- render: () => <ChatListDemo initialCount={PAGE_SIZE} totalCount={TOTAL_CHATS} />,
285
+ /** A new account with no chats: the empty state says so and how to start one. */
286
+ export const Empty: SidebarStory = {
287
+ ...sidebarStory,
288
+ args: {
289
+ initialPage: NO_CHATS_PAGE,
290
+ pageSize: CHAT_PAGE_SIZE,
291
+ onLoadPage: fn(async () => NO_CHATS_PAGE),
292
+ onOpenChat: fn(),
293
+ },
294
+ };
295
+
296
+ /** The first page fails: the error replaces the skeleton and says what to do next. */
297
+ export const ErrorState: SidebarStory = {
298
+ ...sidebarStory,
299
+ args: {
300
+ pageSize: CHAT_PAGE_SIZE,
301
+ onLoadPage: fn(async () => {
302
+ await delay(300);
303
+ throw new Error('Network error');
304
+ }),
305
+ onOpenChat: fn(),
306
+ },
307
+ };
308
+
309
+ /** The first page is on its way: skeleton rows hold the place of the chats. */
310
+ export const InitialSkeleton: SidebarStory = {
311
+ ...sidebarStory,
312
+ args: {
313
+ pageSize: CHAT_PAGE_SIZE,
314
+ onLoadPage: fn(pending),
315
+ onOpenChat: fn(),
316
+ },
317
+ };
318
+
319
+ /** A slow first page: the skeleton stays for 30 seconds, then the chats take its place. */
320
+ export const InitialLongLoad: SidebarStory = {
321
+ ...sidebarStory,
322
+ args: {
323
+ pageSize: CHAT_PAGE_SIZE,
324
+ onLoadPage: fn(async (offset: number, limit: number) => {
325
+ await delay(offset === 0 ? 30_000 : 600);
326
+ return getChatPage(offset, limit);
327
+ }),
328
+ onOpenChat: fn(),
329
+ },
330
+ };
331
+
332
+ /** The next page is on its way: the load-more row sits under the loaded chats. */
333
+ export const LoadingMore: SidebarStory = {
334
+ ...sidebarStory,
335
+ args: {
336
+ initialPage: SHORT_CHAT_PAGE,
337
+ pageSize: CHAT_PAGE_SIZE,
338
+ onLoadPage: fn(pending),
339
+ onOpenChat: fn(),
340
+ },
341
+ };
342
+
343
+ /** Every chat loaded: 80 rows scroll smoothly because only the ones in view are rendered. */
344
+ export const LongList: SidebarStory = {
345
+ ...sidebarStory,
346
+ args: {
347
+ initialPage: ALL_CHATS_PAGE,
348
+ pageSize: CHAT_PAGE_SIZE,
349
+ initialChatId: CHATS[0].chatId,
350
+ onLoadPage: fn(async (offset: number, limit: number) => getChatPage(offset, limit)),
351
+ onOpenChat: fn(),
352
+ },
353
+ };
354
+
355
+ /** The list in each place it's allowed: a sidebar and a navigation drawer. */
356
+ export const Examples: SidebarStory = {
357
+ parameters: { controls: { disable: true } },
358
+ args: {
359
+ initialPage: FIRST_CHAT_PAGE,
360
+ pageSize: CHAT_PAGE_SIZE,
361
+ initialChatId: CHATS[1].chatId,
362
+ onLoadPage: fn(async (offset: number, limit: number) => {
363
+ await delay(600);
364
+ return getChatPage(offset, limit);
365
+ }),
366
+ onOpenChat: fn(),
367
+ },
368
+ render: (args) => (
369
+ <div className="flex flex-col gap-24">
370
+ <ParentBlock parent="sidebar">
371
+ <aside
372
+ aria-label="Sidebar"
373
+ className="flex h-100 w-80 flex-col gap-8 border-r border-side-menu-border bg-side-menu-background py-12"
374
+ >
375
+ <div className="flex items-center justify-between pr-12 pl-24">
376
+ <Typography variant="title-x-small">Chats</Typography>
377
+ <IconButton variant="tertiary" size="md" aria-label="Start a new chat">
378
+ <NewChatIcon />
379
+ </IconButton>
380
+ </div>
381
+ <SidebarChatList {...args} className="px-12" aria-label="Chat list" />
382
+ </aside>
383
+ </ParentBlock>
384
+
385
+ <ParentBlock parent="navigation drawer">
386
+ <aside
387
+ aria-label="Navigation drawer"
388
+ className="flex h-100 w-72 flex-col gap-8 rounded-r-lg border border-side-menu-border bg-side-menu-background-floating py-12"
389
+ >
390
+ <div className="flex items-center justify-between pr-12 pl-24">
391
+ <Typography variant="title-x-small">Chats</Typography>
392
+ <IconButton variant="tertiary" size="md" aria-label="Close menu">
393
+ <CloseIcon />
394
+ </IconButton>
395
+ </div>
396
+ <SidebarChatList {...args} className="px-12" aria-label="Chat list in the drawer" />
397
+ </aside>
398
+ </ParentBlock>
399
+ </div>
400
+ ),
401
+ };
402
+
403
+ function scrollToLastRow(rows: HTMLElement[]) {
404
+ rows[rows.length - 1]?.scrollIntoView();
405
+ }
406
+
407
+ /** Scrolls to the end of the loaded chats and checks the next page is requested and appended. */
408
+ export const DefaultLoadsNextPage: SidebarStory = {
409
+ ...Default,
410
+ tags: ['e2e', '!autodocs'],
411
+ args: {
412
+ ...Default.args,
413
+ onLoadPage: fn(async (offset: number, limit: number) => {
414
+ await delay(300);
415
+ return getChatPage(offset, limit);
416
+ }),
417
+ onOpenChat: fn(),
418
+ },
419
+ play: async ({ args, canvas, step }) => {
420
+ await step('Asks for the second page while the first still fills the view', async () => {
421
+ await waitFor(() =>
422
+ expect(args.onLoadPage).toHaveBeenCalledWith(CHAT_PAGE_SIZE, CHAT_PAGE_SIZE),
423
+ );
424
+ await expect(
425
+ canvas.getByRole('link', { name: new RegExp(CHATS[0].title) }),
426
+ ).toBeInTheDocument();
427
+ });
428
+
429
+ await step('Scrolling to the last loaded chat asks for the third page', async () => {
430
+ await waitFor(async () => {
431
+ scrollToLastRow(canvas.getAllByRole('link'));
432
+ await expect(args.onLoadPage).toHaveBeenCalledWith(CHAT_PAGE_SIZE * 2, CHAT_PAGE_SIZE);
433
+ });
434
+ });
435
+
436
+ await step('The third page is appended under the loaded chats', async () => {
437
+ // Each older chat was updated on its own day, so the date finds one row of the third page.
438
+ await waitFor(async () => {
439
+ scrollToLastRow(canvas.getAllByRole('link'));
440
+ await expect(canvas.getByText(CHATS[CHAT_PAGE_SIZE * 2].updatedAt)).toBeVisible();
441
+ });
442
+ });
443
+ },
444
+ };
445
+
446
+ /** Opens a chat with a click and another with the keyboard, checking which row is marked current. */
447
+ export const DefaultOpensAChat: SidebarStory = {
448
+ ...Default,
449
+ tags: ['e2e', '!autodocs'],
450
+ args: { ...Default.args, onOpenChat: fn() },
451
+ play: async ({ args, canvas, userEvent, step }) => {
452
+ const first = canvas.getByRole('link', { name: new RegExp(CHATS[0].title) });
453
+ const second = canvas.getByRole('link', { name: new RegExp(CHATS[1].title) });
454
+ const fourth = canvas.getByRole('link', { name: new RegExp(CHATS[3].title) });
455
+
456
+ await step('Starts with the open chat marked as the current page', async () => {
457
+ await expect(second).toHaveAttribute('aria-current', 'page');
458
+ await expect(first).not.toHaveAttribute('aria-current');
459
+ });
460
+
461
+ await step('A click opens another chat and moves the mark', async () => {
462
+ await userEvent.click(fourth);
463
+ await expect(args.onOpenChat).toHaveBeenLastCalledWith(CHATS[3].chatId);
464
+ await expect(fourth).toHaveAttribute('aria-current', 'page');
465
+ await expect(second).not.toHaveAttribute('aria-current');
466
+ });
467
+
468
+ await step('Enter on a focused row opens it', async () => {
469
+ first.focus();
470
+ await expect(first).toHaveFocus();
471
+ await userEvent.keyboard('{Enter}');
472
+ await expect(args.onOpenChat).toHaveBeenLastCalledWith(CHATS[0].chatId);
473
+ await expect(first).toHaveAttribute('aria-current', 'page');
474
+ });
475
+
476
+ await step('Tab moves to the next row', async () => {
477
+ await userEvent.tab();
478
+ await expect(second).toHaveFocus();
479
+ });
480
+ },
481
+ };
482
+
483
+ /** With nothing loaded, only the empty state is announced: no skeleton, no error, no rows. */
484
+ export const EmptyAnnouncesNoChats: SidebarStory = {
485
+ ...Empty,
486
+ tags: ['e2e', '!autodocs'],
487
+ play: async ({ canvas }) => {
488
+ const emptyState = canvas.getByRole('status', { name: 'No chats' });
489
+
490
+ await expect(emptyState).toBeVisible();
491
+ await expect(emptyState).toHaveTextContent('No conversations yet');
492
+ await expect(canvas.queryByRole('status', { name: 'Loading chats' })).toBeNull();
493
+ await expect(canvas.queryByRole('alert')).toBeNull();
494
+ await expect(canvas.queryByRole('link')).toBeNull();
495
+ },
496
+ };
497
+
498
+ /** The skeleton shows while the first page loads; when it fails, the alert takes its place. */
499
+ export const ErrorStateShowsAlert: SidebarStory = {
500
+ ...ErrorState,
501
+ tags: ['e2e', '!autodocs'],
502
+ args: {
503
+ ...ErrorState.args,
504
+ onLoadPage: fn(async () => {
505
+ await delay(300);
506
+ throw new Error('Network error');
507
+ }),
508
+ },
509
+ play: async ({ args, canvas, step }) => {
510
+ await step('Shows the skeleton while the request is in flight', async () => {
511
+ await expect(await canvas.findByRole('status', { name: 'Loading chats' })).toBeVisible();
512
+ await expect(args.onLoadPage).toHaveBeenCalledWith(0, CHAT_PAGE_SIZE);
513
+ });
514
+
515
+ await step('Replaces it with the error when the request fails', async () => {
516
+ const alert = await canvas.findByRole('alert', { name: 'Error loading chats' });
517
+
518
+ await expect(alert).toHaveTextContent('Failed to load chats');
519
+ await expect(alert).toHaveTextContent('Please try again later.');
520
+ await expect(canvas.queryByRole('status', { name: 'Loading chats' })).toBeNull();
521
+ await expect(canvas.queryByRole('status', { name: 'No chats' })).toBeNull();
522
+ });
523
+ },
328
524
  };
329
525
 
330
- export const LongList: Story = {
331
- render: () => <ChatListDemo initialCount={TOTAL_CHATS} totalCount={TOTAL_CHATS} />,
526
+ /** While the first page loads, the skeleton is a busy status region and no rows or empty state show. */
527
+ export const InitialSkeletonAnnouncesLoading: SidebarStory = {
528
+ ...InitialSkeleton,
529
+ tags: ['e2e', '!autodocs'],
530
+ args: { ...InitialSkeleton.args, onLoadPage: fn(pending) },
531
+ play: async ({ args, canvas }) => {
532
+ const skeleton = await canvas.findByRole('status', { name: 'Loading chats' });
533
+
534
+ await expect(skeleton).toBeVisible();
535
+ await expect(skeleton).toHaveAttribute('aria-busy', 'true');
536
+ await expect(args.onLoadPage).toHaveBeenCalledWith(0, CHAT_PAGE_SIZE);
537
+ await expect(canvas.queryByRole('link')).toBeNull();
538
+ await expect(canvas.queryByRole('status', { name: 'No chats' })).toBeNull();
539
+ },
540
+ };
541
+
542
+ /** While the next page loads, the loaded chats stay and the load-more row is a busy status under them. */
543
+ export const LoadingMoreKeepsRows: SidebarStory = {
544
+ ...LoadingMore,
545
+ tags: ['e2e', '!autodocs'],
546
+ args: { ...LoadingMore.args, onLoadPage: fn(pending) },
547
+ play: async ({ args, canvas }) => {
548
+ const loadMore = await canvas.findByText('Loading more…');
549
+
550
+ await expect(loadMore).toBeVisible();
551
+ await waitFor(() =>
552
+ expect(loadMore.closest('[role="status"]')).toHaveAttribute('aria-busy', 'true'),
553
+ );
554
+ await expect(args.onLoadPage).toHaveBeenCalledWith(
555
+ SHORT_CHAT_PAGE.chats.length,
556
+ CHAT_PAGE_SIZE,
557
+ );
558
+ await expect(canvas.getAllByRole('link')).toHaveLength(SHORT_CHAT_PAGE.chats.length);
559
+ },
560
+ };
561
+
562
+ /** A later page fails: the loaded chats stay on screen, no error replaces them and the list stops asking. */
563
+ export const LaterPageFailureKeepsRows: SidebarStory = {
564
+ ...sidebarStory,
565
+ tags: ['e2e', '!autodocs'],
566
+ args: {
567
+ initialPage: SHORT_CHAT_PAGE,
568
+ pageSize: CHAT_PAGE_SIZE,
569
+ onLoadPage: fn(async () => {
570
+ await delay(300);
571
+ throw new Error('Network error');
572
+ }),
573
+ onOpenChat: fn(),
574
+ },
575
+ play: async ({ args, canvas }) => {
576
+ await expect(await canvas.findByText('Loading more…')).toBeVisible();
577
+ await waitFor(() => expect(canvas.queryByText('Loading more…')).toBeNull());
578
+
579
+ await expect(canvas.getAllByRole('link')).toHaveLength(SHORT_CHAT_PAGE.chats.length);
580
+ await expect(canvas.queryByRole('alert')).toBeNull();
581
+
582
+ const callCount = (args.onLoadPage as ReturnType<typeof fn>).mock.calls.length;
583
+ await delay(400);
584
+ await expect(args.onLoadPage).toHaveBeenCalledTimes(callCount);
585
+ },
586
+ };
587
+
588
+ interface ChatListPlaygroundProps extends Omit<ChatListProps, 'children' | 'getItemKey'> {
589
+ /** Position of the open chat in the list, from 1; 0 marks none. */
590
+ selectedPosition: number;
591
+ hasSkeleton: boolean;
592
+ hasLoadMore: boolean;
593
+ hasEmptyState: boolean;
594
+ hasErrorState: boolean;
595
+ /** `rows` on `ChatListSkeleton`. */
596
+ rows: number;
597
+ /** `estimateSize`, `overscan` and `gap` on `ChatListItems`. */
598
+ estimateSize: number;
599
+ overscan: number;
600
+ gap: number;
601
+ loadMoreLabel: string;
602
+ emptyTitle: string;
603
+ emptyDescription: string;
604
+ errorTitle: string;
605
+ errorDescription: string;
606
+ onOpenChat: (chatId: string) => void;
607
+ }
608
+
609
+ function getChatKey(index: number) {
610
+ return CHATS[index].chatId;
611
+ }
612
+
613
+ function ChatListPlayground({
614
+ loadedCount,
615
+ selectedPosition,
616
+ hasSkeleton,
617
+ hasLoadMore,
618
+ hasEmptyState,
619
+ hasErrorState,
620
+ rows,
621
+ estimateSize,
622
+ overscan,
623
+ gap,
624
+ loadMoreLabel,
625
+ emptyTitle,
626
+ emptyDescription,
627
+ errorTitle,
628
+ errorDescription,
629
+ onOpenChat,
630
+ ...rest
631
+ }: ChatListPlaygroundProps) {
632
+ return (
633
+ <ChatList
634
+ {...rest}
635
+ // The fixture holds 80 chats; the list can't render more rows than that.
636
+ loadedCount={Math.min(Math.max(loadedCount, 0), CHATS.length)}
637
+ getItemKey={getChatKey}
638
+ >
639
+ <ChatListItems estimateSize={estimateSize} overscan={overscan} gap={gap}>
640
+ {(index) => (
641
+ <ChatRow
642
+ chat={CHATS[index]}
643
+ isSelected={index === selectedPosition - 1}
644
+ onOpen={onOpenChat}
645
+ />
646
+ )}
647
+ </ChatListItems>
648
+
649
+ {hasSkeleton && <ChatListSkeleton rows={rows} />}
650
+
651
+ {hasLoadMore && (
652
+ <ChatListLoadMore>
653
+ <Typography variant="caption-md" className="block py-12 text-center text-text-secondary">
654
+ {loadMoreLabel}
655
+ </Typography>
656
+ </ChatListLoadMore>
657
+ )}
658
+
659
+ {hasEmptyState && (
660
+ <ChatListEmptyState className="absolute inset-0">
661
+ <div className="flex flex-col items-center gap-8 px-24 text-center">
662
+ <Typography variant="body-small-high">{emptyTitle}</Typography>
663
+ <Typography variant="caption-md" className="text-text-secondary">
664
+ {emptyDescription}
665
+ </Typography>
666
+ </div>
667
+ </ChatListEmptyState>
668
+ )}
669
+
670
+ {hasErrorState && (
671
+ <ChatListError className="absolute inset-0">
672
+ <div className="flex flex-col items-center gap-8 px-24 text-center">
673
+ <Typography variant="body-small-high" className="text-text-error-main">
674
+ {errorTitle}
675
+ </Typography>
676
+ <Typography variant="caption-md" className="text-text-secondary">
677
+ {errorDescription}
678
+ </Typography>
679
+ </div>
680
+ </ChatListError>
681
+ )}
682
+ </ChatList>
683
+ );
684
+ }
685
+
686
+ /** Every part of the list at once, with each part and prop on the Controls panel; set `loadedCount` to 0 to reach the skeleton, empty and error states. */
687
+ export const Playground: StoryObj<typeof ChatListPlayground> = {
688
+ tags: ['!autodocs'],
689
+ decorators: [sidebarFrame],
690
+ args: {
691
+ className: 'h-full',
692
+ 'aria-label': 'Chat list',
693
+ loadedCount: CHAT_PAGE_SIZE * 2,
694
+ totalCount: CHATS.length,
695
+ isLoading: false,
696
+ isLoadingMore: true,
697
+ hasError: false,
698
+ selectedPosition: 2,
699
+ hasSkeleton: true,
700
+ hasLoadMore: true,
701
+ hasEmptyState: true,
702
+ hasErrorState: true,
703
+ rows: CHAT_PAGE_SIZE,
704
+ estimateSize: 54,
705
+ overscan: 6,
706
+ gap: 4,
707
+ loadMoreLabel: 'Loading more…',
708
+ emptyTitle: 'No conversations yet',
709
+ emptyDescription: 'Start a new chat to see it here.',
710
+ errorTitle: 'Failed to load chats',
711
+ errorDescription: 'Please try again later.',
712
+ onLoadMore: fn(),
713
+ onOpenChat: fn(),
714
+ },
715
+ argTypes: {
716
+ selectedPosition: {
717
+ control: { type: 'number', min: 0, max: CHATS.length },
718
+ description: 'Which row gets `isSelected` on its `ChatListItem`, counted from 1; 0 for none.',
719
+ },
720
+ hasSkeleton: { control: 'boolean', description: 'Renders `ChatListSkeleton`.' },
721
+ hasLoadMore: { control: 'boolean', description: 'Renders `ChatListLoadMore`.' },
722
+ hasEmptyState: { control: 'boolean', description: 'Renders `ChatListEmptyState`.' },
723
+ hasErrorState: { control: 'boolean', description: 'Renders `ChatListError`.' },
724
+ rows: {
725
+ control: { type: 'number', min: 1, max: 24 },
726
+ description: '`rows` on `ChatListSkeleton`: how many default skeleton rows it draws.',
727
+ },
728
+ estimateSize: {
729
+ control: { type: 'number', min: 24, max: 120 },
730
+ description: '`estimateSize` on `ChatListItems`: the first guess of a row height, in pixels.',
731
+ },
732
+ overscan: {
733
+ control: { type: 'number', min: 0, max: 20 },
734
+ description: '`overscan` on `ChatListItems`: rows rendered beyond the visible ones.',
735
+ },
736
+ gap: {
737
+ control: { type: 'number', min: 0, max: 24 },
738
+ description: '`gap` on `ChatListItems`: space between rows, in pixels.',
739
+ },
740
+ loadMoreLabel: { control: 'text', description: 'Text of the load-more row.' },
741
+ emptyTitle: { control: 'text', description: 'Headline of `ChatListEmptyState`.' },
742
+ emptyDescription: { control: 'text', description: 'Second line of `ChatListEmptyState`.' },
743
+ errorTitle: { control: 'text', description: 'Headline of `ChatListError`.' },
744
+ errorDescription: { control: 'text', description: 'Second line of `ChatListError`.' },
745
+ onOpenChat: { description: 'Called with the chat id when a row is activated.' },
746
+ },
747
+ render: (args) => <ChatListPlayground {...args} />,
332
748
  };