@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
@@ -3,14 +3,19 @@ import React from 'react';
3
3
  import { cn } from '@swisper.ai/web-core';
4
4
 
5
5
  export interface ChatMessageProps {
6
+ /** The message parts, usually a `ChatMessageContent` followed by an optional `ChatMessageActions`. */
6
7
  children: React.ReactNode;
8
+ /** Classes merged last onto the root, e.g. `gap-12` to change the gap between the parts. */
7
9
  className?: string;
10
+ /** Marks the message as the user's question: end-aligns it and turns its content into a filled bubble. */
8
11
  isQuestion?: boolean;
9
12
  }
10
13
 
14
+ /** One message in a conversation: the user's question as an end-aligned bubble, or the assistant's answer. */
11
15
  export function ChatMessage({ children, className, isQuestion }: ChatMessageProps) {
12
16
  return (
13
17
  <div
18
+ data-slot="chat-message"
14
19
  data-question={isQuestion}
15
20
  className={cn(
16
21
  'group/message',
@@ -26,12 +31,17 @@ export function ChatMessage({ children, className, isQuestion }: ChatMessageProp
26
31
  }
27
32
 
28
33
  export interface ChatMessageContentProps {
34
+ /** The message body: plain text, a `MarkdownViewer` or a `ChatCardContainer`. */
29
35
  children: React.ReactNode;
36
+ /** Classes merged last onto the content element. */
37
+ className?: string;
30
38
  }
31
39
 
32
- export function ChatMessageContent({ children }: ChatMessageContentProps) {
40
+ /** The body of a `ChatMessage`. Inside a question it renders as a padded, filled bubble. */
41
+ export function ChatMessageContent({ children, className }: ChatMessageContentProps) {
33
42
  return (
34
43
  <div
44
+ data-slot="chat-message-content"
35
45
  data-bubble={true}
36
46
  className={cn(
37
47
  'w-fit',
@@ -39,6 +49,7 @@ export function ChatMessageContent({ children }: ChatMessageContentProps) {
39
49
  'group-data-[question=true]/message:data-[bubble=true]:p-16',
40
50
  'group-data-[question=true]/message:data-[bubble=true]:rounded-[20px]',
41
51
  'group-data-[question=true]/message:data-[bubble=true]:bg-[#22283499]',
52
+ className,
42
53
  )}
43
54
  >
44
55
  {children}
@@ -47,13 +58,17 @@ export function ChatMessageContent({ children }: ChatMessageContentProps) {
47
58
  }
48
59
 
49
60
  export interface ChatMessageActionsProps {
61
+ /** The controls under the message, usually a `ChatMessageToolbar`. */
50
62
  children: React.ReactNode;
63
+ /** Classes merged last onto the actions row. */
51
64
  className?: string;
52
65
  }
53
66
 
67
+ /** A row under the message body. From `md` up it is hidden until its `ChatMessage` is hovered. */
54
68
  export function ChatMessageActions({ children, className }: ChatMessageActionsProps) {
55
69
  return (
56
70
  <div
71
+ data-slot="chat-message-actions"
57
72
  className={cn(
58
73
  'transition-opacity duration-300',
59
74
  'md:opacity-0 group-hover/message:opacity-100',
@@ -1 +1,8 @@
1
- export { ChatMessage, ChatMessageContent, ChatMessageActions } from './chat-message';
1
+ export {
2
+ ChatMessage,
3
+ ChatMessageContent,
4
+ ChatMessageActions,
5
+ type ChatMessageProps,
6
+ type ChatMessageContentProps,
7
+ type ChatMessageActionsProps,
8
+ } from './chat-message';
@@ -0,0 +1,30 @@
1
+ import type { AttachedFile, AttachmentIconExample } from './types';
2
+
3
+ // An inline image, so the thumbnail renders without a network request. The app passes the data
4
+ // URL it reads from the attached file.
5
+ export const RECEIPT_PHOTO_SRC = `data:image/svg+xml,${encodeURIComponent(
6
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 112 112"><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#f4d9b0"/><stop offset="1" stop-color="#c98a5e"/></linearGradient></defs><rect width="112" height="112" fill="url(#g)"/><rect x="30" y="18" width="52" height="76" rx="4" fill="#fffdf8"/><g fill="#8a8377"><rect x="38" y="30" width="36" height="4"/><rect x="38" y="42" width="28" height="4"/><rect x="38" y="54" width="36" height="4"/><rect x="38" y="66" width="20" height="4"/><rect x="38" y="80" width="36" height="6"/></g></svg>',
7
+ )}`;
8
+
9
+ export const STATEMENT_FILE_NAME = 'Account_statement_May_2026.pdf';
10
+
11
+ export const LONG_FILE_NAME = 'Rental_agreement_Seestrasse_14_signed_by_both_parties_final_v3.docx';
12
+
13
+ export const SENT_QUESTION = 'Does this statement match what you have for May?';
14
+
15
+ // The files of one prompt: a mix of types, one name too long to fit, and an image.
16
+ export const ATTACHED_FILES: AttachedFile[] = [
17
+ { name: STATEMENT_FILE_NAME },
18
+ { name: 'Household_budget_2026.xlsx' },
19
+ { name: LONG_FILE_NAME },
20
+ { name: 'Pharmacy_receipt.jpg', previewSrc: RECEIPT_PHOTO_SRC },
21
+ ];
22
+
23
+ export const ATTACHMENT_ICON_EXAMPLES: AttachmentIconExample[] = [
24
+ { icon: 'pdf', fileName: STATEMENT_FILE_NAME },
25
+ { icon: 'spreadsheet', fileName: 'Household_budget_2026.xlsx' },
26
+ { icon: 'document', fileName: 'Rental_agreement.docx' },
27
+ { icon: 'presentation', fileName: 'Quarterly_review.pptx' },
28
+ { icon: 'code', fileName: 'transactions_export.json' },
29
+ { icon: 'unknown', fileName: 'Tax_documents_2025.zip' },
30
+ ];
@@ -0,0 +1,14 @@
1
+ import type { ChatMessageAttachmentCardIconType } from '../chat-message-attachment-card-icon';
2
+
3
+ /** A file in the prompt's attachment list, trimmed to what the card renders. */
4
+ export interface AttachedFile {
5
+ name: string;
6
+ /** Set for an image: the data URL the app reads from the file. */
7
+ previewSrc?: string;
8
+ }
9
+
10
+ /** One file type the card has an icon for, with a file name that maps to it. */
11
+ export interface AttachmentIconExample {
12
+ icon: Exclude<ChatMessageAttachmentCardIconType, 'image'>;
13
+ fileName: string;
14
+ }
@@ -6,6 +6,7 @@ import { cn } from '@swisper.ai/web-core';
6
6
 
7
7
  type IconProps = SvgIconProps;
8
8
 
9
+ /** The file types the card has an icon for. `image` has no icon: show a `ChatMessageAttachmentCardPreview`. */
9
10
  export type ChatMessageAttachmentCardIconType =
10
11
  'spreadsheet' | 'pdf' | 'presentation' | 'document' | 'code' | 'image' | 'unknown';
11
12
 
@@ -43,9 +44,11 @@ const CHAT_ATTACHMENT_ICON_MAP: Record<
43
44
  };
44
45
 
45
46
  export interface ChatMessageAttachmentCardIconProps extends IconProps {
47
+ /** The file type, which picks the icon and its background colour. `getAttachmentIcon(file)` returns it. */
46
48
  icon: Exclude<ChatMessageAttachmentCardIconType, 'image'>;
47
49
  }
48
50
 
51
+ /** The file-type icon on its coloured tile. `className` goes to the tile, every other prop to the icon. */
49
52
  export function ChatMessageAttachmentCardIcon({
50
53
  icon,
51
54
  className,
@@ -55,6 +58,7 @@ export function ChatMessageAttachmentCardIcon({
55
58
 
56
59
  return (
57
60
  <span
61
+ data-slot="chat-message-attachment-card-icon"
58
62
  data-testid="chat-attachment-icon"
59
63
  data-icon={icon}
60
64
  className={cn(
@@ -2,6 +2,25 @@
2
2
  "$schema": "../../../../int-eslint-config/schemas/component.schema.json",
3
3
  "component": "chat-message-attachment-card",
4
4
  "purpose": "A compact chip for a file attached to a chat prompt or message: a file-type icon (ChatMessageAttachmentCardIcon) or image thumbnail (ChatMessageAttachmentCardPreview), the truncated file name, and a hover remove button (ChatMessageAttachmentCardActions).",
5
+ "anatomy": [
6
+ "import {",
7
+ " ChatMessageAttachmentCard,",
8
+ " ChatMessageAttachmentCardIcon,",
9
+ " ChatMessageAttachmentCardContent,",
10
+ " ChatMessageAttachmentCardTitle,",
11
+ " ChatMessageAttachmentCardPreview,",
12
+ " ChatMessageAttachmentCardActions,",
13
+ "} from '@swisper.ai/web-chat-ui';",
14
+ "",
15
+ "<ChatMessageAttachmentCard>",
16
+ " <ChatMessageAttachmentCardIcon />",
17
+ " <ChatMessageAttachmentCardContent>",
18
+ " <ChatMessageAttachmentCardTitle />",
19
+ " </ChatMessageAttachmentCardContent>",
20
+ " <ChatMessageAttachmentCardPreview />",
21
+ " <ChatMessageAttachmentCardActions />",
22
+ "</ChatMessageAttachmentCard>"
23
+ ],
5
24
  "useWhen": [
6
25
  "Listing the files a user has attached to the prompt before sending, with a remove action on each",
7
26
  "Showing the files that were sent with a question, read-only (isInteractive=false)",
@@ -41,6 +60,7 @@
41
60
  "isPreview=true shrinks the card to a 56px square for an image; ChatMessageAttachmentCardPreview then covers the whole card with the image (object-cover)",
42
61
  "ChatMessageAttachmentCardActions renders a single remove (close) icon button pinned over the card's top-right corner and calls onDelete when it is clicked",
43
62
  "ChatMessageAttachmentCardTitle truncates a long file name to one line; ChatMessageAttachmentCardContent takes the remaining width",
63
+ "Every part takes className, merged last. On ChatMessageAttachmentCardActions it styles the corner wrapper and buttonClassName styles the remove button; on ChatMessageAttachmentCardPreview it styles the figure and imageClassName the image; on ChatMessageAttachmentCardIcon it styles the coloured tile and the other props go to the icon",
44
64
  "ChatMessageAttachmentCardIcon shows a fixed icon and background colour per file type: spreadsheet, pdf, presentation, document, code, or unknown (draft icon)",
45
65
  "getAttachmentIcon(file) picks the icon type from the file name's extension: known office, PDF, CSV and text MIME types map to their type, other text, JavaScript and JSON files to code, anything else to unknown",
46
66
  "The card does not read or upload the file; the consumer owns the attachment list and removes the item in onDelete"
@@ -1,5 +1,21 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { useState } from 'react';
3
+ import { expect, fn, within } from 'storybook/test';
4
+
5
+ import { Typography } from '@swisper.ai/ui';
6
+
7
+ import { ParentBlock } from '../../__storybook__/parent-block';
8
+ import { ChatMessage, ChatMessageContent } from '../chat-message';
2
9
 
10
+ import {
11
+ ATTACHED_FILES,
12
+ ATTACHMENT_ICON_EXAMPLES,
13
+ LONG_FILE_NAME,
14
+ RECEIPT_PHOTO_SRC,
15
+ SENT_QUESTION,
16
+ STATEMENT_FILE_NAME,
17
+ } from './__stories__/fixtures';
18
+ import type { AttachedFile } from './__stories__/types';
3
19
  import {
4
20
  ChatMessageAttachmentCard,
5
21
  ChatMessageAttachmentCardActions,
@@ -9,20 +25,21 @@ import {
9
25
  } from './chat-message-attachment-card';
10
26
  import {
11
27
  ChatMessageAttachmentCardIcon,
12
- type ChatMessageAttachmentCardIconType,
28
+ type ChatMessageAttachmentCardIconProps,
13
29
  } from './chat-message-attachment-card-icon';
30
+ import { getAttachmentIcon } from './utils';
14
31
 
15
32
  const meta: Meta<typeof ChatMessageAttachmentCard> = {
16
- title: 'Chatbot/ChatMessageAttachmentCard',
33
+ title: 'Chat/ChatMessageAttachmentCard',
17
34
  component: ChatMessageAttachmentCard,
35
+ subcomponents: {
36
+ ChatMessageAttachmentCardIcon,
37
+ ChatMessageAttachmentCardContent,
38
+ ChatMessageAttachmentCardTitle,
39
+ ChatMessageAttachmentCardPreview,
40
+ ChatMessageAttachmentCardActions,
41
+ },
18
42
  tags: ['autodocs'],
19
- decorators: [
20
- (Story) => (
21
- <div className="max-w-[229px]">
22
- <Story />
23
- </div>
24
- ),
25
- ],
26
43
  args: {
27
44
  isPreview: false,
28
45
  isInteractive: true,
@@ -44,12 +61,11 @@ const meta: Meta<typeof ChatMessageAttachmentCard> = {
44
61
  control: false,
45
62
  description:
46
63
  'The card parts: an icon or `ChatMessageAttachmentCardPreview`, `ChatMessageAttachmentCardContent` with the file name, and `ChatMessageAttachmentCardActions`.',
47
- table: { disable: true },
48
64
  },
49
65
  className: {
50
66
  control: 'text',
51
- description: 'Extra classes merged onto the card root.',
52
- table: { disable: true },
67
+ description:
68
+ 'Extra classes merged onto the card root, e.g. `w-fit max-w-60` to cap the chip in a row.',
53
69
  },
54
70
  },
55
71
  };
@@ -57,75 +73,274 @@ const meta: Meta<typeof ChatMessageAttachmentCard> = {
57
73
  export default meta;
58
74
  type Story = StoryObj<typeof ChatMessageAttachmentCard>;
59
75
 
76
+ /** A file attached to the prompt before sending: its type icon, its name, and a remove button that shows on hover. */
60
77
  export const Default: Story = {
78
+ args: { className: 'w-fit max-w-60' },
61
79
  render: (args) => (
62
80
  <ChatMessageAttachmentCard {...args}>
63
- <ChatMessageAttachmentCardIcon icon="document" />
81
+ <ChatMessageAttachmentCardIcon icon="pdf" />
64
82
  <ChatMessageAttachmentCardContent>
65
- <ChatMessageAttachmentCardTitle>
66
- Long_document_name_with_spaces.pdf
67
- </ChatMessageAttachmentCardTitle>
83
+ <ChatMessageAttachmentCardTitle>{STATEMENT_FILE_NAME}</ChatMessageAttachmentCardTitle>
68
84
  </ChatMessageAttachmentCardContent>
69
- <ChatMessageAttachmentCardActions />
85
+ <ChatMessageAttachmentCardActions onDelete={fn()} />
70
86
  </ChatMessageAttachmentCard>
71
87
  ),
72
88
  };
73
89
 
90
+ /** A file that was sent with a question: static, with no hover background and no remove action. */
74
91
  export const NonInteractive: Story = {
75
- args: { isInteractive: false },
92
+ args: { isInteractive: false, className: 'w-fit max-w-60' },
76
93
  render: (args) => (
77
94
  <ChatMessageAttachmentCard {...args}>
78
- <ChatMessageAttachmentCardIcon icon="document" />
95
+ <ChatMessageAttachmentCardIcon icon="pdf" />
79
96
  <ChatMessageAttachmentCardContent>
80
- <ChatMessageAttachmentCardTitle>
81
- Long_document_name_with_spaces.pdf
82
- </ChatMessageAttachmentCardTitle>
97
+ <ChatMessageAttachmentCardTitle>{STATEMENT_FILE_NAME}</ChatMessageAttachmentCardTitle>
83
98
  </ChatMessageAttachmentCardContent>
84
- <ChatMessageAttachmentCardActions />
85
99
  </ChatMessageAttachmentCard>
86
100
  ),
87
101
  };
88
102
 
103
+ /** An attached image as a 56px square thumbnail, in place of the icon and file name. */
89
104
  export const WithPreview: Story = {
90
105
  args: { isPreview: true },
91
- render: (args) => (
92
- <ChatMessageAttachmentCard {...args} className="h-[200px]">
93
- <ChatMessageAttachmentCardPreview previewSrc="https://picsum.photos/420/200" />
94
- <ChatMessageAttachmentCardActions />
95
- </ChatMessageAttachmentCard>
96
- ),
97
- };
98
-
99
- export const Playground: Story = {
100
106
  render: (args) => (
101
107
  <ChatMessageAttachmentCard {...args}>
102
- <ChatMessageAttachmentCardIcon icon="pdf" />
103
- <ChatMessageAttachmentCardContent>
104
- <ChatMessageAttachmentCardTitle>document.pdf</ChatMessageAttachmentCardTitle>
105
- </ChatMessageAttachmentCardContent>
106
- <ChatMessageAttachmentCardActions />
108
+ <ChatMessageAttachmentCardPreview previewSrc={RECEIPT_PHOTO_SRC} />
109
+ <ChatMessageAttachmentCardActions onDelete={fn()} />
107
110
  </ChatMessageAttachmentCard>
108
111
  ),
109
112
  };
110
113
 
114
+ /** Every file type the card has an icon for, each with a file name that `getAttachmentIcon` maps to it. */
111
115
  export const Icon: Story = {
116
+ parameters: { controls: { disable: true } },
112
117
  render: () => (
113
- <div className="flex flex-wrap gap-3">
114
- {(
115
- [
116
- 'spreadsheet',
117
- 'pdf',
118
- 'presentation',
119
- 'document',
120
- 'code',
121
- 'unknown',
122
- ] satisfies ChatMessageAttachmentCardIconType[]
123
- ).map((icon) => (
124
- <div key={icon} className="flex flex-col items-center gap-1">
118
+ <ul aria-label="File type icons" className="flex flex-col gap-12">
119
+ {ATTACHMENT_ICON_EXAMPLES.map(({ icon, fileName }) => (
120
+ <li key={icon} className="flex items-center gap-12">
125
121
  <ChatMessageAttachmentCardIcon icon={icon} />
126
- <span className="text-xs text-gray-500">{icon}</span>
127
- </div>
122
+ <div className="flex flex-col">
123
+ <Typography variant="body-sm">{icon}</Typography>
124
+ <Typography variant="caption-md" className="text-text-tertiary">
125
+ {fileName}
126
+ </Typography>
127
+ </div>
128
+ </li>
128
129
  ))}
130
+ </ul>
131
+ ),
132
+ };
133
+
134
+ interface UploadedFilesPreviewProps {
135
+ initialFiles: AttachedFile[];
136
+ onRemove: (fileName: string) => void;
137
+ }
138
+
139
+ /** The prompt's attachment row: a chip per file, a thumbnail per image, each with a remove action. */
140
+ function UploadedFilesPreview({ initialFiles, onRemove }: UploadedFilesPreviewProps) {
141
+ const [files, setFiles] = useState(initialFiles);
142
+
143
+ if (files.length === 0) {
144
+ return null;
145
+ }
146
+
147
+ const handleRemove = (fileName: string) => {
148
+ setFiles((current) => current.filter((file) => file.name !== fileName));
149
+ onRemove(fileName);
150
+ };
151
+
152
+ return (
153
+ // The top and right padding leave room for the remove button, which overhangs the card's corner.
154
+ <ul aria-label="Attached files" className="flex flex-wrap gap-8 pt-12 pr-12">
155
+ {files.map((file) => (
156
+ <li key={file.name} aria-label={file.name} className="min-w-0">
157
+ {file.previewSrc ? (
158
+ <ChatMessageAttachmentCard isPreview>
159
+ <ChatMessageAttachmentCardPreview previewSrc={file.previewSrc} />
160
+ <ChatMessageAttachmentCardActions onDelete={() => handleRemove(file.name)} />
161
+ </ChatMessageAttachmentCard>
162
+ ) : (
163
+ <ChatMessageAttachmentCard className="w-fit max-w-60">
164
+ <ChatMessageAttachmentCardIcon icon={getAttachmentIcon(new File([], file.name))} />
165
+ <ChatMessageAttachmentCardContent>
166
+ <ChatMessageAttachmentCardTitle>{file.name}</ChatMessageAttachmentCardTitle>
167
+ </ChatMessageAttachmentCardContent>
168
+ <ChatMessageAttachmentCardActions onDelete={() => handleRemove(file.name)} />
169
+ </ChatMessageAttachmentCard>
170
+ )}
171
+ </li>
172
+ ))}
173
+ </ul>
174
+ );
175
+ }
176
+
177
+ type AttachmentRowStory = StoryObj<typeof UploadedFilesPreview>;
178
+
179
+ /** The files of one prompt in a row: the icon follows each file's extension, a long name truncates, and removing a file takes its chip out. */
180
+ export const AttachmentRow: AttachmentRowStory = {
181
+ args: { initialFiles: ATTACHED_FILES, onRemove: fn() },
182
+ argTypes: {
183
+ initialFiles: { control: false, description: 'The files attached to the prompt.' },
184
+ onRemove: { control: false, description: 'Called with the file name when a file is removed.' },
185
+ },
186
+ render: (args) => <UploadedFilesPreview {...args} />,
187
+ };
188
+
189
+ /** Checks that a long file name truncates and that pressing a file's remove button takes its chip out of the row. */
190
+ export const AttachmentRowRemove: AttachmentRowStory = {
191
+ tags: ['e2e', '!autodocs'],
192
+ args: { initialFiles: ATTACHED_FILES, onRemove: fn() },
193
+ render: (args) => <UploadedFilesPreview {...args} />,
194
+ play: async ({ args, canvas, userEvent, step }) => {
195
+ await step('Truncates a file name that is longer than the chip', async () => {
196
+ const title = canvas.getByText(LONG_FILE_NAME);
197
+
198
+ await expect(title.scrollWidth).toBeGreaterThan(title.clientWidth);
199
+ });
200
+
201
+ await step('Removes the file whose remove button is pressed', async () => {
202
+ const statement = within(canvas.getByRole('listitem', { name: STATEMENT_FILE_NAME }));
203
+
204
+ // TODO(echo-ds): the remove button has no accessible name, and it is `display: none` until
205
+ // the card is hovered. A simulated hover does not set `:hover`, so it is queried hidden.
206
+ await userEvent.click(statement.getByRole('button', { hidden: true }));
207
+
208
+ await expect(args.onRemove).toHaveBeenCalledWith(STATEMENT_FILE_NAME);
209
+ await expect(canvas.queryByText(STATEMENT_FILE_NAME)).not.toBeInTheDocument();
210
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(ATTACHED_FILES.length - 1);
211
+ });
212
+ },
213
+ };
214
+
215
+ /** The card in each place it's allowed: the prompt box toolbar, a chat message, the prompt box attachment row and a sent question's attachments. */
216
+ export const Examples: Story = {
217
+ parameters: { controls: { disable: true } },
218
+ render: () => (
219
+ <div className="flex max-w-140 flex-col gap-24">
220
+ <ParentBlock parent="web-chat-ui/ChatPromptBoxToolbar">
221
+ <div
222
+ aria-label="Prompt box toolbar"
223
+ className="rounded-sm border border-component-divider p-12"
224
+ >
225
+ <ChatMessageAttachmentCard className="w-fit max-w-60">
226
+ <ChatMessageAttachmentCardIcon icon="pdf" />
227
+ <ChatMessageAttachmentCardContent>
228
+ <ChatMessageAttachmentCardTitle>{STATEMENT_FILE_NAME}</ChatMessageAttachmentCardTitle>
229
+ </ChatMessageAttachmentCardContent>
230
+ <ChatMessageAttachmentCardActions onDelete={fn()} />
231
+ </ChatMessageAttachmentCard>
232
+ </div>
233
+ </ParentBlock>
234
+
235
+ <ParentBlock parent="web-chat-ui/chat-message">
236
+ <ChatMessage isQuestion>
237
+ <ChatMessageAttachmentCard isInteractive={false} className="max-w-60">
238
+ <ChatMessageAttachmentCardIcon icon="pdf" />
239
+ <ChatMessageAttachmentCardContent>
240
+ <ChatMessageAttachmentCardTitle>{STATEMENT_FILE_NAME}</ChatMessageAttachmentCardTitle>
241
+ </ChatMessageAttachmentCardContent>
242
+ </ChatMessageAttachmentCard>
243
+ <ChatMessageContent>{SENT_QUESTION}</ChatMessageContent>
244
+ </ChatMessage>
245
+ </ParentBlock>
246
+
247
+ <ParentBlock parent="prompt box attachment row">
248
+ <UploadedFilesPreview initialFiles={ATTACHED_FILES} onRemove={fn()} />
249
+ </ParentBlock>
250
+
251
+ <ParentBlock parent="sent question's attachments">
252
+ <ul aria-label="Sent attachments" className="flex flex-col items-end gap-8">
253
+ {ATTACHED_FILES.filter((file) => !file.previewSrc).map((file) => (
254
+ <li key={file.name} className="max-w-1/2 min-w-0">
255
+ <ChatMessageAttachmentCard isInteractive={false}>
256
+ <ChatMessageAttachmentCardIcon icon={getAttachmentIcon(new File([], file.name))} />
257
+ <ChatMessageAttachmentCardContent>
258
+ <ChatMessageAttachmentCardTitle>{file.name}</ChatMessageAttachmentCardTitle>
259
+ </ChatMessageAttachmentCardContent>
260
+ </ChatMessageAttachmentCard>
261
+ </li>
262
+ ))}
263
+ </ul>
264
+ </ParentBlock>
129
265
  </div>
130
266
  ),
131
267
  };
268
+
269
+ interface ChatMessageAttachmentCardPlaygroundProps {
270
+ className?: string;
271
+ icon: ChatMessageAttachmentCardIconProps['icon'];
272
+ title: string;
273
+ previewSrc: string;
274
+ isPreview: boolean;
275
+ isInteractive: boolean;
276
+ hasActions: boolean;
277
+ onDelete: () => void;
278
+ }
279
+
280
+ function ChatMessageAttachmentCardPlayground({
281
+ className,
282
+ icon,
283
+ title,
284
+ previewSrc,
285
+ isPreview,
286
+ isInteractive,
287
+ hasActions,
288
+ onDelete,
289
+ }: ChatMessageAttachmentCardPlaygroundProps) {
290
+ return (
291
+ <ChatMessageAttachmentCard
292
+ isPreview={isPreview}
293
+ isInteractive={isInteractive}
294
+ className={className}
295
+ >
296
+ {isPreview ? (
297
+ <ChatMessageAttachmentCardPreview previewSrc={previewSrc} />
298
+ ) : (
299
+ <>
300
+ <ChatMessageAttachmentCardIcon icon={icon} />
301
+ <ChatMessageAttachmentCardContent>
302
+ <ChatMessageAttachmentCardTitle>{title}</ChatMessageAttachmentCardTitle>
303
+ </ChatMessageAttachmentCardContent>
304
+ </>
305
+ )}
306
+ {hasActions && <ChatMessageAttachmentCardActions onDelete={onDelete} />}
307
+ </ChatMessageAttachmentCard>
308
+ );
309
+ }
310
+
311
+ /** Every part and prop on the Controls panel. `isPreview` swaps the icon and file name for the image, because the two never go together. */
312
+ export const Playground: StoryObj<typeof ChatMessageAttachmentCardPlayground> = {
313
+ tags: ['!autodocs'],
314
+ args: {
315
+ className: 'w-fit max-w-60',
316
+ icon: 'document',
317
+ title: LONG_FILE_NAME,
318
+ previewSrc: RECEIPT_PHOTO_SRC,
319
+ isPreview: false,
320
+ isInteractive: true,
321
+ hasActions: true,
322
+ onDelete: fn(),
323
+ },
324
+ argTypes: {
325
+ icon: {
326
+ control: 'select',
327
+ options: ATTACHMENT_ICON_EXAMPLES.map(({ icon }) => icon),
328
+ description: '`icon` of `ChatMessageAttachmentCardIcon`: the file type.',
329
+ },
330
+ title: { control: 'text', description: 'Text of `ChatMessageAttachmentCardTitle`.' },
331
+ previewSrc: {
332
+ control: 'text',
333
+ description: '`previewSrc` of `ChatMessageAttachmentCardPreview`, shown while `isPreview`.',
334
+ },
335
+ hasActions: {
336
+ control: 'boolean',
337
+ description:
338
+ 'Renders `ChatMessageAttachmentCardActions`. It only shows on hover while `isInteractive`.',
339
+ },
340
+ onDelete: {
341
+ control: false,
342
+ description: '`onDelete` of `ChatMessageAttachmentCardActions`.',
343
+ },
344
+ },
345
+ render: (args) => <ChatMessageAttachmentCardPlayground {...args} />,
346
+ };