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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (355) hide show
  1. package/README.md +9 -12
  2. package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
  3. package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
  4. package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
  5. package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
  6. package/dist/components/chat-card/chat-card.d.ts +1 -0
  7. package/dist/components/chat-card/chat-card.d.ts.map +1 -1
  8. package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
  9. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  10. package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
  11. package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
  12. package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
  13. package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
  14. package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
  15. package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
  16. package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
  17. package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
  18. package/dist/components/chat-card/contexts.d.ts +2 -0
  19. package/dist/components/chat-card/contexts.d.ts.map +1 -1
  20. package/dist/components/chat-card/hooks.d.ts +1 -0
  21. package/dist/components/chat-card/hooks.d.ts.map +1 -1
  22. package/dist/components/chat-card/types.d.ts +3 -0
  23. package/dist/components/chat-card/types.d.ts.map +1 -1
  24. package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
  25. package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
  26. package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
  27. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  28. package/dist/components/chat-container/chat-container.d.ts.map +1 -1
  29. package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
  30. package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
  31. package/dist/components/chat-input/chat-input.d.ts +27 -2
  32. package/dist/components/chat-input/chat-input.d.ts.map +1 -1
  33. package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
  34. package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
  35. package/dist/components/chat-list/chat-list-item.d.ts +6 -0
  36. package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
  37. package/dist/components/chat-list/chat-list-items.d.ts +12 -1
  38. package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
  39. package/dist/components/chat-list/chat-list.d.ts +36 -2
  40. package/dist/components/chat-list/chat-list.d.ts.map +1 -1
  41. package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
  42. package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
  43. package/dist/components/chat-message/chat-message.d.ts +12 -1
  44. package/dist/components/chat-message/chat-message.d.ts.map +1 -1
  45. package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
  46. package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
  47. package/dist/components/chat-message/index.d.ts +1 -1
  48. package/dist/components/chat-message/index.d.ts.map +1 -1
  49. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
  50. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
  51. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
  52. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
  53. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
  54. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
  55. package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
  56. package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
  57. package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
  58. package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
  59. package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
  60. package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
  61. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
  62. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
  63. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
  64. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
  65. package/dist/components/chat-message-toolbar/index.d.ts +1 -1
  66. package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
  67. package/dist/components/chat-messages/chat-messages.d.ts +34 -2
  68. package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
  69. package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
  70. package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
  71. package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
  72. package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
  73. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
  74. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
  75. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
  76. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
  77. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
  78. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
  79. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
  80. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
  81. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
  82. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
  83. package/dist/components/chat-reply/chat-reply.d.ts +11 -0
  84. package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
  85. package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
  86. package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
  87. package/dist/components/chat-reply/index.d.ts +1 -1
  88. package/dist/components/chat-reply/index.d.ts.map +1 -1
  89. package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
  90. package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
  91. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
  92. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
  93. package/dist/components/chat-suggestion/index.d.ts +2 -1
  94. package/dist/components/chat-suggestion/index.d.ts.map +1 -1
  95. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
  96. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  97. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
  98. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  99. package/dist/components/chat-thread/chat-thread.d.ts +17 -2
  100. package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
  101. package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
  102. package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
  103. package/dist/components/index.d.ts +1 -3
  104. package/dist/components/index.d.ts.map +1 -1
  105. package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
  106. package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
  107. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
  108. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
  109. package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
  110. package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
  111. package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
  112. package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
  113. package/dist/components/rich-text-area/styled.d.ts +6 -2
  114. package/dist/components/rich-text-area/styled.d.ts.map +1 -1
  115. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
  116. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
  117. package/dist/components/rich-text-field/components/index.d.ts +5 -5
  118. package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
  119. package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
  120. package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
  121. package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
  122. package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
  123. package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
  124. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  125. package/dist/components/topmenu/index.d.ts +2 -0
  126. package/dist/components/topmenu/index.d.ts.map +1 -0
  127. package/dist/components/topmenu/topmenu.d.ts +22 -0
  128. package/dist/components/topmenu/topmenu.d.ts.map +1 -0
  129. package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
  130. package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
  131. package/dist/docs/agent.stories.d.ts.map +1 -1
  132. package/dist/docs/chat-panel.d.ts +7 -5
  133. package/dist/docs/chat-panel.d.ts.map +1 -1
  134. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  135. package/dist/docs/chatbot.stories.d.ts.map +1 -1
  136. package/dist/index.css +1 -1
  137. package/dist/index.es.js +1227 -1260
  138. package/dist/index.es.js.map +1 -1
  139. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
  140. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
  141. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
  142. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
  143. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
  144. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
  145. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
  146. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
  147. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
  148. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
  149. package/package.json +15 -9
  150. package/src/__storybook__/parent-block.tsx +21 -0
  151. package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
  152. package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
  153. package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
  154. package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
  155. package/src/components/canvas-shell/__stories__/types.ts +47 -0
  156. package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
  157. package/src/components/canvas-shell/canvas-shell.json +24 -0
  158. package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
  159. package/src/components/canvas-shell/canvas-shell.tsx +44 -17
  160. package/src/components/chat-card/__stories__/fixtures.ts +119 -0
  161. package/src/components/chat-card/__stories__/types.ts +44 -0
  162. package/src/components/chat-card/chat-card.json +67 -3
  163. package/src/components/chat-card/chat-card.stories.tsx +872 -148
  164. package/src/components/chat-card/chat-card.tsx +2 -0
  165. package/src/components/chat-card/components/chat-card-body.tsx +12 -0
  166. package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
  167. package/src/components/chat-card/components/chat-card-form.tsx +21 -2
  168. package/src/components/chat-card/components/chat-card-header.tsx +39 -2
  169. package/src/components/chat-card/contexts.tsx +2 -0
  170. package/src/components/chat-card/hooks.ts +1 -0
  171. package/src/components/chat-card/types.ts +3 -0
  172. package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
  173. package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
  174. package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
  175. package/src/components/chat-card-container/__stories__/types.ts +16 -0
  176. package/src/components/chat-card-container/chat-card-container.json +7 -0
  177. package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
  178. package/src/components/chat-card-container/chat-card-container.tsx +5 -0
  179. package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
  180. package/src/components/chat-container/__stories__/fixtures.ts +27 -0
  181. package/src/components/chat-container/__stories__/measure.ts +22 -0
  182. package/src/components/chat-container/__stories__/types.ts +7 -0
  183. package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
  184. package/src/components/chat-container/chat-container.json +9 -1
  185. package/src/components/chat-container/chat-container.stories.tsx +538 -106
  186. package/src/components/chat-container/chat-container.tsx +3 -0
  187. package/src/components/chat-input/__stories__/fixtures.ts +31 -0
  188. package/src/components/chat-input/chat-input.json +10 -2
  189. package/src/components/chat-input/chat-input.stories.tsx +660 -197
  190. package/src/components/chat-input/chat-input.tsx +32 -2
  191. package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
  192. package/src/components/chat-list/__stories__/fixtures.ts +94 -0
  193. package/src/components/chat-list/__stories__/types.ts +13 -0
  194. package/src/components/chat-list/chat-list-item.tsx +6 -0
  195. package/src/components/chat-list/chat-list-items.tsx +16 -0
  196. package/src/components/chat-list/chat-list.json +24 -2
  197. package/src/components/chat-list/chat-list.stories.tsx +631 -215
  198. package/src/components/chat-list/chat-list.tsx +51 -4
  199. package/src/components/chat-message/__stories__/fixtures.ts +53 -0
  200. package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
  201. package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
  202. package/src/components/chat-message/chat-message.json +10 -1
  203. package/src/components/chat-message/chat-message.stories.tsx +282 -20
  204. package/src/components/chat-message/chat-message.tsx +16 -1
  205. package/src/components/chat-message/index.ts +8 -1
  206. package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
  207. package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
  208. package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
  209. package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
  210. package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
  211. package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
  212. package/src/components/chat-message-attachment-card/index.ts +6 -0
  213. package/src/components/chat-message-attachment-card/utils.ts +1 -0
  214. package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
  215. package/src/components/chat-message-response/chat-message-response.json +5 -0
  216. package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
  217. package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
  218. package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
  219. package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
  220. package/src/components/chat-message-toolbar/index.ts +4 -0
  221. package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
  222. package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
  223. package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
  224. package/src/components/chat-messages/__stories__/types.ts +5 -0
  225. package/src/components/chat-messages/chat-messages.json +30 -12
  226. package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
  227. package/src/components/chat-messages/chat-messages.tsx +46 -3
  228. package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
  229. package/src/components/chat-notification-card/__stories__/types.ts +13 -0
  230. package/src/components/chat-notification-card/chat-notification-card.json +52 -2
  231. package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
  232. package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
  233. package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
  234. package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
  235. package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
  236. package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
  237. package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
  238. package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
  239. package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
  240. package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
  241. package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
  242. package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
  243. package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
  244. package/src/components/chat-reply/chat-reply.json +10 -0
  245. package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
  246. package/src/components/chat-reply/chat-reply.tsx +15 -0
  247. package/src/components/chat-reply/index.ts +10 -1
  248. package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
  249. package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
  250. package/src/components/chat-suggestion/chat-suggestion.json +62 -20
  251. package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
  252. package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
  253. package/src/components/chat-suggestion/index.ts +9 -0
  254. package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
  255. package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
  256. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
  257. package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
  258. package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
  259. package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
  260. package/src/components/chat-thread/__stories__/snippets.ts +129 -0
  261. package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
  262. package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
  263. package/src/components/chat-thread/__stories__/types.ts +12 -0
  264. package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
  265. package/src/components/chat-thread/chat-thread.json +23 -3
  266. package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
  267. package/src/components/chat-thread/chat-thread.tsx +64 -16
  268. package/src/components/index.ts +1 -3
  269. package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
  270. package/src/components/markdown-viewer/markdown-viewer.json +7 -1
  271. package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
  272. package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
  273. package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
  274. package/src/components/rich-text-area/rich-text-area.json +6 -4
  275. package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
  276. package/src/components/rich-text-area/rich-text-area.tsx +22 -1
  277. package/src/components/rich-text-area/styled.tsx +11 -5
  278. package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
  279. package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
  280. package/src/components/rich-text-field/components/index.ts +8 -5
  281. package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
  282. package/src/components/rich-text-field/rich-text-field.json +3 -1
  283. package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
  284. package/src/components/rich-text-field/rich-text-field.tsx +23 -0
  285. package/src/components/topmenu/index.ts +1 -0
  286. package/src/components/topmenu/topmenu.json +107 -0
  287. package/src/components/topmenu/topmenu.stories.tsx +334 -0
  288. package/src/components/topmenu/topmenu.tsx +71 -0
  289. package/src/docs/agent.stories.tsx +16 -16
  290. package/src/docs/chat-panel.tsx +37 -32
  291. package/src/docs/chatbot-panel.tsx +11 -2
  292. package/src/docs/chatbot.mdx +17 -12
  293. package/src/docs/chatbot.stories.tsx +7 -8
  294. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
  295. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
  296. package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
  297. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
  298. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
  299. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
  300. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
  301. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
  302. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
  303. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
  304. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
  305. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
  306. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
  307. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
  308. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
  309. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
  310. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
  311. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
  312. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
  313. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
  314. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
  315. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
  316. package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
  317. package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
  318. package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
  319. package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
  320. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
  321. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
  322. package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
  323. package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
  324. package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
  325. package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
  326. package/dist/components/card-item-picker/index.d.ts +0 -9
  327. package/dist/components/card-item-picker/index.d.ts.map +0 -1
  328. package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
  329. package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
  330. package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
  331. package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
  332. package/dist/components/chat-message-history/index.d.ts +0 -2
  333. package/dist/components/chat-message-history/index.d.ts.map +0 -1
  334. package/dist/components/spinner/index.d.ts +0 -2
  335. package/dist/components/spinner/index.d.ts.map +0 -1
  336. package/dist/components/spinner/spinner.d.ts +0 -9
  337. package/dist/components/spinner/spinner.d.ts.map +0 -1
  338. package/dist/components/spinner/spinner.stories.d.ts +0 -8
  339. package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
  340. package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
  341. package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
  342. package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
  343. package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
  344. package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
  345. package/src/components/card-item-picker/card-item-picker.json +0 -147
  346. package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
  347. package/src/components/card-item-picker/index.ts +0 -24
  348. package/src/components/chat-message-history/chat-message-history.json +0 -99
  349. package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
  350. package/src/components/chat-message-history/chat-message-history.tsx +0 -277
  351. package/src/components/chat-message-history/index.ts +0 -13
  352. package/src/components/spinner/index.ts +0 -1
  353. package/src/components/spinner/spinner.json +0 -73
  354. package/src/components/spinner/spinner.stories.tsx +0 -41
  355. package/src/components/spinner/spinner.tsx +0 -32
