@swisper.ai/web-chat-ui 0.0.2
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/LICENSE +202 -0
- package/README.md +251 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts +64 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts +26 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -0
- package/dist/components/canvas-shell/index.d.ts +2 -0
- package/dist/components/canvas-shell/index.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts +21 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts +24 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +28 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts +12 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts +19 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +1 -0
- package/dist/components/card-item-picker/index.d.ts +9 -0
- package/dist/components/card-item-picker/index.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.d.ts +4 -0
- package/dist/components/chat-card/chat-card.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.stories.d.ts +11 -0
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts +22 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts +20 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts +28 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts +36 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -0
- package/dist/components/chat-card/components/index.d.ts +5 -0
- package/dist/components/chat-card/components/index.d.ts.map +1 -0
- package/dist/components/chat-card/context.d.ts +13 -0
- package/dist/components/chat-card/context.d.ts.map +1 -0
- package/dist/components/chat-card/contexts.d.ts +16 -0
- package/dist/components/chat-card/contexts.d.ts.map +1 -0
- package/dist/components/chat-card/hooks.d.ts +13 -0
- package/dist/components/chat-card/hooks.d.ts.map +1 -0
- package/dist/components/chat-card/index.d.ts +6 -0
- package/dist/components/chat-card/index.d.ts.map +1 -0
- package/dist/components/chat-card/types.d.ts +21 -0
- package/dist/components/chat-card/types.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts +43 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts +17 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -0
- package/dist/components/chat-card-container/index.d.ts +3 -0
- package/dist/components/chat-card-container/index.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.d.ts +51 -0
- package/dist/components/chat-container/chat-container.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.stories.d.ts +21 -0
- package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -0
- package/dist/components/chat-container/index.d.ts +3 -0
- package/dist/components/chat-container/index.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.d.ts +35 -0
- package/dist/components/chat-input/chat-input.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.stories.d.ts +14 -0
- package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -0
- package/dist/components/chat-input/index.d.ts +3 -0
- package/dist/components/chat-input/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts +8 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts +7 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/hooks.d.ts +2 -0
- package/dist/components/chat-input/plugins/hooks.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/index.d.ts +8 -0
- package/dist/components/chat-input/plugins/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/utils.d.ts +4 -0
- package/dist/components/chat-input/plugins/utils.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/transformers.d.ts +3 -0
- package/dist/components/chat-input/transformers.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-item.d.ts +8 -0
- package/dist/components/chat-list/chat-list-item.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-items.d.ts +11 -0
- package/dist/components/chat-list/chat-list-items.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.d.ts +63 -0
- package/dist/components/chat-list/chat-list.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.stories.d.ts +13 -0
- package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -0
- package/dist/components/chat-list/index.d.ts +4 -0
- package/dist/components/chat-list/index.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.d.ts +17 -0
- package/dist/components/chat-message/chat-message.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.stories.d.ts +11 -0
- package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -0
- package/dist/components/chat-message/index.d.ts +2 -0
- package/dist/components/chat-message/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +9 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +30 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +11 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/index.d.ts +4 -0
- package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts +5 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts +48 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts +7 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +1 -0
- package/dist/components/chat-message-history/index.d.ts +2 -0
- package/dist/components/chat-message-history/index.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -0
- package/dist/components/chat-message-response/index.d.ts +2 -0
- package/dist/components/chat-message-response/index.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +25 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +7 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/index.d.ts +2 -0
- package/dist/components/chat-message-toolbar/index.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.d.ts +24 -0
- package/dist/components/chat-messages/chat-messages.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts +8 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -0
- package/dist/components/chat-messages/index.d.ts +2 -0
- package/dist/components/chat-messages/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts +114 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +10 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-card/index.d.ts +4 -0
- package/dist/components/chat-notification-card/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/types.d.ts +2 -0
- package/dist/components/chat-notification-card/types.d.ts.map +1 -0
- package/dist/components/chat-notification-card/utils.d.ts +3 -0
- package/dist/components/chat-notification-card/utils.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +12 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +8 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/index.d.ts +2 -0
- package/dist/components/chat-notification-popup/index.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts +17 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts +2 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +27 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +9 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/index.d.ts +3 -0
- package/dist/components/chat-prompt-box/index.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.d.ts +23 -0
- package/dist/components/chat-reply/chat-reply.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts +7 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -0
- package/dist/components/chat-reply/index.d.ts +2 -0
- package/dist/components/chat-reply/index.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts +37 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +9 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -0
- package/dist/components/chat-suggestion/index.d.ts +2 -0
- package/dist/components/chat-suggestion/index.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +47 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +10 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/index.d.ts +2 -0
- package/dist/components/chat-thinking-process/index.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.d.ts +78 -0
- package/dist/components/chat-thread/chat-thread.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts +14 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -0
- package/dist/components/chat-thread/index.d.ts +2 -0
- package/dist/components/chat-thread/index.d.ts.map +1 -0
- package/dist/components/deprecated-empty-state.d.ts +22 -0
- package/dist/components/deprecated-empty-state.d.ts.map +1 -0
- package/dist/components/index.d.ts +27 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/hooks.d.ts +9 -0
- package/dist/components/markdown-viewer/hooks.d.ts.map +1 -0
- package/dist/components/markdown-viewer/index.d.ts +3 -0
- package/dist/components/markdown-viewer/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts +10 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +9 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -0
- package/dist/components/markdown-viewer/types.d.ts +9 -0
- package/dist/components/markdown-viewer/types.d.ts.map +1 -0
- package/dist/components/markdown-viewer/utils.d.ts +3 -0
- package/dist/components/markdown-viewer/utils.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/index.d.ts +2 -0
- package/dist/components/new-chat-trigger/index.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts +8 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts.map +1 -0
- package/dist/components/rich-text-area/constants/index.d.ts +3 -0
- package/dist/components/rich-text-area/constants/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/hooks.d.ts +3 -0
- package/dist/components/rich-text-area/hooks.d.ts.map +1 -0
- package/dist/components/rich-text-area/html-config.d.ts +4 -0
- package/dist/components/rich-text-area/html-config.d.ts.map +1 -0
- package/dist/components/rich-text-area/index.d.ts +7 -0
- package/dist/components/rich-text-area/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts +18 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts +24 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts +10 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts +19 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts +12 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/index.d.ts +11 -0
- package/dist/components/rich-text-area/plugins/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts +20 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts +7 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -0
- package/dist/components/rich-text-area/styled.d.ts +3 -0
- package/dist/components/rich-text-area/styled.d.ts.map +1 -0
- package/dist/components/rich-text-area/transformers.d.ts +16 -0
- package/dist/components/rich-text-area/transformers.d.ts.map +1 -0
- package/dist/components/rich-text-area/types.d.ts +8 -0
- package/dist/components/rich-text-area/types.d.ts.map +1 -0
- package/dist/components/rich-text-area/utils/index.d.ts +6 -0
- package/dist/components/rich-text-area/utils/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +11 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/image-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/image-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/index.d.ts +14 -0
- package/dist/components/rich-text-field/components/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/link-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/link-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/size-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/size-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts +6 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/constants.d.ts +57 -0
- package/dist/components/rich-text-field/constants.d.ts.map +1 -0
- package/dist/components/rich-text-field/context.d.ts +26 -0
- package/dist/components/rich-text-field/context.d.ts.map +1 -0
- package/dist/components/rich-text-field/index.d.ts +3 -0
- package/dist/components/rich-text-field/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts +17 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts +10 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -0
- package/dist/components/rich-text-field/utils.d.ts +1759 -0
- package/dist/components/rich-text-field/utils.d.ts.map +1 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.d.ts.map +1 -0
- package/dist/components/spinner/spinner.d.ts +9 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -0
- package/dist/components/spinner/spinner.stories.d.ts +8 -0
- package/dist/components/spinner/spinner.stories.d.ts.map +1 -0
- package/dist/contexts/chat-context/chat-context.d.ts +20 -0
- package/dist/contexts/chat-context/chat-context.d.ts.map +1 -0
- package/dist/contexts/chat-context/index.d.ts +2 -0
- package/dist/contexts/chat-context/index.d.ts.map +1 -0
- package/dist/contexts/chat-context/utils.d.ts +3 -0
- package/dist/contexts/chat-context/utils.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts +20 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/index.d.ts +2 -0
- package/dist/contexts/chat-conversation-context/index.d.ts.map +1 -0
- package/dist/contexts/index.d.ts +3 -0
- package/dist/contexts/index.d.ts.map +1 -0
- package/dist/docs/agent.stories.d.ts +41 -0
- package/dist/docs/agent.stories.d.ts.map +1 -0
- package/dist/docs/chat-panel.d.ts +33 -0
- package/dist/docs/chat-panel.d.ts.map +1 -0
- package/dist/docs/chatbot-panel.d.ts +20 -0
- package/dist/docs/chatbot-panel.d.ts.map +1 -0
- package/dist/docs/chatbot.stories.d.ts +11 -0
- package/dist/docs/chatbot.stories.d.ts.map +1 -0
- package/dist/domain/actions/constants.d.ts +2 -0
- package/dist/domain/actions/constants.d.ts.map +1 -0
- package/dist/domain/actions/hooks/index.d.ts +3 -0
- package/dist/domain/actions/hooks/index.d.ts.map +1 -0
- package/dist/domain/actions/index.d.ts +5 -0
- package/dist/domain/actions/index.d.ts.map +1 -0
- package/dist/domain/actions/types.d.ts +7 -0
- package/dist/domain/actions/types.d.ts.map +1 -0
- package/dist/domain/actions/utils/index.d.ts +11 -0
- package/dist/domain/actions/utils/index.d.ts.map +1 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts +6 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts.map +1 -0
- package/dist/hooks/use-chat-stream-message.d.ts +42 -0
- package/dist/hooks/use-chat-stream-message.d.ts.map +1 -0
- package/dist/hooks/use-current-chat-id.d.ts +2 -0
- package/dist/hooks/use-current-chat-id.d.ts.map +1 -0
- package/dist/hooks/use-is-current-chat-new.d.ts +2 -0
- package/dist/hooks/use-is-current-chat-new.d.ts.map +1 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts +9 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts.map +1 -0
- package/dist/hooks/use-on-chat-changed.d.ts +9 -0
- package/dist/hooks/use-on-chat-changed.d.ts.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +4404 -0
- package/dist/index.es.js.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +95 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +24 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts +3 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +84 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +45 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +37 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +81 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts +5 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +31 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +12 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +19 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +35 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts +4 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/index.d.ts +4 -0
- package/dist/layouts/index.d.ts.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/use-streaming-markdown.d.ts +18 -0
- package/dist/utils/use-streaming-markdown.d.ts.map +1 -0
- package/package.json +155 -0
- package/src/__tests__/setup.ts +5 -0
- package/src/components/canvas-shell/canvas-shell.json +126 -0
- package/src/components/canvas-shell/canvas-shell.stories.tsx +194 -0
- package/src/components/canvas-shell/canvas-shell.test.tsx +205 -0
- package/src/components/canvas-shell/canvas-shell.tsx +250 -0
- package/src/components/canvas-shell/index.ts +19 -0
- package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +279 -0
- package/src/components/card-item-picker/card-item-picker-context.tsx +44 -0
- package/src/components/card-item-picker/card-item-picker-list.tsx +95 -0
- package/src/components/card-item-picker/card-item-picker-row-parts.tsx +96 -0
- package/src/components/card-item-picker/card-item-picker-row.tsx +109 -0
- package/src/components/card-item-picker/card-item-picker.json +147 -0
- package/src/components/card-item-picker/card-item-picker.stories.tsx +158 -0
- package/src/components/card-item-picker/index.ts +24 -0
- package/src/components/chat-card/__tests__/chat-card.spec.tsx +118 -0
- package/src/components/chat-card/chat-card.json +162 -0
- package/src/components/chat-card/chat-card.stories.tsx +349 -0
- package/src/components/chat-card/chat-card.tsx +106 -0
- package/src/components/chat-card/components/chat-card-body.tsx +115 -0
- package/src/components/chat-card/components/chat-card-footer.tsx +95 -0
- package/src/components/chat-card/components/chat-card-form.tsx +120 -0
- package/src/components/chat-card/components/chat-card-header.tsx +240 -0
- package/src/components/chat-card/components/index.ts +4 -0
- package/src/components/chat-card/context.tsx +34 -0
- package/src/components/chat-card/contexts.tsx +42 -0
- package/src/components/chat-card/hooks.ts +51 -0
- package/src/components/chat-card/index.ts +5 -0
- package/src/components/chat-card/types.ts +23 -0
- package/src/components/chat-card-container/chat-card-container.json +84 -0
- package/src/components/chat-card-container/chat-card-container.stories.tsx +149 -0
- package/src/components/chat-card-container/chat-card-container.tsx +75 -0
- package/src/components/chat-card-container/index.ts +2 -0
- package/src/components/chat-container/chat-container.json +93 -0
- package/src/components/chat-container/chat-container.stories.tsx +179 -0
- package/src/components/chat-container/chat-container.tsx +231 -0
- package/src/components/chat-container/index.ts +2 -0
- package/src/components/chat-input/chat-input.json +106 -0
- package/src/components/chat-input/chat-input.stories.tsx +291 -0
- package/src/components/chat-input/chat-input.tsx +220 -0
- package/src/components/chat-input/index.ts +2 -0
- package/src/components/chat-input/plugins/auto-focus-plugin.tsx +43 -0
- package/src/components/chat-input/plugins/controlled-value-plugin.tsx +47 -0
- package/src/components/chat-input/plugins/disabled-plugin.tsx +18 -0
- package/src/components/chat-input/plugins/focus-plugin.tsx +44 -0
- package/src/components/chat-input/plugins/has-value-plugin.tsx +51 -0
- package/src/components/chat-input/plugins/hooks.ts +7 -0
- package/src/components/chat-input/plugins/index.ts +7 -0
- package/src/components/chat-input/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/chat-input/plugins/utils.ts +48 -0
- package/src/components/chat-input/plugins/value-plugin.tsx +35 -0
- package/src/components/chat-input/transformers.ts +4 -0
- package/src/components/chat-list/chat-list-item.tsx +33 -0
- package/src/components/chat-list/chat-list-items.tsx +144 -0
- package/src/components/chat-list/chat-list.json +117 -0
- package/src/components/chat-list/chat-list.stories.tsx +332 -0
- package/src/components/chat-list/chat-list.tsx +278 -0
- package/src/components/chat-list/index.ts +18 -0
- package/src/components/chat-message/chat-message.json +105 -0
- package/src/components/chat-message/chat-message.stories.tsx +95 -0
- package/src/components/chat-message/chat-message.tsx +66 -0
- package/src/components/chat-message/index.ts +1 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +74 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +110 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +131 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +142 -0
- package/src/components/chat-message-attachment-card/index.ts +12 -0
- package/src/components/chat-message-attachment-card/utils.ts +41 -0
- package/src/components/chat-message-history/chat-message-history.json +99 -0
- package/src/components/chat-message-history/chat-message-history.stories.tsx +136 -0
- package/src/components/chat-message-history/chat-message-history.tsx +277 -0
- package/src/components/chat-message-history/index.ts +13 -0
- package/src/components/chat-message-response/chat-message-response.json +68 -0
- package/src/components/chat-message-response/chat-message-response.stories.tsx +63 -0
- package/src/components/chat-message-response/chat-message-response.tsx +24 -0
- package/src/components/chat-message-response/index.ts +1 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.json +100 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +62 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +97 -0
- package/src/components/chat-message-toolbar/index.ts +6 -0
- package/src/components/chat-messages/chat-messages.json +95 -0
- package/src/components/chat-messages/chat-messages.stories.tsx +284 -0
- package/src/components/chat-messages/chat-messages.tsx +264 -0
- package/src/components/chat-messages/index.ts +10 -0
- package/src/components/chat-notification-card/chat-notification-card.json +135 -0
- package/src/components/chat-notification-card/chat-notification-card.stories.tsx +290 -0
- package/src/components/chat-notification-card/chat-notification-card.tsx +684 -0
- package/src/components/chat-notification-card/index.ts +3 -0
- package/src/components/chat-notification-card/types.ts +1 -0
- package/src/components/chat-notification-card/utils.ts +34 -0
- package/src/components/chat-notification-popup/chat-notification-popup.json +97 -0
- package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +80 -0
- package/src/components/chat-notification-popup/chat-notification-popup.tsx +36 -0
- package/src/components/chat-notification-popup/index.ts +1 -0
- package/src/components/chat-prompt-box/chat-prompt-box-context.tsx +62 -0
- package/src/components/chat-prompt-box/chat-prompt-box-focus-plugin.tsx +22 -0
- package/src/components/chat-prompt-box/chat-prompt-box.json +106 -0
- package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +117 -0
- package/src/components/chat-prompt-box/chat-prompt-box.tsx +296 -0
- package/src/components/chat-prompt-box/index.ts +16 -0
- package/src/components/chat-reply/chat-reply.json +79 -0
- package/src/components/chat-reply/chat-reply.stories.tsx +72 -0
- package/src/components/chat-reply/chat-reply.tsx +103 -0
- package/src/components/chat-reply/index.ts +1 -0
- package/src/components/chat-suggestion/chat-suggestion.json +108 -0
- package/src/components/chat-suggestion/chat-suggestion.stories.tsx +147 -0
- package/src/components/chat-suggestion/chat-suggestion.tsx +184 -0
- package/src/components/chat-suggestion/index.ts +8 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +110 -0
- package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +202 -0
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +268 -0
- package/src/components/chat-thinking-process/index.ts +9 -0
- package/src/components/chat-thread/__tests__/chat-thread.spec.tsx +385 -0
- package/src/components/chat-thread/chat-thread.json +120 -0
- package/src/components/chat-thread/chat-thread.stories.tsx +218 -0
- package/src/components/chat-thread/chat-thread.tsx +549 -0
- package/src/components/chat-thread/index.ts +18 -0
- package/src/components/deprecated-empty-state.ts +39 -0
- package/src/components/index.ts +26 -0
- package/src/components/markdown-viewer/hooks.ts +59 -0
- package/src/components/markdown-viewer/index.ts +2 -0
- package/src/components/markdown-viewer/markdown-viewer.json +84 -0
- package/src/components/markdown-viewer/markdown-viewer.stories.tsx +110 -0
- package/src/components/markdown-viewer/markdown-viewer.tsx +95 -0
- package/src/components/markdown-viewer/types.ts +10 -0
- package/src/components/markdown-viewer/utils.ts +5 -0
- package/src/components/new-chat-trigger/index.ts +1 -0
- package/src/components/new-chat-trigger/new-chat-trigger.tsx +29 -0
- package/src/components/rich-text-area/constants/index.ts +10 -0
- package/src/components/rich-text-area/hooks.ts +24 -0
- package/src/components/rich-text-area/html-config.ts +195 -0
- package/src/components/rich-text-area/index.ts +6 -0
- package/src/components/rich-text-area/nodes/div-block-node.tsx +145 -0
- package/src/components/rich-text-area/nodes/image-node.tsx +100 -0
- package/src/components/rich-text-area/plugins/blur-plugin.tsx +36 -0
- package/src/components/rich-text-area/plugins/controlled-plugin.tsx +23 -0
- package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +101 -0
- package/src/components/rich-text-area/plugins/disabled-plugin.tsx +17 -0
- package/src/components/rich-text-area/plugins/file-attachment-plugin.tsx +57 -0
- package/src/components/rich-text-area/plugins/focus-plugin.tsx +44 -0
- package/src/components/rich-text-area/plugins/html-paste-plugin.tsx +104 -0
- package/src/components/rich-text-area/plugins/image-drop-plugin.tsx +56 -0
- package/src/components/rich-text-area/plugins/index.ts +10 -0
- package/src/components/rich-text-area/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/rich-text-area/plugins/value-plugin.tsx +46 -0
- package/src/components/rich-text-area/rich-text-area.json +102 -0
- package/src/components/rich-text-area/rich-text-area.stories.tsx +140 -0
- package/src/components/rich-text-area/rich-text-area.tsx +156 -0
- package/src/components/rich-text-area/styled.tsx +20 -0
- package/src/components/rich-text-area/transformers.ts +175 -0
- package/src/components/rich-text-area/types.ts +8 -0
- package/src/components/rich-text-area/utils/index.ts +77 -0
- package/src/components/rich-text-field/components/alignment-select.tsx +103 -0
- package/src/components/rich-text-field/components/attachment-button.tsx +25 -0
- package/src/components/rich-text-field/components/bold-button.tsx +21 -0
- package/src/components/rich-text-field/components/clean-format-button.tsx +44 -0
- package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +69 -0
- package/src/components/rich-text-field/components/image-button.tsx +11 -0
- package/src/components/rich-text-field/components/index.ts +14 -0
- package/src/components/rich-text-field/components/italic-button.tsx +21 -0
- package/src/components/rich-text-field/components/link-button.tsx +11 -0
- package/src/components/rich-text-field/components/size-select.tsx +27 -0
- package/src/components/rich-text-field/components/text-color-button.tsx +41 -0
- package/src/components/rich-text-field/components/toolbar-button.tsx +27 -0
- package/src/components/rich-text-field/components/toolbar-select.tsx +19 -0
- package/src/components/rich-text-field/components/typography-select.tsx +27 -0
- package/src/components/rich-text-field/components/underline-button.tsx +21 -0
- package/src/components/rich-text-field/constants.ts +33 -0
- package/src/components/rich-text-field/context.tsx +251 -0
- package/src/components/rich-text-field/index.tsx +6 -0
- package/src/components/rich-text-field/rich-text-field.json +118 -0
- package/src/components/rich-text-field/rich-text-field.stories.tsx +218 -0
- package/src/components/rich-text-field/rich-text-field.tsx +93 -0
- package/src/components/rich-text-field/utils.ts +532 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner/spinner.json +73 -0
- package/src/components/spinner/spinner.stories.tsx +41 -0
- package/src/components/spinner/spinner.tsx +32 -0
- package/src/contexts/chat-context/chat-context.tsx +97 -0
- package/src/contexts/chat-context/index.ts +1 -0
- package/src/contexts/chat-context/utils.ts +7 -0
- package/src/contexts/chat-conversation-context/chat-conversation-context.tsx +608 -0
- package/src/contexts/chat-conversation-context/index.ts +1 -0
- package/src/contexts/index.ts +2 -0
- package/src/docs/agent.stories.tsx +567 -0
- package/src/docs/chat-panel.tsx +174 -0
- package/src/docs/chatbot-panel.tsx +381 -0
- package/src/docs/chatbot.mdx +144 -0
- package/src/docs/chatbot.stories.tsx +63 -0
- package/src/domain/actions/constants.ts +1 -0
- package/src/domain/actions/hooks/index.ts +22 -0
- package/src/domain/actions/index.ts +4 -0
- package/src/domain/actions/types.ts +6 -0
- package/src/domain/actions/utils/index.ts +112 -0
- package/src/domain/index.ts +1 -0
- package/src/hooks/index.tsx +10 -0
- package/src/hooks/use-chat-prompt-placeholder.ts +7 -0
- package/src/hooks/use-chat-stream-message.ts +189 -0
- package/src/hooks/use-current-chat-id.ts +6 -0
- package/src/hooks/use-is-current-chat-new.ts +6 -0
- package/src/hooks/use-loaded-chat-ids.ts +32 -0
- package/src/hooks/use-on-chat-changed.ts +33 -0
- package/src/index.css +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +204 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +116 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +190 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +250 -0
- package/src/layouts/chat-card-list-layout/index.ts +11 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +73 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +282 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +131 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +78 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +273 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +291 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +135 -0
- package/src/layouts/chat-card-three-column-layout/index.ts +24 -0
- package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +109 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +97 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +21 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +138 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +132 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +65 -0
- package/src/layouts/chat-card-two-column-layout/index.ts +17 -0
- package/src/layouts/index.ts +3 -0
- package/src/types.ts +29 -0
- package/src/utils/use-streaming-markdown.ts +113 -0
- package/tailwind.css +7 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { useState, type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { CloseIcon, OpenInFullIcon, MoreHorizontalIcon } from '@swisper.ai/icons';
|
|
4
|
+
import {
|
|
5
|
+
IconButton,
|
|
6
|
+
Menu,
|
|
7
|
+
MenuProvider,
|
|
8
|
+
MenuTrigger,
|
|
9
|
+
Typography,
|
|
10
|
+
cn,
|
|
11
|
+
type IconButtonProps,
|
|
12
|
+
type TypographyProps,
|
|
13
|
+
} from '@swisper.ai/ui';
|
|
14
|
+
|
|
15
|
+
// TODO: move this module to @swisper.ai/web-chat-ui, then switch the consumers to it and delete it here.
|
|
16
|
+
|
|
17
|
+
export type CanvasShellProps = ComponentProps<'section'>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Three-row grid: header and footer size to their content, the content row takes the rest.
|
|
21
|
+
* `minmax(0,1fr)` keeps a long list from growing the middle row past the shell's height.
|
|
22
|
+
*/
|
|
23
|
+
export function CanvasShell({ className, ...props }: CanvasShellProps) {
|
|
24
|
+
return (
|
|
25
|
+
<section
|
|
26
|
+
data-slot="canvas-shell"
|
|
27
|
+
className={cn(
|
|
28
|
+
'grid grid-rows-[auto_minmax(0,1fr)_auto]',
|
|
29
|
+
'h-full overflow-hidden',
|
|
30
|
+
className,
|
|
31
|
+
)}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CanvasShellHeaderProps extends ComponentProps<'header'> {
|
|
38
|
+
hasBorder?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function CanvasShellHeader({
|
|
42
|
+
className,
|
|
43
|
+
hasBorder = true,
|
|
44
|
+
...props
|
|
45
|
+
}: CanvasShellHeaderProps) {
|
|
46
|
+
return (
|
|
47
|
+
<header
|
|
48
|
+
data-slot="canvas-shell-header"
|
|
49
|
+
data-separator={hasBorder}
|
|
50
|
+
className={cn(
|
|
51
|
+
'row-start-1',
|
|
52
|
+
'flex items-center gap-[8px]',
|
|
53
|
+
'p-[12px] md:p-[16px]',
|
|
54
|
+
'data-[separator=true]:border-b data-[separator=true]:border-brand-secondary-700',
|
|
55
|
+
className,
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type CanvasShellTitleProps = Omit<TypographyProps, 'variant'>;
|
|
63
|
+
|
|
64
|
+
export function CanvasShellTitle({ className, ...props }: CanvasShellTitleProps) {
|
|
65
|
+
return (
|
|
66
|
+
<Typography
|
|
67
|
+
data-slot="canvas-shell-title"
|
|
68
|
+
variant="label-xl"
|
|
69
|
+
fontWeight="normal"
|
|
70
|
+
className={cn('flex-1 min-w-0 truncate', className)}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type CanvasShellCloseTriggerProps = IconButtonProps;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Icon-only close button; the host decides what closing means through `onClick`.
|
|
80
|
+
*/
|
|
81
|
+
export function CanvasShellCloseTrigger({
|
|
82
|
+
className,
|
|
83
|
+
children,
|
|
84
|
+
...props
|
|
85
|
+
}: CanvasShellCloseTriggerProps) {
|
|
86
|
+
return (
|
|
87
|
+
<IconButton
|
|
88
|
+
data-slot="canvas-shell-close-trigger"
|
|
89
|
+
type="button"
|
|
90
|
+
variant="tertiary"
|
|
91
|
+
size="md"
|
|
92
|
+
aria-label="Close panel"
|
|
93
|
+
className={cn('shrink-0', className)}
|
|
94
|
+
{...props}
|
|
95
|
+
>
|
|
96
|
+
{children || <CloseIcon />}
|
|
97
|
+
</IconButton>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface CanvasShellFullScreenTriggerProps extends Omit<
|
|
102
|
+
IconButtonProps,
|
|
103
|
+
'aria-label' | 'aria-pressed'
|
|
104
|
+
> {
|
|
105
|
+
/** Whether the canvas currently fills the viewport; drives `aria-pressed` and the label. */
|
|
106
|
+
isFullScreen: boolean;
|
|
107
|
+
/** Accessible names for each state; English by default. */
|
|
108
|
+
labels?: { enter?: string; exit?: string };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Toggle between the canvas width and the full viewport; the host owns the state and passes
|
|
113
|
+
* `isFullScreen` and `onClick`. Desktop only: on mobile the canvas already spans the screen.
|
|
114
|
+
*/
|
|
115
|
+
export function CanvasShellFullScreenTrigger({
|
|
116
|
+
className,
|
|
117
|
+
children,
|
|
118
|
+
isFullScreen,
|
|
119
|
+
labels,
|
|
120
|
+
...props
|
|
121
|
+
}: CanvasShellFullScreenTriggerProps) {
|
|
122
|
+
return (
|
|
123
|
+
<IconButton
|
|
124
|
+
data-slot="canvas-shell-full-screen-trigger"
|
|
125
|
+
type="button"
|
|
126
|
+
variant="tertiary"
|
|
127
|
+
size="md"
|
|
128
|
+
aria-pressed={isFullScreen}
|
|
129
|
+
aria-label={
|
|
130
|
+
isFullScreen ? (labels?.exit ?? 'Exit full screen') : (labels?.enter ?? 'Full screen')
|
|
131
|
+
}
|
|
132
|
+
className={cn('shrink-0 max-md:hidden', className)}
|
|
133
|
+
{...props}
|
|
134
|
+
>
|
|
135
|
+
{children || <OpenInFullIcon />}
|
|
136
|
+
</IconButton>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface CanvasShellOptionsButtonProps extends Omit<IconButtonProps, 'children'> {
|
|
141
|
+
/** Menu contents, typically a `DropdownMenuList` of `DropdownMenuListItem`s. */
|
|
142
|
+
children: ReactNode;
|
|
143
|
+
/** Classes for the dropdown panel. */
|
|
144
|
+
menuClassName?: string;
|
|
145
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* "More options" button that opens a dropdown of canvas actions passed as children.
|
|
150
|
+
*/
|
|
151
|
+
export function CanvasShellOptionsButton({
|
|
152
|
+
className,
|
|
153
|
+
children,
|
|
154
|
+
menuClassName,
|
|
155
|
+
onOpenChange,
|
|
156
|
+
...props
|
|
157
|
+
}: CanvasShellOptionsButtonProps) {
|
|
158
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
159
|
+
|
|
160
|
+
function handleOpenChange(open: boolean) {
|
|
161
|
+
setIsOpen(open);
|
|
162
|
+
onOpenChange?.(open);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<MenuProvider modal={false} onOpenChange={handleOpenChange}>
|
|
167
|
+
<MenuTrigger asChild>
|
|
168
|
+
<IconButton
|
|
169
|
+
data-slot="canvas-shell-options-button"
|
|
170
|
+
type="button"
|
|
171
|
+
variant="tertiary"
|
|
172
|
+
size="md"
|
|
173
|
+
isActive={isOpen}
|
|
174
|
+
aria-label="More options"
|
|
175
|
+
className={cn('shrink-0', className)}
|
|
176
|
+
{...props}
|
|
177
|
+
>
|
|
178
|
+
<MoreHorizontalIcon />
|
|
179
|
+
</IconButton>
|
|
180
|
+
</MenuTrigger>
|
|
181
|
+
<Menu className={cn('w-[200px]', menuClassName)}>{children}</Menu>
|
|
182
|
+
</MenuProvider>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface CanvasShellContentProps extends ComponentProps<'div'> {
|
|
187
|
+
/**
|
|
188
|
+
* Apply the shell's horizontal padding (`canvasShellContentPadding`).
|
|
189
|
+
* Set false for edge-to-edge children that pad themselves.
|
|
190
|
+
*/
|
|
191
|
+
hasPadding?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Scroll children that overflow the region, on either axis, with always-visible scrollbars.
|
|
194
|
+
* When false, the region clips overflow: for children that scroll themselves.
|
|
195
|
+
*/
|
|
196
|
+
hasScroll?: boolean;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Horizontal padding of the content region; reuse it to align custom scroll areas with the shell.
|
|
201
|
+
*/
|
|
202
|
+
export const canvasShellContentPadding = 'px-[12px] md:px-[16px]';
|
|
203
|
+
|
|
204
|
+
export function CanvasShellContent({
|
|
205
|
+
className,
|
|
206
|
+
hasPadding = true,
|
|
207
|
+
hasScroll = true,
|
|
208
|
+
children,
|
|
209
|
+
...props
|
|
210
|
+
}: CanvasShellContentProps) {
|
|
211
|
+
return (
|
|
212
|
+
<div
|
|
213
|
+
data-slot="canvas-shell-content"
|
|
214
|
+
data-has-scroll={hasScroll}
|
|
215
|
+
className={cn('row-start-2', 'relative min-w-0 overflow-hidden', className)}
|
|
216
|
+
{...props}
|
|
217
|
+
>
|
|
218
|
+
<div
|
|
219
|
+
data-slot="canvas-shell-content-body"
|
|
220
|
+
data-spacing={hasPadding}
|
|
221
|
+
className={cn(
|
|
222
|
+
'size-full',
|
|
223
|
+
'py-[16px]',
|
|
224
|
+
hasPadding && canvasShellContentPadding,
|
|
225
|
+
hasScroll ? 'overflow-auto' : 'overflow-hidden',
|
|
226
|
+
)}
|
|
227
|
+
>
|
|
228
|
+
{children}
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export type CanvasShellFooterProps = ComponentProps<'footer'>;
|
|
235
|
+
|
|
236
|
+
export function CanvasShellFooter({ className, ...props }: CanvasShellFooterProps) {
|
|
237
|
+
return (
|
|
238
|
+
<footer
|
|
239
|
+
data-slot="canvas-shell-footer"
|
|
240
|
+
className={cn(
|
|
241
|
+
'row-start-3',
|
|
242
|
+
'flex items-center justify-end gap-[8px]',
|
|
243
|
+
'p-[12px] md:p-[16px]',
|
|
244
|
+
'pb-[20px]',
|
|
245
|
+
className,
|
|
246
|
+
)}
|
|
247
|
+
{...props}
|
|
248
|
+
/>
|
|
249
|
+
);
|
|
250
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
CanvasShell,
|
|
3
|
+
CanvasShellCloseTrigger,
|
|
4
|
+
CanvasShellContent,
|
|
5
|
+
CanvasShellFooter,
|
|
6
|
+
CanvasShellFullScreenTrigger,
|
|
7
|
+
CanvasShellHeader,
|
|
8
|
+
CanvasShellOptionsButton,
|
|
9
|
+
CanvasShellTitle,
|
|
10
|
+
canvasShellContentPadding,
|
|
11
|
+
type CanvasShellCloseTriggerProps,
|
|
12
|
+
type CanvasShellContentProps,
|
|
13
|
+
type CanvasShellFooterProps,
|
|
14
|
+
type CanvasShellFullScreenTriggerProps,
|
|
15
|
+
type CanvasShellHeaderProps,
|
|
16
|
+
type CanvasShellOptionsButtonProps,
|
|
17
|
+
type CanvasShellProps,
|
|
18
|
+
type CanvasShellTitleProps,
|
|
19
|
+
} from './canvas-shell';
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CardItemPickerList,
|
|
6
|
+
CardItemPickerRow,
|
|
7
|
+
CardItemPickerRowCheckbox,
|
|
8
|
+
CardItemPickerRowContent,
|
|
9
|
+
CardItemPickerRowDescription,
|
|
10
|
+
CardItemPickerRowTitle,
|
|
11
|
+
type CardItemPickerOrientation,
|
|
12
|
+
} from '..';
|
|
13
|
+
|
|
14
|
+
const CITIES = ['Zurich', 'Geneva', 'Basel'];
|
|
15
|
+
|
|
16
|
+
function renderList({
|
|
17
|
+
value = null,
|
|
18
|
+
hoveredValue = null,
|
|
19
|
+
orientation,
|
|
20
|
+
onValueChange = vi.fn(),
|
|
21
|
+
onHoverChange = vi.fn(),
|
|
22
|
+
}: {
|
|
23
|
+
value?: string | null;
|
|
24
|
+
hoveredValue?: string | null;
|
|
25
|
+
orientation?: CardItemPickerOrientation;
|
|
26
|
+
onValueChange?: (value: string) => void;
|
|
27
|
+
onHoverChange?: (value: string | null) => void;
|
|
28
|
+
} = {}) {
|
|
29
|
+
return render(
|
|
30
|
+
<CardItemPickerList
|
|
31
|
+
aria-label="Cities"
|
|
32
|
+
value={value}
|
|
33
|
+
hoveredValue={hoveredValue}
|
|
34
|
+
orientation={orientation}
|
|
35
|
+
onValueChange={onValueChange}
|
|
36
|
+
onHoverChange={onHoverChange}
|
|
37
|
+
>
|
|
38
|
+
{CITIES.map((city) => (
|
|
39
|
+
<CardItemPickerRow key={city} value={city}>
|
|
40
|
+
<CardItemPickerRowContent>
|
|
41
|
+
<CardItemPickerRowTitle>{city}</CardItemPickerRowTitle>
|
|
42
|
+
<CardItemPickerRowDescription>{`${city} is in Switzerland`}</CardItemPickerRowDescription>
|
|
43
|
+
</CardItemPickerRowContent>
|
|
44
|
+
</CardItemPickerRow>
|
|
45
|
+
))}
|
|
46
|
+
</CardItemPickerList>,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function options() {
|
|
51
|
+
return screen.getAllByRole('option');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function tabStops() {
|
|
55
|
+
return options().filter((option) => option.tabIndex === 0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
cleanup();
|
|
60
|
+
vi.restoreAllMocks();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('semantics', () => {
|
|
64
|
+
test('is a named listbox of options named by their titles', () => {
|
|
65
|
+
renderList();
|
|
66
|
+
|
|
67
|
+
expect(screen.getByRole('listbox', { name: 'Cities' })).not.toBeNull();
|
|
68
|
+
expect(options().map((option) => option.getAttribute('aria-labelledby'))).not.toContain(null);
|
|
69
|
+
expect(screen.getByRole('option', { name: 'Geneva' })).not.toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('describes each option by its description', () => {
|
|
73
|
+
renderList();
|
|
74
|
+
|
|
75
|
+
const geneva = screen.getByRole('option', { name: 'Geneva' });
|
|
76
|
+
const description = document.getElementById(geneva.getAttribute('aria-describedby')!);
|
|
77
|
+
expect(description?.textContent).toBe('Geneva is in Switzerland');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('marks only the selected option as selected', () => {
|
|
81
|
+
renderList({ value: 'Basel' });
|
|
82
|
+
|
|
83
|
+
expect(options().map((option) => option.getAttribute('aria-selected'))).toEqual([
|
|
84
|
+
'false',
|
|
85
|
+
'false',
|
|
86
|
+
'true',
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('parts throw outside their parents', () => {
|
|
91
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
92
|
+
|
|
93
|
+
expect(() => render(<CardItemPickerRow value="x" />)).toThrow(/within a CardItemPickerList/);
|
|
94
|
+
expect(() => render(<CardItemPickerRowTitle>x</CardItemPickerRowTitle>)).toThrow(
|
|
95
|
+
/within a CardItemPickerRow/,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('checkbox', () => {
|
|
101
|
+
function renderWithCheckbox(value: string | null, onValueChange = vi.fn()) {
|
|
102
|
+
render(
|
|
103
|
+
<CardItemPickerList aria-label="Cities" value={value} onValueChange={onValueChange}>
|
|
104
|
+
{CITIES.map((city) => (
|
|
105
|
+
<CardItemPickerRow key={city} value={city}>
|
|
106
|
+
<CardItemPickerRowTitle>{city}</CardItemPickerRowTitle>
|
|
107
|
+
<CardItemPickerRowCheckbox />
|
|
108
|
+
</CardItemPickerRow>
|
|
109
|
+
))}
|
|
110
|
+
</CardItemPickerList>,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
test('mirrors the selection, hidden from assistive tech and out of the tab order', () => {
|
|
115
|
+
renderWithCheckbox('Geneva');
|
|
116
|
+
|
|
117
|
+
const boxes = screen.getAllByTestId('checkbox');
|
|
118
|
+
expect(boxes.map((box) => box.getAttribute('data-state'))).toEqual([
|
|
119
|
+
'unchecked',
|
|
120
|
+
'checked',
|
|
121
|
+
'unchecked',
|
|
122
|
+
]);
|
|
123
|
+
expect(boxes.every((box) => box.tabIndex === -1)).toBe(true);
|
|
124
|
+
expect(screen.queryAllByRole('checkbox')).toEqual([]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('sits in the top-right corner', () => {
|
|
128
|
+
renderWithCheckbox(null);
|
|
129
|
+
|
|
130
|
+
expect(screen.getAllByTestId('card-item-picker-row-checkbox')[0].className).toContain(
|
|
131
|
+
'absolute top-[8px] right-[8px]',
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('selection', () => {
|
|
137
|
+
test('a click picks the card', () => {
|
|
138
|
+
const onValueChange = vi.fn();
|
|
139
|
+
renderList({ onValueChange });
|
|
140
|
+
|
|
141
|
+
fireEvent.click(screen.getByRole('option', { name: 'Geneva' }));
|
|
142
|
+
|
|
143
|
+
expect(onValueChange).toHaveBeenCalledWith('Geneva');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test.each(['Enter', ' '])('%j picks the focused card', (key) => {
|
|
147
|
+
const onValueChange = vi.fn();
|
|
148
|
+
renderList({ onValueChange });
|
|
149
|
+
|
|
150
|
+
fireEvent.keyDown(screen.getByRole('option', { name: 'Basel' }), { key });
|
|
151
|
+
|
|
152
|
+
expect(onValueChange).toHaveBeenCalledWith('Basel');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('hover', () => {
|
|
157
|
+
test('reports the card under the pointer, then none', () => {
|
|
158
|
+
const onHoverChange = vi.fn();
|
|
159
|
+
renderList({ onHoverChange });
|
|
160
|
+
|
|
161
|
+
const zurich = screen.getByRole('option', { name: 'Zurich' });
|
|
162
|
+
fireEvent.mouseEnter(zurich);
|
|
163
|
+
fireEvent.mouseLeave(zurich);
|
|
164
|
+
|
|
165
|
+
expect(onHoverChange.mock.calls).toEqual([['Zurich'], [null]]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('mirrors the hovered value onto its card', () => {
|
|
169
|
+
renderList({ hoveredValue: 'Geneva' });
|
|
170
|
+
|
|
171
|
+
expect(options().map((option) => option.dataset.hovered)).toEqual(['false', 'true', 'false']);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('keyboard focus', () => {
|
|
176
|
+
beforeEach(() => {
|
|
177
|
+
vi.useFakeTimers();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(() => {
|
|
181
|
+
vi.useRealTimers();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Radix moves focus on a timeout after the keydown
|
|
185
|
+
function press(element: HTMLElement, key: string) {
|
|
186
|
+
fireEvent.keyDown(element, { key });
|
|
187
|
+
act(() => vi.runAllTimers());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function tabIntoList() {
|
|
191
|
+
act(() => screen.getByRole('listbox').focus());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
test('tabbing in lands on the first card when nothing is selected', () => {
|
|
195
|
+
renderList();
|
|
196
|
+
|
|
197
|
+
tabIntoList();
|
|
198
|
+
|
|
199
|
+
expect(document.activeElement).toBe(screen.getByRole('option', { name: 'Zurich' }));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('tabbing in lands on the selected card', () => {
|
|
203
|
+
renderList({ value: 'Basel' });
|
|
204
|
+
|
|
205
|
+
expect(tabStops()).toEqual([screen.getByRole('option', { name: 'Basel' })]);
|
|
206
|
+
|
|
207
|
+
tabIntoList();
|
|
208
|
+
|
|
209
|
+
expect(document.activeElement).toBe(screen.getByRole('option', { name: 'Basel' }));
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('tabbing back in returns to the last focused card, over the selected one', () => {
|
|
213
|
+
renderList({ value: 'Basel' });
|
|
214
|
+
const [zurich] = options();
|
|
215
|
+
|
|
216
|
+
act(() => zurich.focus());
|
|
217
|
+
act(() => zurich.blur());
|
|
218
|
+
tabIntoList();
|
|
219
|
+
|
|
220
|
+
expect(document.activeElement).toBe(zurich);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('arrow keys, Home and End move focus between cards', () => {
|
|
224
|
+
renderList();
|
|
225
|
+
const [zurich, geneva, basel] = options();
|
|
226
|
+
act(() => zurich.focus());
|
|
227
|
+
|
|
228
|
+
press(zurich, 'ArrowDown');
|
|
229
|
+
expect(document.activeElement).toBe(geneva);
|
|
230
|
+
|
|
231
|
+
press(geneva, 'End');
|
|
232
|
+
expect(document.activeElement).toBe(basel);
|
|
233
|
+
|
|
234
|
+
press(basel, 'ArrowDown');
|
|
235
|
+
expect(document.activeElement).toBe(basel);
|
|
236
|
+
|
|
237
|
+
press(basel, 'ArrowUp');
|
|
238
|
+
expect(document.activeElement).toBe(geneva);
|
|
239
|
+
|
|
240
|
+
press(geneva, 'Home');
|
|
241
|
+
expect(document.activeElement).toBe(zurich);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('PageDown and PageUp jump to the last and first card', () => {
|
|
245
|
+
renderList();
|
|
246
|
+
const [zurich, , basel] = options();
|
|
247
|
+
act(() => zurich.focus());
|
|
248
|
+
|
|
249
|
+
press(zurich, 'PageDown');
|
|
250
|
+
expect(document.activeElement).toBe(basel);
|
|
251
|
+
|
|
252
|
+
press(basel, 'PageUp');
|
|
253
|
+
expect(document.activeElement).toBe(zurich);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('the tab stop follows focus', () => {
|
|
257
|
+
renderList();
|
|
258
|
+
const [zurich, geneva] = options();
|
|
259
|
+
act(() => zurich.focus());
|
|
260
|
+
|
|
261
|
+
press(zurich, 'ArrowDown');
|
|
262
|
+
|
|
263
|
+
expect(tabStops()).toEqual([geneva]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('a horizontal list moves with left and right', () => {
|
|
267
|
+
renderList({ orientation: 'horizontal' });
|
|
268
|
+
const [zurich, geneva] = options();
|
|
269
|
+
act(() => zurich.focus());
|
|
270
|
+
|
|
271
|
+
press(zurich, 'ArrowDown');
|
|
272
|
+
expect(document.activeElement).toBe(zurich);
|
|
273
|
+
|
|
274
|
+
press(zurich, 'ArrowRight');
|
|
275
|
+
expect(document.activeElement).toBe(geneva);
|
|
276
|
+
|
|
277
|
+
expect(screen.getByRole('listbox').getAttribute('aria-orientation')).toBe('horizontal');
|
|
278
|
+
});
|
|
279
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export type CardItemPickerValue = string | number;
|
|
4
|
+
export type CardItemPickerOrientation = 'vertical' | 'horizontal';
|
|
5
|
+
|
|
6
|
+
export interface CardItemPickerListContextValue {
|
|
7
|
+
value: CardItemPickerValue | null;
|
|
8
|
+
hoveredValue: CardItemPickerValue | null;
|
|
9
|
+
orientation: CardItemPickerOrientation;
|
|
10
|
+
select: (value: CardItemPickerValue) => void;
|
|
11
|
+
hover: (value: CardItemPickerValue | null) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const CardItemPickerListContext = createContext<CardItemPickerListContextValue | null>(null);
|
|
15
|
+
|
|
16
|
+
export function useCardItemPickerListContext() {
|
|
17
|
+
const context = useContext(CardItemPickerListContext);
|
|
18
|
+
|
|
19
|
+
if (!context) {
|
|
20
|
+
throw new Error('useCardItemPickerListContext must be used within a CardItemPickerList');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CardItemPickerRowContextValue {
|
|
27
|
+
isSelected: boolean;
|
|
28
|
+
titleId: string;
|
|
29
|
+
descriptionId: string;
|
|
30
|
+
registerTitle: () => () => void;
|
|
31
|
+
registerDescription: () => () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const CardItemPickerRowContext = createContext<CardItemPickerRowContextValue | null>(null);
|
|
35
|
+
|
|
36
|
+
export function useCardItemPickerRowContext() {
|
|
37
|
+
const context = useContext(CardItemPickerRowContext);
|
|
38
|
+
|
|
39
|
+
if (!context) {
|
|
40
|
+
throw new Error('useCardItemPickerRowContext must be used within a CardItemPickerRow');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return context;
|
|
44
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
|
|
2
|
+
import type { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { cn } from '@swisper.ai/ui';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CardItemPickerListContext,
|
|
9
|
+
type CardItemPickerListContextValue,
|
|
10
|
+
type CardItemPickerOrientation,
|
|
11
|
+
type CardItemPickerValue,
|
|
12
|
+
} from './card-item-picker-context';
|
|
13
|
+
|
|
14
|
+
export interface CardItemPickerListProps<
|
|
15
|
+
V extends CardItemPickerValue = CardItemPickerValue,
|
|
16
|
+
> extends Omit<ComponentPropsWithoutRef<'ul'>, 'role' | 'onKeyDown' | 'aria-orientation'> {
|
|
17
|
+
/** The selected card, or `null` when nothing is selected. */
|
|
18
|
+
value: V | null;
|
|
19
|
+
/** The card under the pointer, mirrored as `data-hovered` (e.g. when a map pin is hovered). */
|
|
20
|
+
hoveredValue?: V | null;
|
|
21
|
+
/** A card was picked by click, Enter or Space. Toggling is up to the caller. */
|
|
22
|
+
onValueChange: (value: V) => void;
|
|
23
|
+
/** The pointer entered a card (`value`) or left it (`null`). */
|
|
24
|
+
onHoverChange?: (value: V | null) => void;
|
|
25
|
+
orientation?: CardItemPickerOrientation;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A single-select list of cards, built on the ARIA listbox pattern: the list is
|
|
30
|
+
* one tab stop that moves focus into the last focused card, else the selected
|
|
31
|
+
* one, else the first. Arrow keys (plus Home/End, PageUp/PageDown) move between
|
|
32
|
+
* cards and Enter/Space picks one. Name it with `aria-label` or `aria-labelledby`.
|
|
33
|
+
*
|
|
34
|
+
* Cards are listbox options, so they must not contain their own links or
|
|
35
|
+
* buttons — put those in a details view instead.
|
|
36
|
+
*/
|
|
37
|
+
export function CardItemPickerList<V extends CardItemPickerValue>({
|
|
38
|
+
value,
|
|
39
|
+
hoveredValue = null,
|
|
40
|
+
onValueChange,
|
|
41
|
+
onHoverChange,
|
|
42
|
+
orientation = 'vertical',
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}: CardItemPickerListProps<V>) {
|
|
47
|
+
// Radix moves focus; we only pick which card is the tab stop. Controlled so the
|
|
48
|
+
// last focused card wins over the selected one (Radix's `active` would not).
|
|
49
|
+
const [lastFocusedId, setLastFocusedId] = useState<string | null>(null);
|
|
50
|
+
const tabStopId = lastFocusedId ?? (value != null ? String(value) : null);
|
|
51
|
+
|
|
52
|
+
const onHoverChangeRef = useRef(onHoverChange);
|
|
53
|
+
onHoverChangeRef.current = onHoverChange;
|
|
54
|
+
const onValueChangeRef = useRef(onValueChange);
|
|
55
|
+
onValueChangeRef.current = onValueChange;
|
|
56
|
+
|
|
57
|
+
// items only ever report the values they were given, so these are the caller's `V`
|
|
58
|
+
const select = useCallback(
|
|
59
|
+
(itemValue: CardItemPickerValue) => onValueChangeRef.current(itemValue as V),
|
|
60
|
+
[],
|
|
61
|
+
);
|
|
62
|
+
const hover = useCallback(
|
|
63
|
+
(itemValue: CardItemPickerValue | null) => onHoverChangeRef.current?.(itemValue as V | null),
|
|
64
|
+
[],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const context = useMemo<CardItemPickerListContextValue>(
|
|
68
|
+
() => ({ value, hoveredValue, orientation, select, hover }),
|
|
69
|
+
[value, hoveredValue, orientation, select, hover],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<CardItemPickerListContext.Provider value={context}>
|
|
74
|
+
<RovingFocusGroup.Root
|
|
75
|
+
asChild
|
|
76
|
+
orientation={orientation}
|
|
77
|
+
currentTabStopId={tabStopId}
|
|
78
|
+
onCurrentTabStopIdChange={setLastFocusedId}
|
|
79
|
+
>
|
|
80
|
+
<ul
|
|
81
|
+
{...props}
|
|
82
|
+
role="listbox"
|
|
83
|
+
aria-orientation={orientation}
|
|
84
|
+
className={cn(
|
|
85
|
+
'flex gap-[4px]',
|
|
86
|
+
orientation === 'vertical' ? 'flex-col' : 'flex-row',
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
</ul>
|
|
92
|
+
</RovingFocusGroup.Root>
|
|
93
|
+
</CardItemPickerListContext.Provider>
|
|
94
|
+
);
|
|
95
|
+
}
|