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