@@ -1,10 +1,40 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { useState } from 'react';
3
- import { fn } from 'storybook/test';
2
+ import { useState, type FormEvent } from 'react';
3
+ import { expect, fn } from 'storybook/test';
4
4
 
5
- import { Button, TextField, Typography } from '@swisper.ai/ui';
5
+ import {
6
+ CloseIcon,
7
+ CodeIcon,
8
+ CopyIcon,
9
+ DownloadIcon,
10
+ EditIcon,
11
+ MailIcon,
12
+ SendEmailIcon,
13
+ TicketOnLineIcon,
14
+ TrainIcon,
15
+ } from '@swisper.ai/icons';
16
+ import { Button, TextField, Typography, withTooltip } from '@swisper.ai/ui';
17
+
18
+ import { ParentBlock } from '../../__storybook__/parent-block';
19
+ import {
20
+ ChatCardListLayout,
21
+ ChatCardListLayoutItems,
22
+ ChatCardListLayoutShowMore,
23
+ } from '../../layouts/chat-card-list-layout';
24
+ import { ChatCardContainer } from '../chat-card-container';
6
25
 
26
+ import {
27
+ CODE_SNIPPET,
28
+ EMAIL_DRAFT,
29
+ INBOX_EMAILS,
30
+ NEWS_ARTICLES,
31
+ TRIP_CONNECTIONS,
32
+ TRIP_STOPS,
33
+ WEEKEND_FORECAST,
34
+ } from './__stories__/fixtures';
35
+ import type { EmailMessage, TripConnection } from './__stories__/types';
7
36
  import { useEditChatCard } from './hooks';
37
+ import type { ChatCardProps } from './types';
8
38
 
9
39
  import {
10
40
  ChatCard,
@@ -21,6 +51,7 @@ import {
21
51
  ChatCardFooterPrice,
22
52
  ChatCardFooterActions,
23
53
  ChatCardHeaderContent,
54
+ ChatCardMedia,
24
55
  ChatCardSubTitle,
25
56
  ChatCardAttribute,
26
57
  ChatCardAttributeLabel,
@@ -31,12 +62,13 @@ import {
31
62
  } from '.';
32
63
 
33
64
  const meta: Meta<typeof ChatCard> = {
34
- title: 'Chatbot/ChatCard',
65
+ title: 'Chat/ChatCard',
35
66
  component: ChatCard,
36
67
  tags: ['autodocs'],
37
68
  decorators: [
69
+ withTooltip,
38
70
  (Story) => (
39
- <div className="max-w-[704px] relative">
71
+ <div className="relative max-w-176">
40
72
  <Story />
41
73
  </div>
42
74
  ),
@@ -51,14 +83,12 @@ const meta: Meta<typeof ChatCard> = {
51
83
  },
52
84
  isSelected: {
53
85
  control: 'boolean',
54
- defaultValue: false,
55
86
  description:
56
87
  'Highlights the border with the primary colour and sets `aria-current`, e.g. while the card is being edited.',
57
88
  table: { defaultValue: { summary: 'false' } },
58
89
  },
59
90
  isCollapsible: {
60
91
  control: 'boolean',
61
- defaultValue: true,
62
92
  description:
63
93
  'Lets the header toggle the body; a closed card expands on click. Set false for cards that always stay open.',
64
94
  table: { defaultValue: { summary: 'true' } },
@@ -73,7 +103,7 @@ const meta: Meta<typeof ChatCard> = {
73
103
  fullWidth: {
74
104
  control: 'boolean',
75
105
  description:
76
- 'Keeps the card at full width even when collapsed, instead of the reading-column cap.',
106
+ 'Sets `w-full` on the root, which it already has: a closed card keeps the reading-column cap either way.',
77
107
  table: { defaultValue: { summary: 'false' } },
78
108
  },
79
109
  isRounded: {
@@ -123,227 +153,921 @@ const meta: Meta<typeof ChatCard> = {
123
153
  export default meta;
124
154
  type Story = StoryObj<typeof ChatCard>;
125
155
 
126
- function CardFooterExample() {
127
- return (
128
- <ChatCardFooter>
129
- <ChatCardFooterNotes>
130
- <Typography variant="caption-sm" className="text-layout-feedback-success-text-base">
131
- 4/6 items available to book
132
- </Typography>
133
- <Typography variant="caption-sm" className="text-text-secondary">
134
- 2x passengers • 6 tickets
135
- </Typography>
136
- </ChatCardFooterNotes>
137
- <ChatCardFooterPrice>
138
- <Typography variant="caption-sm" className="text-layout-feedback-info-text-base">
139
- Swisper 5% discount applied
140
- </Typography>
141
- <div className="flex items-center gap-1">
142
- <Typography variant="label-sm" className="text-text-secondary">
143
- ~
144
- </Typography>
145
- <Typography variant="body-small-low" className="text-text-secondary line-through">
146
- CHF 100.00
147
- </Typography>
148
- <Typography variant="body-small-low" fontWeight="bold">
149
- CHF 95.00
150
- </Typography>
151
- </div>
152
- </ChatCardFooterPrice>
153
- <ChatCardFooterActions>
154
- <Button variant="danger-subtle" size="sm">
155
- Remove
156
- </Button>
157
- <Button variant="secondary" size="sm">
158
- Edit
159
- </Button>
160
- <Button variant="primary" size="sm">
161
- Book
162
- </Button>
163
- </ChatCardFooterActions>
164
- </ChatCardFooter>
165
- );
166
- }
167
-
156
+ /** A drafted email the user reviews before it is sent: header, label and value rows, the message, and the decisions in the footer. */
168
157
  export const Default: Story = {
169
- args: {
170
- level: 1,
171
- },
172
- render: ({ ...rest }) => (
173
- <ChatCard {...rest}>
158
+ render: (args) => (
159
+ <ChatCard {...args} aria-labelledby="email-draft-title">
174
160
  <ChatCardHeader>
175
- <ChatCardIcon>🗂️</ChatCardIcon>
161
+ <ChatCardIcon>
162
+ <MailIcon fontSize="small" />
163
+ </ChatCardIcon>
176
164
  <ChatCardHeaderContent>
177
- <ChatCardTitle>Booking details • Trip Plan Switzerland 5 days</ChatCardTitle>
178
- <ChatCardSubTitle>Tue, Oct 15 • 1:30 - 2:30pm</ChatCardSubTitle>
165
+ <ChatCardTitle id="email-draft-title">{EMAIL_DRAFT.subject}</ChatCardTitle>
166
+ <ChatCardSubTitle>
167
+ {EMAIL_DRAFT.from} • {EMAIL_DRAFT.date}
168
+ </ChatCardSubTitle>
179
169
  </ChatCardHeaderContent>
180
170
  <ChatCardActions>
181
- <ChatCardCollapsibleButton />
171
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the email" />
182
172
  </ChatCardActions>
183
173
  </ChatCardHeader>
184
174
  <ChatCardBody>
185
- <ChatCardForm>
175
+ <ChatCardContent>
186
176
  <ChatCardAttributes>
187
177
  <ChatCardAttribute>
188
178
  <ChatCardAttributeLabel>From</ChatCardAttributeLabel>
189
- <ChatCardAttributeValue>Fillipo Magnini</ChatCardAttributeValue>
179
+ <ChatCardAttributeValue>{EMAIL_DRAFT.from}</ChatCardAttributeValue>
180
+ </ChatCardAttribute>
181
+ <ChatCardAttribute>
182
+ <ChatCardAttributeLabel>To</ChatCardAttributeLabel>
183
+ <ChatCardAttributeValue>{EMAIL_DRAFT.to.join('; ')}</ChatCardAttributeValue>
190
184
  </ChatCardAttribute>
191
185
  <ChatCardAttribute>
192
- <ChatCardAttributeLabel>cc</ChatCardAttributeLabel>
193
- <ChatCardAttributeValue>
194
- Carlos Areias; Manueal Soares; Johny Bigodes; Mello Bryanner; Valentino Tista;
195
- </ChatCardAttributeValue>
186
+ <ChatCardAttributeLabel>CC</ChatCardAttributeLabel>
187
+ <ChatCardAttributeValue>{EMAIL_DRAFT.cc.join('; ')}</ChatCardAttributeValue>
196
188
  </ChatCardAttribute>
197
189
  </ChatCardAttributes>
198
- <p>This is the collapsible content of the card.</p>
199
- </ChatCardForm>
200
- <CardFooterExample />
190
+ <Typography variant="body-small-high" className="whitespace-pre-line">
191
+ {EMAIL_DRAFT.body}
192
+ </Typography>
193
+ </ChatCardContent>
194
+ <ChatCardFooter>
195
+ <ChatCardFooterActions>
196
+ <Button variant="tertiary">Cancel</Button>
197
+ <Button variant="secondary" startIcon={<EditIcon />}>
198
+ Edit
199
+ </Button>
200
+ <Button variant="primary" startIcon={<SendEmailIcon />}>
201
+ Send
202
+ </Button>
203
+ </ChatCardFooterActions>
204
+ </ChatCardFooter>
201
205
  </ChatCardBody>
202
206
  </ChatCard>
203
207
  ),
204
208
  };
205
209
 
210
+ /** Clicks the header to collapse the email and again to expand it, and checks a click in the open body leaves it open. */
211
+ export const DefaultCollapseAndExpand: Story = {
212
+ ...Default,
213
+ tags: ['e2e', '!autodocs'],
214
+ args: { onOpenChange: fn() },
215
+ play: async ({ args, canvas, userEvent, step }) => {
216
+ const card = canvas.getByRole('region', { name: EMAIL_DRAFT.subject });
217
+ const header = canvas.getByText(EMAIL_DRAFT.subject);
218
+
219
+ await step('Starts open with the message and the footer', async () => {
220
+ await expect(card).toHaveAttribute('data-state', 'open');
221
+ await expect(canvas.getByText(/the agenda works for me/i)).toBeVisible();
222
+ await expect(canvas.getByRole('button', { name: 'Send' })).toBeVisible();
223
+ });
224
+
225
+ await step('A click in the open body does not collapse the card', async () => {
226
+ await userEvent.click(canvas.getByText(/the agenda works for me/i));
227
+ await expect(card).toHaveAttribute('data-state', 'open');
228
+ await expect(args.onOpenChange).not.toHaveBeenCalled();
229
+ });
230
+
231
+ await step('A click on the header collapses it', async () => {
232
+ await userEvent.click(header);
233
+ await expect(card).toHaveAttribute('data-state', 'closed');
234
+ await expect(canvas.queryByText(/the agenda works for me/i)).toBeNull();
235
+ await expect(canvas.queryByRole('button', { name: 'Send' })).toBeNull();
236
+ await expect(args.onOpenChange).toHaveBeenLastCalledWith(false);
237
+ });
238
+
239
+ await step('A second click expands it again', async () => {
240
+ await userEvent.click(header);
241
+ await expect(card).toHaveAttribute('data-state', 'open');
242
+ await expect(canvas.getByText(/the agenda works for me/i)).toBeVisible();
243
+ await expect(args.onOpenChange).toHaveBeenLastCalledWith(true);
244
+ });
245
+ },
246
+ };
247
+
248
+ /** Reaches the collapse button with Tab, collapses the email with Enter and expands it with Space. */
249
+ export const DefaultKeyboard: Story = {
250
+ ...Default,
251
+ tags: ['e2e', '!autodocs'],
252
+ args: { onOpenChange: fn() },
253
+ play: async ({ args, canvas, userEvent, step }) => {
254
+ const card = canvas.getByRole('region', { name: EMAIL_DRAFT.subject });
255
+ const toggle = canvas.getByRole('button', { name: 'Collapse or expand the email' });
256
+
257
+ await step('Tab reaches the collapse button first', async () => {
258
+ await userEvent.tab();
259
+ await expect(toggle).toHaveFocus();
260
+ });
261
+
262
+ await step('Enter collapses and focus stays on the button', async () => {
263
+ await userEvent.keyboard('{Enter}');
264
+ await expect(card).toHaveAttribute('data-state', 'closed');
265
+ await expect(toggle).toHaveFocus();
266
+ await expect(args.onOpenChange).toHaveBeenLastCalledWith(false);
267
+ });
268
+
269
+ await step('Space expands', async () => {
270
+ await userEvent.keyboard(' ');
271
+ await expect(card).toHaveAttribute('data-state', 'open');
272
+ await expect(canvas.getByText(/the agenda works for me/i)).toBeVisible();
273
+ await expect(args.onOpenChange).toHaveBeenLastCalledWith(true);
274
+ });
275
+ },
276
+ };
277
+
278
+ interface TripCardProps {
279
+ connection: TripConnection;
280
+ onRemove?: (connectionId: string) => void;
281
+ }
282
+
283
+ function TripCard({ connection, onRemove }: TripCardProps) {
284
+ const titleId = `${connection.id}-title`;
285
+
286
+ return (
287
+ <ChatCard level={2} isCollapsible={false} aria-labelledby={titleId}>
288
+ <ChatCardHeader>
289
+ <ChatCardIcon>
290
+ <TrainIcon fontSize="small" />
291
+ </ChatCardIcon>
292
+ <ChatCardHeaderContent>
293
+ <ChatCardTitle id={titleId}>{connection.route}</ChatCardTitle>
294
+ <ChatCardSubTitle>
295
+ {connection.date} • {connection.times}
296
+ </ChatCardSubTitle>
297
+ </ChatCardHeaderContent>
298
+ <ChatCardActions>
299
+ <ChatCardActionButton
300
+ aria-label={`Remove ${connection.route}`}
301
+ tooltip="Remove trip"
302
+ onClick={() => onRemove?.(connection.id)}
303
+ >
304
+ <CloseIcon />
305
+ </ChatCardActionButton>
306
+ </ChatCardActions>
307
+ </ChatCardHeader>
308
+ <ChatCardBody>
309
+ <ChatCardFooter>
310
+ <ChatCardFooterNotes>
311
+ <Typography variant="caption-sm" className="text-text-secondary">
312
+ {connection.duration} • {connection.changes}
313
+ </Typography>
314
+ <Typography variant="caption-sm" className="text-text-secondary">
315
+ {connection.fare}
316
+ </Typography>
317
+ </ChatCardFooterNotes>
318
+ <ChatCardFooterPrice>
319
+ <Typography variant="body-small-low" fontWeight="bold">
320
+ {connection.price}
321
+ </Typography>
322
+ </ChatCardFooterPrice>
323
+ </ChatCardFooter>
324
+ </ChatCardBody>
325
+ </ChatCard>
326
+ );
327
+ }
328
+
329
+ /** A booking card holding one level 2 card per trip: the nested cards stay open, so only the outer card folds. */
206
330
  export const Level2: Story = {
207
331
  args: {
208
332
  level: 1,
209
333
  defaultOpen: true,
210
334
  },
211
- render: ({ ...rest }) => (
212
- <ChatCard {...rest}>
335
+ render: (args) => (
336
+ <ChatCard {...args} aria-labelledby="booking-title">
213
337
  <ChatCardHeader>
214
- <ChatCardIcon>🗂️</ChatCardIcon>
338
+ <ChatCardIcon>
339
+ <TicketOnLineIcon fontSize="small" />
340
+ </ChatCardIcon>
215
341
  <ChatCardHeaderContent>
216
- <ChatCardTitle>Booking details • Trip Plan Switzerland 5 days</ChatCardTitle>
342
+ <ChatCardTitle id="booking-title">Booking details</ChatCardTitle>
217
343
  </ChatCardHeaderContent>
218
344
  <ChatCardActions>
219
- <ChatCardCollapsibleButton />
345
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the booking details" />
220
346
  </ChatCardActions>
221
347
  </ChatCardHeader>
222
348
  <ChatCardBody>
223
- <ChatCardContent>
224
- <ChatCard level={2} isCollapsible={false}>
225
- <ChatCardHeader>
226
- <ChatCardIcon>♡</ChatCardIcon>
227
- <ChatCardHeaderContent>
228
- <ChatCardTitle>Zürich HB ➔ Interlaken Ost</ChatCardTitle>
229
- </ChatCardHeaderContent>
230
- <ChatCardActions>
231
- <ChatCardActionButton aria-label="More">⋯</ChatCardActionButton>
232
- </ChatCardActions>
233
- </ChatCardHeader>
234
- <ChatCardBody>
235
- <ChatCardContent>Nested Lvl 2 card content.</ChatCardContent>
236
- <CardFooterExample />
237
- </ChatCardBody>
238
- </ChatCard>
349
+ <ChatCardContent hasHeaderPadding={false} className="flex flex-col">
350
+ {TRIP_CONNECTIONS.map((connection) => (
351
+ <TripCard key={connection.id} connection={connection} />
352
+ ))}
239
353
  </ChatCardContent>
354
+ <ChatCardFooter>
355
+ <ChatCardFooterNotes>
356
+ <Typography variant="caption-sm" className="text-layout-feedback-success-text-base">
357
+ 2/2 trips available to book
358
+ </Typography>
359
+ <Typography variant="caption-sm" className="text-text-secondary">
360
+ 2 passengers • 2 trips • 4 tickets
361
+ </Typography>
362
+ </ChatCardFooterNotes>
363
+ <ChatCardFooterPrice>
364
+ <Typography variant="caption-sm" className="text-layout-feedback-info-text-base">
365
+ Swisper 5% discount applied
366
+ </Typography>
367
+ <div className="flex items-center gap-4">
368
+ <Typography variant="body-small-low" className="text-text-secondary line-through">
369
+ CHF 132.00
370
+ </Typography>
371
+ <Typography variant="body-small-low" fontWeight="bold">
372
+ CHF 125.40
373
+ </Typography>
374
+ </div>
375
+ </ChatCardFooterPrice>
376
+ <ChatCardFooterActions>
377
+ <Button variant="tertiary">Cancel</Button>
378
+ <Button variant="primary">Select</Button>
379
+ </ChatCardFooterActions>
380
+ </ChatCardFooter>
240
381
  </ChatCardBody>
241
382
  </ChatCard>
242
383
  ),
243
384
  };
244
385
 
386
+ /** An email from a search result, closed until the user opens it: the title and subtitle name it, and the preview shows how the message starts. */
245
387
  export const Collapsed: Story = {
246
388
  args: {
247
389
  defaultOpen: false,
248
390
  },
249
- render: ({ ...rest }) => (
250
- <ChatCard {...rest}>
391
+ render: (args) => (
392
+ <ChatCard {...args} aria-labelledby="collapsed-email-title">
251
393
  <ChatCardHeader>
252
- <ChatCardIcon>🗂️</ChatCardIcon>
394
+ <ChatCardIcon>
395
+ <MailIcon fontSize="small" />
396
+ </ChatCardIcon>
253
397
  <ChatCardHeaderContent>
254
- <ChatCardTitle>Booking details • Trip Plan Switzerland 5 days</ChatCardTitle>
255
- <ChatCardSubTitle>Tue, Oct 15 • 1:30 - 2:30pm</ChatCardSubTitle>
398
+ <ChatCardTitle id="collapsed-email-title">{INBOX_EMAILS[0].subject}</ChatCardTitle>
399
+ <ChatCardSubTitle>
400
+ {INBOX_EMAILS[0].from} • {INBOX_EMAILS[0].date}
401
+ </ChatCardSubTitle>
256
402
  </ChatCardHeaderContent>
257
403
  <ChatCardActions>
258
- <ChatCardCollapsibleButton />
404
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the email" />
259
405
  </ChatCardActions>
260
406
  </ChatCardHeader>
261
407
  <ChatCardBody>
262
408
  <ChatCardContent>
263
- <p>Expanded body. Click the header to collapse.</p>
409
+ <Typography variant="body-small-high" className="whitespace-pre-line">
410
+ {INBOX_EMAILS[0].body}
411
+ </Typography>
264
412
  </ChatCardContent>
265
- <CardFooterExample />
266
413
  </ChatCardBody>
267
414
  <ChatCardPreview>
268
- <p>Collapsed preview. Click anywhere on the card to expand.</p>
415
+ <Typography variant="body-small-high" className="line-clamp-2 text-text-secondary">
416
+ {INBOX_EMAILS[0].body}
417
+ </Typography>
269
418
  </ChatCardPreview>
270
419
  </ChatCard>
271
420
  ),
272
421
  };
273
422
 
274
- export const Editable: Story = {
275
- render: ({ ...rest }) => {
276
- const [value, setValue] = useState('This is the editable content of the card.');
277
- const { isEditing, startEdit, discard } = useEditChatCard({
278
- isEditable: true,
279
- defaultEditing: true,
280
- });
423
+ interface EmailDraftCardProps {
424
+ email: EmailMessage;
425
+ isDefaultEditing?: boolean;
426
+ onSend: (subject: string) => void;
427
+ onCancel: () => void;
428
+ }
429
+
430
+ function EmailDraftCard({
431
+ email,
432
+ isDefaultEditing = false,
433
+ onSend,
434
+ onCancel,
435
+ }: EmailDraftCardProps) {
436
+ const [subject, setSubject] = useState(email.subject);
437
+ const [draft, setDraft] = useState(email.subject);
438
+ const { isEditing, startEdit, discard } = useEditChatCard({
439
+ isEditable: true,
440
+ defaultEditing: isDefaultEditing,
441
+ });
281
442
 
282
- return (
283
- <ChatCard isSelected={isEditing} {...rest}>
284
- <ChatCardHeader>
285
- <ChatCardIcon>🗂️</ChatCardIcon>
286
- <ChatCardHeaderContent>
287
- <ChatCardTitle>Card Title</ChatCardTitle>
288
- <ChatCardSubTitle>Card Subtitle</ChatCardSubTitle>
289
- </ChatCardHeaderContent>
290
- <ChatCardActions>
291
- <ChatCardCollapsibleButton />
292
- </ChatCardActions>
293
- </ChatCardHeader>
294
- <ChatCardBody>
443
+ function handleDiscard() {
444
+ setDraft(subject);
445
+ discard();
446
+ }
447
+
448
+ function handleSubmit(event: FormEvent<HTMLFormElement>) {
449
+ event.preventDefault();
450
+ setSubject(draft);
451
+ discard();
452
+ onSend(draft);
453
+ }
454
+
455
+ return (
456
+ <ChatCard isSelected={isEditing} aria-labelledby="editable-email-title">
457
+ <ChatCardHeader>
458
+ <ChatCardIcon>
459
+ <MailIcon fontSize="small" />
460
+ </ChatCardIcon>
461
+ <ChatCardHeaderContent>
462
+ <ChatCardTitle id="editable-email-title">{subject}</ChatCardTitle>
463
+ <ChatCardSubTitle>
464
+ {email.from} • {email.date}
465
+ </ChatCardSubTitle>
466
+ </ChatCardHeaderContent>
467
+ <ChatCardActions>
468
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the email" />
469
+ </ChatCardActions>
470
+ </ChatCardHeader>
471
+ <ChatCardBody>
472
+ {isEditing ? (
473
+ <ChatCardForm id="editable-email-form" onSubmit={handleSubmit}>
474
+ <TextField
475
+ label="Subject"
476
+ value={draft}
477
+ onChange={(event) => setDraft(event.target.value)}
478
+ />
479
+ </ChatCardForm>
480
+ ) : (
295
481
  <ChatCardContent>
296
- {isEditing ? (
297
- <TextField
298
- className="text-text-primary"
299
- defaultValue={value}
300
- onChange={(event) => setValue(event.target.value)}
301
- />
302
- ) : (
303
- <p>{value}</p>
304
- )}
482
+ <Typography variant="body-small-high" className="whitespace-pre-line">
483
+ {email.body}
484
+ </Typography>
305
485
  </ChatCardContent>
306
- <ChatCardFooter>
307
- {!isEditing ? (
308
- <Button variant="secondary" onClick={startEdit}>
309
- Edit
310
- </Button>
486
+ )}
487
+ <ChatCardFooter>
488
+ <ChatCardFooterActions>
489
+ {isEditing ? (
490
+ <>
491
+ <Button variant="tertiary" onClick={handleDiscard}>
492
+ Discard
493
+ </Button>
494
+ <Button
495
+ variant="primary"
496
+ type="submit"
497
+ form="editable-email-form"
498
+ startIcon={<SendEmailIcon />}
499
+ >
500
+ Send
501
+ </Button>
502
+ </>
311
503
  ) : (
312
- <Button variant="danger" onClick={discard}>
313
- Discard
314
- </Button>
504
+ <>
505
+ <Button variant="tertiary" onClick={onCancel}>
506
+ Cancel
507
+ </Button>
508
+ <Button variant="secondary" startIcon={<EditIcon />} onClick={startEdit}>
509
+ Edit
510
+ </Button>
511
+ <Button
512
+ variant="primary"
513
+ startIcon={<SendEmailIcon />}
514
+ onClick={() => onSend(subject)}
515
+ >
516
+ Send
517
+ </Button>
518
+ </>
315
519
  )}
316
- </ChatCardFooter>
317
- </ChatCardBody>
318
- </ChatCard>
319
- );
520
+ </ChatCardFooterActions>
521
+ </ChatCardFooter>
522
+ </ChatCardBody>
523
+ </ChatCard>
524
+ );
525
+ }
526
+
527
+ type EmailDraftStory = StoryObj<typeof EmailDraftCard>;
528
+
529
+ /** A drafted email being edited: `useEditChatCard` holds the edit state, and the card is selected while its field is open. */
530
+ export const Editable: EmailDraftStory = {
531
+ args: { email: EMAIL_DRAFT, isDefaultEditing: true, onSend: fn(), onCancel: fn() },
532
+ argTypes: {
533
+ email: { control: 'object', description: 'The drafted email.' },
534
+ isDefaultEditing: {
535
+ control: 'boolean',
536
+ description: '`defaultEditing` of `useEditChatCard`: whether the card starts in edit mode.',
537
+ },
538
+ onSend: { description: 'Called with the subject when the email is sent.' },
539
+ onCancel: { description: 'Called when the user cancels the draft.' },
540
+ },
541
+ parameters: { controls: { include: ['email', 'isDefaultEditing'] } },
542
+ render: (args) => <EmailDraftCard {...args} />,
543
+ };
544
+
545
+ /** Opens the editor, changes the subject and discards it: the card is selected only while editing and the subject is unchanged. */
546
+ export const EditableEditAndDiscard: EmailDraftStory = {
547
+ ...Editable,
548
+ tags: ['e2e', '!autodocs'],
549
+ args: { email: EMAIL_DRAFT, isDefaultEditing: false, onSend: fn(), onCancel: fn() },
550
+ play: async ({ args, canvas, userEvent, step }) => {
551
+ const card = canvas.getByRole('region', { name: EMAIL_DRAFT.subject });
552
+
553
+ await step('Starts read-only and not selected', async () => {
554
+ await expect(card).toHaveAttribute('aria-current', 'false');
555
+ await expect(canvas.queryByLabelText('Subject')).toBeNull();
556
+ });
557
+
558
+ await step('Edit selects the card and shows the field', async () => {
559
+ await userEvent.click(canvas.getByRole('button', { name: 'Edit' }));
560
+ await expect(card).toHaveAttribute('aria-current', 'true');
561
+ await expect(canvas.getByLabelText('Subject')).toHaveValue(EMAIL_DRAFT.subject);
562
+ });
563
+
564
+ await step('Discard drops the change and leaves edit mode', async () => {
565
+ const field = canvas.getByLabelText('Subject');
566
+ await userEvent.clear(field);
567
+ await userEvent.type(field, 'Arriving at 10:01 on Tuesday');
568
+ await userEvent.click(canvas.getByRole('button', { name: 'Discard' }));
569
+ await expect(card).toHaveAttribute('aria-current', 'false');
570
+ await expect(card).toHaveAttribute('data-state', 'open');
571
+ await expect(canvas.getByText(EMAIL_DRAFT.subject)).toBeVisible();
572
+ await expect(args.onSend).not.toHaveBeenCalled();
573
+ });
574
+ },
575
+ };
576
+
577
+ /** Changes the subject and sends: the callback gets the new subject, and the card leaves edit mode with it in the title. */
578
+ export const EditableSend: EmailDraftStory = {
579
+ ...Editable,
580
+ tags: ['e2e', '!autodocs'],
581
+ args: { email: EMAIL_DRAFT, isDefaultEditing: true, onSend: fn(), onCancel: fn() },
582
+ play: async ({ args, canvas, userEvent }) => {
583
+ const field = canvas.getByLabelText('Subject');
584
+
585
+ await userEvent.clear(field);
586
+ await userEvent.type(field, 'Arriving at 10:01 on Tuesday');
587
+ await userEvent.click(canvas.getByRole('button', { name: 'Send' }));
588
+
589
+ await expect(args.onSend).toHaveBeenCalledWith('Arriving at 10:01 on Tuesday');
590
+ const card = canvas.getByRole('region', { name: 'Arriving at 10:01 on Tuesday' });
591
+ await expect(card).toHaveAttribute('aria-current', 'false');
592
+ await expect(canvas.queryByLabelText('Subject')).toBeNull();
320
593
  },
321
594
  };
322
595
 
596
+ /** A train connection that starts closed: `ChatCardPreview` summarises the journey, and the body holds the stops and the action. */
323
597
  export const WithPreview: Story = {
324
598
  args: {
325
599
  defaultOpen: false,
326
600
  },
327
- render: ({ ...rest }) => (
328
- <ChatCard {...rest}>
601
+ render: (args) => (
602
+ <ChatCard {...args} aria-labelledby="connection-title">
329
603
  <ChatCardHeader>
330
- <ChatCardIcon>🗂️</ChatCardIcon>
604
+ <ChatCardIcon>
605
+ <TrainIcon fontSize="small" />
606
+ </ChatCardIcon>
331
607
  <ChatCardHeaderContent>
332
- <ChatCardTitle>Card Title</ChatCardTitle>
333
- <ChatCardSubTitle>Card Subtitle</ChatCardSubTitle>
608
+ <ChatCardTitle id="connection-title">{TRIP_CONNECTIONS[0].route}</ChatCardTitle>
609
+ <ChatCardSubTitle>
610
+ {TRIP_CONNECTIONS[0].date} • {TRIP_CONNECTIONS[0].times}
611
+ </ChatCardSubTitle>
334
612
  </ChatCardHeaderContent>
335
613
  <ChatCardActions>
336
- <ChatCardCollapsibleButton />
614
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the connection" />
337
615
  </ChatCardActions>
338
616
  </ChatCardHeader>
339
617
  <ChatCardBody>
340
- <ChatCardContent>
341
- <p>body</p>
618
+ <ChatCardContent hasHeaderPadding={false}>
619
+ <ol aria-label="Stops" className="flex flex-col gap-8">
620
+ {TRIP_STOPS.map((stop) => (
621
+ <li key={`${stop.time}-${stop.station}`} className="flex items-baseline gap-12">
622
+ <Typography variant="body-small-low" className="shrink-0 text-text-secondary">
623
+ {stop.time}
624
+ </Typography>
625
+ <Typography variant="body-small-high">{stop.station}</Typography>
626
+ {stop.platform && (
627
+ <Typography variant="caption-sm" className="text-text-tertiary">
628
+ {stop.platform}
629
+ </Typography>
630
+ )}
631
+ </li>
632
+ ))}
633
+ </ol>
342
634
  </ChatCardContent>
635
+ <ChatCardFooter>
636
+ <ChatCardFooterNotes>
637
+ <Typography variant="caption-sm" className="text-text-secondary">
638
+ {TRIP_CONNECTIONS[0].fare}
639
+ </Typography>
640
+ </ChatCardFooterNotes>
641
+ <ChatCardFooterPrice>
642
+ <Typography variant="body-small-low" fontWeight="bold">
643
+ {TRIP_CONNECTIONS[0].price}
644
+ </Typography>
645
+ </ChatCardFooterPrice>
646
+ <ChatCardFooterActions>
647
+ <Button variant="primary">Select</Button>
648
+ </ChatCardFooterActions>
649
+ </ChatCardFooter>
343
650
  </ChatCardBody>
344
651
  <ChatCardPreview>
345
- <p>preview</p>
652
+ <Typography variant="body-small-high" className="text-text-secondary">
653
+ {TRIP_CONNECTIONS[0].duration} • {TRIP_CONNECTIONS[0].changes} • from{' '}
654
+ {TRIP_CONNECTIONS[0].price}
655
+ </Typography>
346
656
  </ChatCardPreview>
347
657
  </ChatCard>
348
658
  ),
349
659
  };
660
+
661
+ /** Clicks the preview of the closed connection: the card expands, the preview goes and the stops and the action appear. */
662
+ export const WithPreviewExpand: Story = {
663
+ ...WithPreview,
664
+ tags: ['e2e', '!autodocs'],
665
+ args: { defaultOpen: false, onOpenChange: fn() },
666
+ play: async ({ args, canvas, userEvent, step }) => {
667
+ const card = canvas.getByRole('region', { name: TRIP_CONNECTIONS[0].route });
668
+
669
+ await step('Starts closed with the preview and no body', async () => {
670
+ await expect(card).toHaveAttribute('data-state', 'closed');
671
+ await expect(canvas.getByText(/1 h 59 min • 1 change/)).toBeVisible();
672
+ await expect(canvas.queryByRole('list', { name: 'Stops' })).toBeNull();
673
+ });
674
+
675
+ await step('A click on the preview expands the card', async () => {
676
+ await userEvent.click(canvas.getByText(/1 h 59 min • 1 change/));
677
+ await expect(card).toHaveAttribute('data-state', 'open');
678
+ await expect(canvas.getByRole('list', { name: 'Stops' })).toBeVisible();
679
+ await expect(canvas.getByRole('button', { name: 'Select' })).toBeVisible();
680
+ await expect(canvas.getByText(/1 h 59 min • 1 change/)).not.toBeVisible();
681
+ await expect(args.onOpenChange).toHaveBeenLastCalledWith(true);
682
+ });
683
+ },
684
+ };
685
+
686
+ interface EmailCardProps extends Omit<ChatCardProps, 'children'> {
687
+ email: EmailMessage;
688
+ }
689
+
690
+ function EmailCard({ email, ...rest }: EmailCardProps) {
691
+ const titleId = `${email.id}-title`;
692
+
693
+ return (
694
+ <ChatCard aria-labelledby={titleId} {...rest}>
695
+ <ChatCardHeader>
696
+ <ChatCardIcon>
697
+ <MailIcon fontSize="small" />
698
+ </ChatCardIcon>
699
+ <ChatCardHeaderContent>
700
+ <ChatCardTitle id={titleId}>{email.subject}</ChatCardTitle>
701
+ <ChatCardSubTitle>
702
+ {email.from} • {email.date}
703
+ </ChatCardSubTitle>
704
+ </ChatCardHeaderContent>
705
+ <ChatCardActions>
706
+ <ChatCardCollapsibleButton aria-label={`Collapse or expand ${email.subject}`} />
707
+ </ChatCardActions>
708
+ </ChatCardHeader>
709
+ <ChatCardBody>
710
+ <ChatCardContent>
711
+ <Typography
712
+ variant="body-small-high"
713
+ className="whitespace-pre-line data-[empty=true]:text-text-secondary"
714
+ data-empty={email.body === ''}
715
+ >
716
+ {email.body || 'No message content available.'}
717
+ </Typography>
718
+ </ChatCardContent>
719
+ </ChatCardBody>
720
+ </ChatCard>
721
+ );
722
+ }
723
+
724
+ /** The card in each place its spec allows: a card container, a card list, another card's content, and the chat contexts. */
725
+ export const Examples: Story = {
726
+ parameters: { controls: { disable: true } },
727
+ render: () => (
728
+ <div className="flex flex-col gap-32">
729
+ <ParentBlock parent="web-chat-ui/chat-card-container">
730
+ <ChatCardContainer variant="fluid">
731
+ <ChatCard fullWidth aria-labelledby="code-title">
732
+ <ChatCardHeader>
733
+ <ChatCardIcon>
734
+ <CodeIcon fontSize="small" />
735
+ </ChatCardIcon>
736
+ <ChatCardHeaderContent>
737
+ <ChatCardTitle id="code-title">format-fare.ts</ChatCardTitle>
738
+ </ChatCardHeaderContent>
739
+ <ChatCardActions>
740
+ <ChatCardActionButton aria-label="Copy code" tooltip="Copy code">
741
+ <CopyIcon />
742
+ </ChatCardActionButton>
743
+ <ChatCardActionButton aria-label="Download code" tooltip="Download code">
744
+ <DownloadIcon />
745
+ </ChatCardActionButton>
746
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the code" />
747
+ </ChatCardActions>
748
+ </ChatCardHeader>
749
+ <ChatCardBody>
750
+ <ChatCardContent hasHeaderPadding={false}>
751
+ <Typography variant="body-small-low" fontFamily="mono" asChild>
752
+ <pre className="overflow-auto">
753
+ <code>{CODE_SNIPPET}</code>
754
+ </pre>
755
+ </Typography>
756
+ </ChatCardContent>
757
+ </ChatCardBody>
758
+ </ChatCard>
759
+ </ChatCardContainer>
760
+ </ParentBlock>
761
+
762
+ <ParentBlock parent="web-chat-ui/ChatCardListLayoutItems">
763
+ <ChatCardContainer variant="fixed">
764
+ <ChatCardListLayout className="flex flex-col gap-8">
765
+ <ChatCardListLayoutItems>
766
+ {INBOX_EMAILS.map((email) => (
767
+ <EmailCard key={email.id} email={email} defaultOpen={false} />
768
+ ))}
769
+ </ChatCardListLayoutItems>
770
+ <ChatCardListLayoutShowMore>Show more</ChatCardListLayoutShowMore>
771
+ </ChatCardListLayout>
772
+ </ChatCardContainer>
773
+ </ParentBlock>
774
+
775
+ <ParentBlock parent="web-chat-ui/ChatCardContent">
776
+ <ChatCard aria-labelledby="nested-booking-title">
777
+ <ChatCardHeader>
778
+ <ChatCardIcon>
779
+ <TicketOnLineIcon fontSize="small" />
780
+ </ChatCardIcon>
781
+ <ChatCardHeaderContent>
782
+ <ChatCardTitle id="nested-booking-title">Booking details</ChatCardTitle>
783
+ </ChatCardHeaderContent>
784
+ <ChatCardActions>
785
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the booking details" />
786
+ </ChatCardActions>
787
+ </ChatCardHeader>
788
+ <ChatCardBody>
789
+ <ChatCardContent hasHeaderPadding={false}>
790
+ <TripCard connection={TRIP_CONNECTIONS[1]} />
791
+ </ChatCardContent>
792
+ </ChatCardBody>
793
+ </ChatCard>
794
+ </ParentBlock>
795
+
796
+ <ParentBlock parent="chat answer">
797
+ <section aria-label="Chat answer" className="flex flex-col gap-12">
798
+ <Typography variant="body-small-high">
799
+ I drafted the reply to Nora. Review it before I send it.
800
+ </Typography>
801
+ <ChatCardContainer variant="fixed">
802
+ <EmailCard email={EMAIL_DRAFT} />
803
+ </ChatCardContainer>
804
+ </section>
805
+ </ParentBlock>
806
+
807
+ <ParentBlock parent="chat message body">
808
+ <section aria-label="Chat message body" className="flex flex-col gap-12">
809
+ <Typography id="forecast-intro" variant="body-small-high">
810
+ Pack a rain jacket for Saturday. Here is the weekend in Interlaken:
811
+ </Typography>
812
+ <ChatCardContainer variant="fixed" inline>
813
+ <ChatCard isCollapsible={false} aria-labelledby="forecast-intro">
814
+ <ChatCardBody>
815
+ <ChatCardContent>
816
+ <ul className="flex flex-col gap-8">
817
+ {WEEKEND_FORECAST.map((forecast) => (
818
+ <li key={forecast.day} className="flex items-baseline gap-12">
819
+ <Typography variant="body-small-high" className="w-32 shrink-0">
820
+ {forecast.day}
821
+ </Typography>
822
+ <Typography variant="body-small-low" className="flex-1 text-text-secondary">
823
+ {forecast.summary}
824
+ </Typography>
825
+ <Typography variant="body-small-low">{forecast.temperature}</Typography>
826
+ </li>
827
+ ))}
828
+ </ul>
829
+ </ChatCardContent>
830
+ </ChatCardBody>
831
+ </ChatCard>
832
+ </ChatCardContainer>
833
+ <Typography variant="body-small-high">
834
+ Sunday clears up again, so the hike is still on.
835
+ </Typography>
836
+ </section>
837
+ </ParentBlock>
838
+
839
+ <ParentBlock parent="chat card list">
840
+ <ul aria-label="Chat card list" className="grid grid-cols-1 gap-8 md:grid-cols-3">
841
+ {NEWS_ARTICLES.map((article) => (
842
+ <li key={article.id} className="flex">
843
+ <ChatCard variant="action" isCollapsible={false} aria-labelledby={article.id}>
844
+ <ChatCardBody>
845
+ <ChatCardMedia
846
+ role="img"
847
+ aria-label={`Photo: ${article.headline}`}
848
+ className="bg-paper-elevation-2"
849
+ >
850
+ {null}
851
+ </ChatCardMedia>
852
+ <ChatCardContent>
853
+ <Typography variant="caption-sm" className="text-text-secondary">
854
+ {article.sourceName}
855
+ </Typography>
856
+ <Typography
857
+ variant="body-small-high"
858
+ fontWeight="semibold"
859
+ className="line-clamp-4"
860
+ asChild
861
+ >
862
+ <a id={article.id} href="#news">
863
+ {article.headline}
864
+ </a>
865
+ </Typography>
866
+ </ChatCardContent>
867
+ <ChatCardFooter>
868
+ <ChatCardFooterNotes>
869
+ <Typography variant="caption-sm" className="text-text-tertiary">
870
+ {article.publishedAt}
871
+ </Typography>
872
+ </ChatCardFooterNotes>
873
+ </ChatCardFooter>
874
+ </ChatCardBody>
875
+ </ChatCard>
876
+ </li>
877
+ ))}
878
+ </ul>
879
+ </ParentBlock>
880
+ </div>
881
+ ),
882
+ };
883
+
884
+ interface ChatCardPlaygroundProps extends Omit<ChatCardProps, 'children' | 'title'> {
885
+ title: string;
886
+ subTitle: string;
887
+ preview: string;
888
+ hasIcon: boolean;
889
+ hasHeaderAction: boolean;
890
+ hasMedia: boolean;
891
+ hasAttributes: boolean;
892
+ hasFooterNotes: boolean;
893
+ hasFooterPrice: boolean;
894
+ hasFooterActions: boolean;
895
+ hasPreview: boolean;
896
+ hasPadding: boolean;
897
+ hasHeaderPadding: boolean;
898
+ onHeaderAction: () => void;
899
+ }
900
+
901
+ function ChatCardPlayground({
902
+ title,
903
+ subTitle,
904
+ preview,
905
+ hasIcon,
906
+ hasHeaderAction,
907
+ hasMedia,
908
+ hasAttributes,
909
+ hasFooterNotes,
910
+ hasFooterPrice,
911
+ hasFooterActions,
912
+ hasPreview,
913
+ hasPadding,
914
+ hasHeaderPadding,
915
+ onHeaderAction,
916
+ ...rest
917
+ }: ChatCardPlaygroundProps) {
918
+ return (
919
+ <ChatCard {...rest} aria-labelledby="playground-title">
920
+ <ChatCardHeader>
921
+ {hasIcon && (
922
+ <ChatCardIcon>
923
+ <TicketOnLineIcon fontSize="small" />
924
+ </ChatCardIcon>
925
+ )}
926
+ <ChatCardHeaderContent>
927
+ <ChatCardTitle id="playground-title">{title}</ChatCardTitle>
928
+ {subTitle && <ChatCardSubTitle>{subTitle}</ChatCardSubTitle>}
929
+ </ChatCardHeaderContent>
930
+ <ChatCardActions>
931
+ {hasHeaderAction && (
932
+ <ChatCardActionButton
933
+ aria-label="Download tickets"
934
+ tooltip="Download tickets"
935
+ onClick={onHeaderAction}
936
+ >
937
+ <DownloadIcon />
938
+ </ChatCardActionButton>
939
+ )}
940
+ <ChatCardCollapsibleButton aria-label="Collapse or expand the booking details" />
941
+ </ChatCardActions>
942
+ </ChatCardHeader>
943
+ <ChatCardBody>
944
+ {hasMedia && (
945
+ <ChatCardMedia
946
+ role="img"
947
+ aria-label="Map of the route from Zürich HB to Interlaken Ost"
948
+ className="bg-paper-elevation-2"
949
+ >
950
+ {null}
951
+ </ChatCardMedia>
952
+ )}
953
+ <ChatCardContent hasPadding={hasPadding} hasHeaderPadding={hasHeaderPadding}>
954
+ <Typography variant="body-small-high">
955
+ Both trips are held for 20 minutes. Check the passengers before you select them.
956
+ </Typography>
957
+ </ChatCardContent>
958
+ {hasAttributes && (
959
+ <ChatCardForm onSubmit={(event) => event.preventDefault()}>
960
+ <ChatCardAttributes>
961
+ <ChatCardAttribute>
962
+ <ChatCardAttributeLabel>Out</ChatCardAttributeLabel>
963
+ <ChatCardAttributeValue>
964
+ {TRIP_CONNECTIONS[0].route} • {TRIP_CONNECTIONS[0].date} •{' '}
965
+ {TRIP_CONNECTIONS[0].times}
966
+ </ChatCardAttributeValue>
967
+ </ChatCardAttribute>
968
+ <ChatCardAttribute>
969
+ <ChatCardAttributeLabel>Return</ChatCardAttributeLabel>
970
+ <ChatCardAttributeValue>
971
+ {TRIP_CONNECTIONS[1].route} • {TRIP_CONNECTIONS[1].date} •{' '}
972
+ {TRIP_CONNECTIONS[1].times}
973
+ </ChatCardAttributeValue>
974
+ </ChatCardAttribute>
975
+ </ChatCardAttributes>
976
+ </ChatCardForm>
977
+ )}
978
+ <ChatCardFooter>
979
+ {hasFooterNotes && (
980
+ <ChatCardFooterNotes>
981
+ <Typography variant="caption-sm" className="text-layout-feedback-success-text-base">
982
+ 2/2 trips available to book
983
+ </Typography>
984
+ <Typography variant="caption-sm" className="text-text-secondary">
985
+ 2 passengers • 2 trips • 4 tickets
986
+ </Typography>
987
+ </ChatCardFooterNotes>
988
+ )}
989
+ {hasFooterPrice && (
990
+ <ChatCardFooterPrice>
991
+ <Typography variant="caption-sm" className="text-layout-feedback-info-text-base">
992
+ Swisper 5% discount applied
993
+ </Typography>
994
+ <Typography variant="body-small-low" fontWeight="bold">
995
+ CHF 125.40
996
+ </Typography>
997
+ </ChatCardFooterPrice>
998
+ )}
999
+ {hasFooterActions && (
1000
+ <ChatCardFooterActions>
1001
+ <Button variant="tertiary">Cancel</Button>
1002
+ <Button variant="primary">Select</Button>
1003
+ </ChatCardFooterActions>
1004
+ )}
1005
+ </ChatCardFooter>
1006
+ </ChatCardBody>
1007
+ {hasPreview && (
1008
+ <ChatCardPreview>
1009
+ <Typography variant="body-small-high" className="text-text-secondary">
1010
+ {preview}
1011
+ </Typography>
1012
+ </ChatCardPreview>
1013
+ )}
1014
+ </ChatCard>
1015
+ );
1016
+ }
1017
+
1018
+ /** Every part of the card at once on a trip booking, with each root prop and each part on the Controls panel. */
1019
+ export const Playground: StoryObj<typeof ChatCardPlayground> = {
1020
+ tags: ['!autodocs'],
1021
+ args: {
1022
+ title: 'Booking details • Zürich HB to Interlaken Ost',
1023
+ subTitle: 'Tue, Oct 15 – Sat, Oct 19 • 2 passengers',
1024
+ preview: '2 trips • 4 tickets • CHF 125.40',
1025
+ isSelected: false,
1026
+ hasIcon: true,
1027
+ hasHeaderAction: true,
1028
+ hasMedia: true,
1029
+ hasAttributes: true,
1030
+ hasFooterNotes: true,
1031
+ hasFooterPrice: true,
1032
+ hasFooterActions: true,
1033
+ hasPreview: true,
1034
+ hasPadding: true,
1035
+ hasHeaderPadding: true,
1036
+ onHeaderAction: fn(),
1037
+ },
1038
+ argTypes: {
1039
+ title: { control: 'text', description: 'Text of `ChatCardTitle`.' },
1040
+ subTitle: {
1041
+ control: 'text',
1042
+ description: 'Text of `ChatCardSubTitle`; empty leaves the part out.',
1043
+ },
1044
+ preview: { control: 'text', description: 'Text of `ChatCardPreview`, shown while closed.' },
1045
+ hasIcon: { control: 'boolean', description: 'Renders `ChatCardIcon` in the header.' },
1046
+ hasHeaderAction: {
1047
+ control: 'boolean',
1048
+ description: 'Renders a `ChatCardActionButton` beside `ChatCardCollapsibleButton`.',
1049
+ },
1050
+ hasMedia: {
1051
+ control: 'boolean',
1052
+ description: 'Renders `ChatCardMedia` at the top of the body.',
1053
+ },
1054
+ hasAttributes: {
1055
+ control: 'boolean',
1056
+ description: 'Renders `ChatCardForm` with `ChatCardAttributes` rows.',
1057
+ },
1058
+ hasFooterNotes: { control: 'boolean', description: 'Renders `ChatCardFooterNotes`.' },
1059
+ hasFooterPrice: { control: 'boolean', description: 'Renders `ChatCardFooterPrice`.' },
1060
+ hasFooterActions: { control: 'boolean', description: 'Renders `ChatCardFooterActions`.' },
1061
+ hasPreview: { control: 'boolean', description: 'Renders `ChatCardPreview` after the body.' },
1062
+ hasPadding: {
1063
+ control: 'boolean',
1064
+ description: '`hasPadding` of `ChatCardContent`: false removes all its padding.',
1065
+ },
1066
+ hasHeaderPadding: {
1067
+ control: 'boolean',
1068
+ description: '`hasHeaderPadding` of `ChatCardContent`: false removes only its top padding.',
1069
+ },
1070
+ onHeaderAction: { description: 'Called when the header action is clicked.' },
1071
+ },
1072
+ render: (args) => <ChatCardPlayground {...args} />,
1073
+ };