@patternfly/chatbot 6.5.0-prerelease.9 → 6.6.0-prerelease.1
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/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +9 -1
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +9 -2
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +38 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.js +29 -2
- package/dist/cjs/CodeModal/CodeModal.d.ts +2 -0
- package/dist/cjs/CodeModal/CodeModal.js +53 -12
- package/dist/cjs/DeepThinking/DeepThinking.d.ts +13 -0
- package/dist/cjs/DeepThinking/DeepThinking.js +31 -3
- package/dist/cjs/DeepThinking/DeepThinking.test.js +80 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.d.ts +44 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.js +181 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.test.d.ts +1 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.test.js +192 -0
- package/dist/cjs/MarkdownContent/index.d.ts +2 -0
- package/dist/cjs/MarkdownContent/index.js +23 -0
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.d.ts +3 -1
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.js +15 -4
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.test.d.ts +1 -0
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.test.js +131 -0
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.d.ts +15 -1
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.js +5 -3
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.test.d.ts +1 -0
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.test.js +30 -0
- package/dist/cjs/Message/LinkMessage/LinkMessage.d.ts +5 -1
- package/dist/cjs/Message/LinkMessage/LinkMessage.js +4 -3
- package/dist/cjs/Message/ListMessage/OrderedListMessage.d.ts +9 -1
- package/dist/cjs/Message/ListMessage/OrderedListMessage.js +2 -1
- package/dist/cjs/Message/ListMessage/UnorderedListMessage.d.ts +7 -1
- package/dist/cjs/Message/ListMessage/UnorderedListMessage.js +2 -1
- package/dist/cjs/Message/Message.d.ts +20 -3
- package/dist/cjs/Message/Message.js +7 -160
- package/dist/cjs/Message/Message.test.js +129 -2
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.d.ts +14 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.js +22 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.test.js +25 -0
- package/dist/cjs/Message/MessageAndActions/index.d.ts +1 -0
- package/dist/cjs/Message/MessageAndActions/index.js +17 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.d.ts +13 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.js +22 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.test.js +25 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.d.ts +13 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.js +22 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.test.js +25 -0
- package/dist/cjs/Message/MessageAttachments/index.d.ts +2 -0
- package/dist/cjs/Message/MessageAttachments/index.js +18 -0
- package/dist/cjs/Message/MessageInput.d.ts +1 -1
- package/dist/cjs/Message/MessageInput.js +3 -1
- package/dist/cjs/Message/MessageLoading.d.ts +13 -4
- package/dist/cjs/Message/MessageLoading.js +19 -5
- package/dist/cjs/Message/MessageLoading.test.d.ts +1 -0
- package/dist/cjs/Message/MessageLoading.test.js +25 -0
- package/dist/cjs/Message/QuickResponse/QuickResponse.js +3 -2
- package/dist/cjs/Message/QuickResponse/QuickResponse.test.d.ts +1 -0
- package/dist/cjs/Message/QuickResponse/QuickResponse.test.js +109 -0
- package/dist/cjs/Message/QuickResponse/index.d.ts +1 -0
- package/dist/cjs/Message/QuickResponse/index.js +17 -0
- package/dist/cjs/Message/QuickStarts/QuickStartTile.d.ts +1 -1
- package/dist/cjs/Message/QuickStarts/QuickStartTile.js +3 -2
- package/dist/cjs/Message/QuickStarts/index.d.ts +2 -0
- package/dist/cjs/Message/QuickStarts/index.js +18 -0
- package/dist/cjs/Message/TableMessage/TableMessage.d.ts +6 -1
- package/dist/cjs/Message/TableMessage/TableMessage.js +3 -2
- package/dist/cjs/Message/TextMessage/TextMessage.d.ts +8 -1
- package/dist/cjs/Message/TextMessage/TextMessage.js +3 -2
- package/dist/cjs/Message/UserFeedback/UserFeedback.d.ts +3 -1
- package/dist/cjs/Message/UserFeedback/UserFeedback.js +8 -6
- package/dist/cjs/Message/UserFeedback/UserFeedbackComplete.d.ts +1 -1
- package/dist/cjs/Message/UserFeedback/UserFeedbackComplete.js +3 -2
- package/dist/cjs/Message/UserFeedback/index.d.ts +2 -0
- package/dist/cjs/Message/UserFeedback/index.js +18 -0
- package/dist/cjs/Message/index.d.ts +8 -0
- package/dist/cjs/Message/index.js +8 -0
- package/dist/cjs/MessageBar/MessageBar.d.ts +10 -0
- package/dist/cjs/MessageBar/MessageBar.js +42 -10
- package/dist/cjs/MessageBar/MessageBar.test.js +20 -0
- package/dist/cjs/Onboarding/Onboarding.d.ts +36 -0
- package/dist/cjs/Onboarding/Onboarding.js +37 -0
- package/dist/cjs/Onboarding/Onboarding.test.d.ts +1 -0
- package/dist/cjs/Onboarding/Onboarding.test.js +80 -0
- package/dist/cjs/Onboarding/index.d.ts +2 -0
- package/dist/cjs/Onboarding/index.js +23 -0
- package/dist/cjs/ResponseActions/ResponseActions.d.ts +7 -0
- package/dist/cjs/ResponseActions/ResponseActions.js +28 -7
- package/dist/cjs/ResponseActions/ResponseActions.test.js +67 -12
- package/dist/cjs/ResponseActions/ResponseActionsGroups.d.ts +13 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.js +22 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.test.d.ts +1 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.test.js +25 -0
- package/dist/cjs/ResponseActions/index.d.ts +1 -0
- package/dist/cjs/ResponseActions/index.js +1 -0
- package/dist/cjs/ToolCall/ToolCall.d.ts +11 -0
- package/dist/cjs/ToolCall/ToolCall.js +24 -3
- package/dist/cjs/ToolCall/ToolCall.test.js +57 -0
- package/dist/cjs/ToolResponse/ToolResponse.d.ts +17 -0
- package/dist/cjs/ToolResponse/ToolResponse.js +49 -3
- package/dist/cjs/ToolResponse/ToolResponse.test.js +100 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +7 -1
- package/dist/css/main.css +276 -30
- package/dist/css/main.css.map +1 -1
- package/dist/dynamic/MarkdownContent/package.json +1 -0
- package/dist/dynamic/Onboarding/package.json +1 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +9 -1
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +10 -3
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +38 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.js +30 -3
- package/dist/esm/CodeModal/CodeModal.d.ts +2 -0
- package/dist/esm/CodeModal/CodeModal.js +54 -13
- package/dist/esm/DeepThinking/DeepThinking.d.ts +13 -0
- package/dist/esm/DeepThinking/DeepThinking.js +28 -3
- package/dist/esm/DeepThinking/DeepThinking.test.js +80 -0
- package/dist/esm/MarkdownContent/MarkdownContent.d.ts +44 -0
- package/dist/esm/MarkdownContent/MarkdownContent.js +174 -0
- package/dist/esm/MarkdownContent/MarkdownContent.test.d.ts +1 -0
- package/dist/esm/MarkdownContent/MarkdownContent.test.js +187 -0
- package/dist/esm/MarkdownContent/index.d.ts +2 -0
- package/dist/esm/MarkdownContent/index.js +2 -0
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.d.ts +3 -1
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.js +15 -4
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.test.d.ts +1 -0
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.test.js +126 -0
- package/dist/esm/Message/ErrorMessage/ErrorMessage.d.ts +15 -1
- package/dist/esm/Message/ErrorMessage/ErrorMessage.js +3 -3
- package/dist/esm/Message/ErrorMessage/ErrorMessage.test.d.ts +1 -0
- package/dist/esm/Message/ErrorMessage/ErrorMessage.test.js +25 -0
- package/dist/esm/Message/LinkMessage/LinkMessage.d.ts +5 -1
- package/dist/esm/Message/LinkMessage/LinkMessage.js +4 -3
- package/dist/esm/Message/ListMessage/OrderedListMessage.d.ts +9 -1
- package/dist/esm/Message/ListMessage/OrderedListMessage.js +2 -1
- package/dist/esm/Message/ListMessage/UnorderedListMessage.d.ts +7 -1
- package/dist/esm/Message/ListMessage/UnorderedListMessage.js +2 -1
- package/dist/esm/Message/Message.d.ts +20 -3
- package/dist/esm/Message/Message.js +8 -161
- package/dist/esm/Message/Message.test.js +129 -2
- package/dist/esm/Message/MessageAndActions/MessageAndActions.d.ts +14 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.js +18 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.test.d.ts +1 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.test.js +20 -0
- package/dist/esm/Message/MessageAndActions/index.d.ts +1 -0
- package/dist/esm/Message/MessageAndActions/index.js +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.d.ts +13 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.js +18 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.test.d.ts +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.test.js +20 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.d.ts +13 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.js +18 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.test.d.ts +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.test.js +20 -0
- package/dist/esm/Message/MessageAttachments/index.d.ts +2 -0
- package/dist/esm/Message/MessageAttachments/index.js +2 -0
- package/dist/esm/Message/MessageInput.d.ts +1 -1
- package/dist/esm/Message/MessageInput.js +1 -1
- package/dist/esm/Message/MessageLoading.d.ts +13 -4
- package/dist/esm/Message/MessageLoading.js +16 -4
- package/dist/esm/Message/MessageLoading.test.d.ts +1 -0
- package/dist/esm/Message/MessageLoading.test.js +20 -0
- package/dist/esm/Message/QuickResponse/QuickResponse.js +3 -2
- package/dist/esm/Message/QuickResponse/QuickResponse.test.d.ts +1 -0
- package/dist/esm/Message/QuickResponse/QuickResponse.test.js +104 -0
- package/dist/esm/Message/QuickResponse/index.d.ts +1 -0
- package/dist/esm/Message/QuickResponse/index.js +1 -0
- package/dist/esm/Message/QuickStarts/QuickStartTile.d.ts +1 -1
- package/dist/esm/Message/QuickStarts/QuickStartTile.js +1 -1
- package/dist/esm/Message/QuickStarts/index.d.ts +2 -0
- package/dist/esm/Message/QuickStarts/index.js +2 -0
- package/dist/esm/Message/TableMessage/TableMessage.d.ts +6 -1
- package/dist/esm/Message/TableMessage/TableMessage.js +3 -2
- package/dist/esm/Message/TextMessage/TextMessage.d.ts +8 -1
- package/dist/esm/Message/TextMessage/TextMessage.js +3 -2
- package/dist/esm/Message/UserFeedback/UserFeedback.d.ts +3 -1
- package/dist/esm/Message/UserFeedback/UserFeedback.js +7 -7
- package/dist/esm/Message/UserFeedback/UserFeedbackComplete.d.ts +1 -1
- package/dist/esm/Message/UserFeedback/UserFeedbackComplete.js +1 -2
- package/dist/esm/Message/UserFeedback/index.d.ts +2 -0
- package/dist/esm/Message/UserFeedback/index.js +2 -0
- package/dist/esm/Message/index.d.ts +8 -0
- package/dist/esm/Message/index.js +8 -0
- package/dist/esm/MessageBar/MessageBar.d.ts +10 -0
- package/dist/esm/MessageBar/MessageBar.js +42 -10
- package/dist/esm/MessageBar/MessageBar.test.js +20 -0
- package/dist/esm/Onboarding/Onboarding.d.ts +36 -0
- package/dist/esm/Onboarding/Onboarding.js +30 -0
- package/dist/esm/Onboarding/Onboarding.test.d.ts +1 -0
- package/dist/esm/Onboarding/Onboarding.test.js +75 -0
- package/dist/esm/Onboarding/index.d.ts +2 -0
- package/dist/esm/Onboarding/index.js +2 -0
- package/dist/esm/ResponseActions/ResponseActions.d.ts +7 -0
- package/dist/esm/ResponseActions/ResponseActions.js +28 -7
- package/dist/esm/ResponseActions/ResponseActions.test.js +67 -12
- package/dist/esm/ResponseActions/ResponseActionsGroups.d.ts +13 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.js +18 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.test.d.ts +1 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.test.js +20 -0
- package/dist/esm/ResponseActions/index.d.ts +1 -0
- package/dist/esm/ResponseActions/index.js +1 -0
- package/dist/esm/ToolCall/ToolCall.d.ts +11 -0
- package/dist/esm/ToolCall/ToolCall.js +21 -3
- package/dist/esm/ToolCall/ToolCall.test.js +57 -0
- package/dist/esm/ToolResponse/ToolResponse.d.ts +17 -0
- package/dist/esm/ToolResponse/ToolResponse.js +46 -3
- package/dist/esm/ToolResponse/ToolResponse.test.js +100 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -3
- package/patternfly-docs/content/extensions/chatbot/chatbot.md +57 -0
- package/patternfly-docs/content/extensions/chatbot/design-guidelines.md +12 -12
- package/patternfly-docs/content/extensions/chatbot/examples/Analytics/Analytics.md +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Customizing Messages/Customizing Messages.md +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx +1 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithCustomStructure.tsx +102 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithDeepThinking.tsx +25 -11
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithFeedback.tsx +14 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownDeepThinking.tsx +26 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolCall.tsx +29 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolResponse.tsx +200 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMultipleActionGroups.tsx +61 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithPersistedActions.tsx +22 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithQuickResponses.tsx +11 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolCall.tsx +14 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolResponse.tsx +222 -105
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +123 -14
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +1 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerWithSearchActions.tsx +198 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotMessageBarCustomActions.tsx +190 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotMessageBarIndicatorThinking.tsx +15 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/CompactOnboarding.tsx +141 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/Onboarding.tsx +151 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/RH-Hat-Image.svg +9 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/UI.md +81 -30
- package/patternfly-docs/content/extensions/chatbot/examples/demos/AttachmentDemos.md +18 -18
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +33 -19
- package/patternfly-docs/patternfly-docs.config.js +1 -1
- package/patternfly-docs/patternfly-docs.source.js +1 -1
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +43 -0
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx +95 -0
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +51 -15
- package/src/ChatbotHeader/ChatbotHeaderMenu.tsx +56 -14
- package/src/ChatbotModal/ChatbotModal.scss +3 -0
- package/src/CodeModal/CodeModal.tsx +71 -26
- package/src/DeepThinking/DeepThinking.scss +1 -1
- package/src/DeepThinking/DeepThinking.test.tsx +109 -0
- package/src/DeepThinking/DeepThinking.tsx +54 -5
- package/src/MarkdownContent/MarkdownContent.test.tsx +207 -0
- package/src/MarkdownContent/MarkdownContent.tsx +269 -0
- package/src/MarkdownContent/index.ts +2 -0
- package/src/Message/CodeBlockMessage/CodeBlockMessage.scss +13 -0
- package/src/Message/CodeBlockMessage/CodeBlockMessage.test.tsx +171 -0
- package/src/Message/CodeBlockMessage/CodeBlockMessage.tsx +17 -4
- package/src/Message/ErrorMessage/ErrorMessage.test.tsx +38 -0
- package/src/Message/ErrorMessage/ErrorMessage.tsx +17 -2
- package/src/Message/LinkMessage/LinkMessage.scss +5 -0
- package/src/Message/LinkMessage/LinkMessage.tsx +24 -2
- package/src/Message/ListMessage/ListMessage.scss +8 -0
- package/src/Message/ListMessage/OrderedListMessage.tsx +16 -2
- package/src/Message/ListMessage/UnorderedListMessage.tsx +12 -2
- package/src/Message/Message.scss +11 -7
- package/src/Message/Message.test.tsx +202 -2
- package/src/Message/Message.tsx +129 -241
- package/src/Message/MessageAndActions/MessageAndActions.test.tsx +23 -0
- package/src/Message/MessageAndActions/MessageAndActions.tsx +22 -0
- package/src/Message/MessageAndActions/index.ts +1 -0
- package/src/Message/MessageAttachments/MessageAttachmentItem.test.tsx +23 -0
- package/src/Message/MessageAttachments/MessageAttachmentItem.tsx +25 -0
- package/src/Message/MessageAttachments/MessageAttachmentsContainer.test.tsx +23 -0
- package/src/Message/MessageAttachments/MessageAttachmentsContainer.tsx +25 -0
- package/src/Message/MessageAttachments/index.ts +2 -0
- package/src/Message/MessageInput.tsx +1 -1
- package/src/Message/MessageLoading.test.tsx +23 -0
- package/src/Message/MessageLoading.tsx +17 -2
- package/src/Message/QuickResponse/QuickResponse.scss +3 -1
- package/src/Message/QuickResponse/QuickResponse.test.tsx +131 -0
- package/src/Message/QuickResponse/QuickResponse.tsx +3 -2
- package/src/Message/QuickResponse/index.ts +1 -0
- package/src/Message/QuickStarts/QuickStartTile.tsx +1 -1
- package/src/Message/QuickStarts/index.ts +2 -0
- package/src/Message/TableMessage/TableMessage.scss +13 -1
- package/src/Message/TableMessage/TableMessage.tsx +18 -2
- package/src/Message/TextMessage/TextMessage.scss +12 -0
- package/src/Message/TextMessage/TextMessage.tsx +29 -2
- package/src/Message/UserFeedback/UserFeedback.scss +28 -1
- package/src/Message/UserFeedback/UserFeedback.tsx +23 -13
- package/src/Message/UserFeedback/UserFeedbackComplete.tsx +1 -4
- package/src/Message/UserFeedback/index.ts +2 -0
- package/src/Message/index.ts +8 -0
- package/src/MessageBar/AttachButton.scss +0 -1
- package/src/MessageBar/MessageBar.scss +63 -7
- package/src/MessageBar/MessageBar.test.tsx +39 -0
- package/src/MessageBar/MessageBar.tsx +124 -48
- package/src/MessageBar/MicrophoneButton.scss +0 -1
- package/src/MessageBar/SendButton.scss +0 -1
- package/src/MessageBar/StopButton.scss +0 -1
- package/src/Onboarding/Onboarding.scss +101 -0
- package/src/Onboarding/Onboarding.test.tsx +148 -0
- package/src/Onboarding/Onboarding.tsx +126 -0
- package/src/Onboarding/index.ts +3 -0
- package/src/ResponseActions/ResponseActions.scss +12 -1
- package/src/ResponseActions/ResponseActions.test.tsx +111 -12
- package/src/ResponseActions/ResponseActions.tsx +44 -10
- package/src/ResponseActions/ResponseActionsGroups.test.tsx +23 -0
- package/src/ResponseActions/ResponseActionsGroups.tsx +28 -0
- package/src/ResponseActions/index.ts +1 -0
- package/src/ToolCall/ToolCall.scss +1 -1
- package/src/ToolCall/ToolCall.test.tsx +91 -0
- package/src/ToolCall/ToolCall.tsx +49 -4
- package/src/ToolResponse/ToolResponse.scss +13 -3
- package/src/ToolResponse/ToolResponse.test.tsx +119 -0
- package/src/ToolResponse/ToolResponse.tsx +82 -7
- package/src/index.ts +6 -0
- package/src/main.scss +2 -0
- package/tsconfig.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/about-chatbot.md +0 -44
|
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
14
14
|
import { TextArea } from '@patternfly/react-core';
|
|
15
|
+
import { css } from '@patternfly/react-styles';
|
|
15
16
|
// Import Chatbot components
|
|
16
17
|
import SendButton from './SendButton';
|
|
17
18
|
import MicrophoneButton from './MicrophoneButton';
|
|
@@ -20,17 +21,24 @@ import AttachMenu from '../AttachMenu';
|
|
|
20
21
|
import StopButton from './StopButton';
|
|
21
22
|
export const MessageBarBase = (_a) => {
|
|
22
23
|
var _b;
|
|
23
|
-
var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes, minSize, maxSize, maxFiles, isAttachmentDisabled, onAttach, onAttachRejected, validator, dropzoneProps, innerRef, isPrimary } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes", "minSize", "maxSize", "maxFiles", "isAttachmentDisabled", "onAttach", "onAttachRejected", "validator", "dropzoneProps", "innerRef", "isPrimary"]);
|
|
24
|
+
var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, attachButtonPosition = 'end', hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes, minSize, maxSize, maxFiles, isAttachmentDisabled, onAttach, onAttachRejected, validator, dropzoneProps, innerRef, isPrimary, additionalActions, forceMultilineLayout = false, hasAiIndicator, isThinking } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "attachButtonPosition", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes", "minSize", "maxSize", "maxFiles", "isAttachmentDisabled", "onAttach", "onAttachRejected", "validator", "dropzoneProps", "innerRef", "isPrimary", "additionalActions", "forceMultilineLayout", "hasAiIndicator", "isThinking"]);
|
|
24
25
|
// Text Input
|
|
25
26
|
// --------------------------------------------------------------------------
|
|
26
27
|
const [message, setMessage] = useState(value !== null && value !== void 0 ? value : '');
|
|
27
28
|
const [isListeningMessage, setIsListeningMessage] = useState(false);
|
|
28
29
|
const [hasSentMessage, setHasSentMessage] = useState(false);
|
|
29
30
|
const [isComposing, setIsComposing] = useState(false);
|
|
31
|
+
const shouldForceMultiline = forceMultilineLayout || additionalActions;
|
|
32
|
+
const [isMultiline, setIsMultiline] = useState(shouldForceMultiline);
|
|
30
33
|
const inputRef = useRef(null);
|
|
31
34
|
const textareaRef = (_b = innerRef) !== null && _b !== void 0 ? _b : inputRef;
|
|
32
35
|
const attachButtonRef = useRef(null);
|
|
33
36
|
const topMargin = '1rem';
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (value !== undefined && value !== message) {
|
|
39
|
+
setMessage(value);
|
|
40
|
+
}
|
|
41
|
+
}, [value, message]);
|
|
34
42
|
const setInitialLineHeight = (field) => {
|
|
35
43
|
field.style.setProperty('line-height', '1rem');
|
|
36
44
|
const parent = field.parentElement;
|
|
@@ -40,7 +48,7 @@ export const MessageBarBase = (_a) => {
|
|
|
40
48
|
parent.style.setProperty('height', 'inherit');
|
|
41
49
|
const grandparent = parent.parentElement;
|
|
42
50
|
if (grandparent) {
|
|
43
|
-
grandparent.style.setProperty('flex-basis', 'auto');
|
|
51
|
+
grandparent.style.setProperty('flex-basis', shouldForceMultiline ? '100%' : 'auto');
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
};
|
|
@@ -67,11 +75,20 @@ export const MessageBarBase = (_a) => {
|
|
|
67
75
|
const lines = field.scrollHeight / lineHeight;
|
|
68
76
|
return lines > 2;
|
|
69
77
|
};
|
|
78
|
+
const checkIfMultiline = useCallback((field) => {
|
|
79
|
+
const parent = field.parentElement;
|
|
80
|
+
const grandparent = parent === null || parent === void 0 ? void 0 : parent.parentElement;
|
|
81
|
+
if (grandparent) {
|
|
82
|
+
const containerHeight = grandparent.offsetHeight;
|
|
83
|
+
const threshold = isCompact ? 56 : 70;
|
|
84
|
+
setIsMultiline(containerHeight > threshold);
|
|
85
|
+
}
|
|
86
|
+
}, [isCompact]);
|
|
70
87
|
const setAutoWidth = useCallback((field) => {
|
|
71
88
|
const parent = field.parentElement;
|
|
72
89
|
if (parent) {
|
|
73
90
|
const grandparent = parent.parentElement;
|
|
74
|
-
if (textIsLongerThan2Lines(field) && grandparent) {
|
|
91
|
+
if ((textIsLongerThan2Lines(field) || shouldForceMultiline) && grandparent) {
|
|
75
92
|
grandparent.style.setProperty('flex-basis', `100%`);
|
|
76
93
|
}
|
|
77
94
|
}
|
|
@@ -119,13 +136,15 @@ export const MessageBarBase = (_a) => {
|
|
|
119
136
|
if (field) {
|
|
120
137
|
if (field.value === '') {
|
|
121
138
|
setInitialLineHeight(field);
|
|
139
|
+
!shouldForceMultiline && setIsMultiline(false);
|
|
122
140
|
}
|
|
123
141
|
else {
|
|
124
142
|
setAutoHeight(field);
|
|
125
143
|
setAutoWidth(field);
|
|
144
|
+
!shouldForceMultiline && checkIfMultiline(field);
|
|
126
145
|
}
|
|
127
146
|
}
|
|
128
|
-
}, [displayMode, message, setAutoWidth]);
|
|
147
|
+
}, [displayMode, message, setAutoWidth, shouldForceMultiline, checkIfMultiline]);
|
|
129
148
|
useEffect(() => {
|
|
130
149
|
const field = textareaRef.current;
|
|
131
150
|
if (field) {
|
|
@@ -138,13 +157,15 @@ export const MessageBarBase = (_a) => {
|
|
|
138
157
|
if (textareaRef.current) {
|
|
139
158
|
if (event.target.value === '') {
|
|
140
159
|
setInitialLineHeight(textareaRef.current);
|
|
160
|
+
!shouldForceMultiline && setIsMultiline(false);
|
|
141
161
|
}
|
|
142
162
|
else {
|
|
143
163
|
setAutoHeight(textareaRef.current);
|
|
164
|
+
!shouldForceMultiline && checkIfMultiline(textareaRef.current);
|
|
144
165
|
}
|
|
145
166
|
}
|
|
146
167
|
setMessage(event.target.value);
|
|
147
|
-
}, [onChange]);
|
|
168
|
+
}, [onChange, checkIfMultiline]);
|
|
148
169
|
// Handle sending message
|
|
149
170
|
const handleSend = useCallback((newMessage) => {
|
|
150
171
|
onSendMessage(newMessage);
|
|
@@ -186,23 +207,34 @@ export const MessageBarBase = (_a) => {
|
|
|
186
207
|
setMessage(message);
|
|
187
208
|
onChange && onChange({}, message);
|
|
188
209
|
};
|
|
210
|
+
const renderAttachButton = () => {
|
|
211
|
+
var _a, _b, _c, _d, _e, _f;
|
|
212
|
+
if (!attachMenuProps && hasAttachButton) {
|
|
213
|
+
return (_jsx(AttachButton, Object.assign({ onAttachAccepted: handleAttach, isDisabled: isListeningMessage, tooltipContent: (_a = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _a === void 0 ? void 0 : _a.tooltipContent, inputTestId: (_b = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _b === void 0 ? void 0 : _b.inputTestId, isCompact: isCompact, tooltipProps: (_c = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _c === void 0 ? void 0 : _c.tooltipProps, allowedFileTypes: allowedFileTypes, minSize: minSize, maxSize: maxSize, maxFiles: maxFiles, isAttachmentDisabled: isAttachmentDisabled, onAttach: onAttach, onAttachRejected: onAttachRejected, validator: validator, dropzoneProps: dropzoneProps }, buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach, (_d = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _d === void 0 ? void 0 : _d.props)));
|
|
214
|
+
}
|
|
215
|
+
if (attachMenuProps) {
|
|
216
|
+
return (_jsx(AttachButton, Object.assign({ ref: attachButtonRef, onClick: handleAttachMenuToggle, isDisabled: isListeningMessage, tooltipContent: (_e = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _e === void 0 ? void 0 : _e.tooltipContent, isCompact: isCompact, tooltipProps: (_f = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach) === null || _f === void 0 ? void 0 : _f.tooltipProps, allowedFileTypes: allowedFileTypes, minSize: minSize, maxSize: maxSize, maxFiles: maxFiles, isAttachmentDisabled: isAttachmentDisabled, onAttach: onAttach, onAttachRejected: onAttachRejected, validator: validator, dropzoneProps: dropzoneProps }, buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.attach)));
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const isAttachButtonAtStart = attachButtonPosition === 'start';
|
|
189
220
|
const renderButtons = () => {
|
|
190
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
221
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
191
222
|
if (hasStopButton && handleStopButton) {
|
|
192
223
|
return (_jsx(StopButton, Object.assign({ onClick: handleStopButton, tooltipContent: (_a = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.stop) === null || _a === void 0 ? void 0 : _a.tooltipContent, isCompact: isCompact, tooltipProps: (_b = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.stop) === null || _b === void 0 ? void 0 : _b.tooltipProps }, (_c = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.stop) === null || _c === void 0 ? void 0 : _c.props)));
|
|
193
224
|
}
|
|
194
|
-
return (_jsxs(_Fragment, { children: [
|
|
225
|
+
return (_jsxs(_Fragment, { children: [!isAttachButtonAtStart && renderAttachButton(), hasMicrophoneButton && (_jsx(MicrophoneButton, Object.assign({ isListening: isListeningMessage, onIsListeningChange: setIsListeningMessage, onSpeechRecognition: handleSpeechRecognition, tooltipContent: (_d = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.microphone) === null || _d === void 0 ? void 0 : _d.tooltipContent, language: (_e = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.microphone) === null || _e === void 0 ? void 0 : _e.language, isCompact: isCompact, tooltipProps: (_f = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.microphone) === null || _f === void 0 ? void 0 : _f.tooltipProps }, (_g = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.microphone) === null || _g === void 0 ? void 0 : _g.props))), (alwayShowSendButton || message) && (_jsx(SendButton, Object.assign({ value: message, onClick: () => handleSend(message), isDisabled: isSendButtonDisabled, tooltipContent: (_h = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.send) === null || _h === void 0 ? void 0 : _h.tooltipContent, isCompact: isCompact, tooltipProps: (_j = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.send) === null || _j === void 0 ? void 0 : _j.tooltipProps }, (_k = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.send) === null || _k === void 0 ? void 0 : _k.props)))] }));
|
|
195
226
|
};
|
|
196
|
-
const
|
|
227
|
+
const hasGroupedActions = additionalActions || (isAttachButtonAtStart && isMultiline);
|
|
228
|
+
const messageBarContents = (_jsxs(_Fragment, { children: [isAttachButtonAtStart && !isMultiline && (_jsx("div", { className: "pf-chatbot__message-bar-actions test", children: renderAttachButton() })), _jsx("div", { className: `pf-chatbot__message-bar-input ${isCompact ? 'pf-m-compact' : ''}`, children: _jsx(TextArea, Object.assign({ className: "pf-chatbot__message-textarea", value: message, onChange: handleChange, "aria-label": isListeningMessage ? listeningText : placeholder, placeholder: isListeningMessage ? listeningText : placeholder, ref: textareaRef, onKeyDown: handleKeyDown, onCompositionStart: handleCompositionStart, onCompositionEnd: handleCompositionEnd }, props)) }), _jsx("div", { className: css('pf-chatbot__message-bar-actions', hasGroupedActions && 'pf-m-grouped'), children: hasGroupedActions ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: css('pf-chatbot__message-bar-actions-group'), children: [isAttachButtonAtStart && renderAttachButton(), additionalActions] }), _jsx("div", { className: css('pf-chatbot__message-bar-actions-group'), children: renderButtons() })] })) : (renderButtons()) })] }));
|
|
197
229
|
if (attachMenuProps) {
|
|
198
|
-
return (_jsx(AttachMenu, Object.assign({ toggle: (toggleRef) => (_jsx("div", { ref: toggleRef, className:
|
|
230
|
+
return (_jsx(AttachMenu, Object.assign({ toggle: (toggleRef) => (_jsx("div", { ref: toggleRef, className: css('pf-chatbot__message-bar', isMultiline && 'pf-m-multiline', className), children: messageBarContents })), filteredItems: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.attachMenuItems }, (attachMenuProps && { isOpen: attachMenuProps.isAttachMenuOpen }), { onOpenChange: (isAttachMenuOpen) => {
|
|
199
231
|
var _a;
|
|
200
232
|
(_a = attachButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
201
233
|
attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.setIsAttachMenuOpen(isAttachMenuOpen);
|
|
202
234
|
(attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.onAttachMenuOpenChange) && (attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.onAttachMenuOpenChange(isAttachMenuOpen));
|
|
203
235
|
}, onOpenChangeKeys: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.onAttachMenuOnOpenChangeKeys, onSelect: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.onAttachMenuSelect }, (attachMenuProps && { handleTextInputChange: attachMenuProps.onAttachMenuInputChange }), { popperProps: { direction: 'up', distance: 8 }, searchInputPlaceholder: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.attachMenuInputPlaceholder }, attachMenuProps)));
|
|
204
236
|
}
|
|
205
|
-
return (_jsx("div", { className:
|
|
237
|
+
return (_jsx("div", { className: css('pf-chatbot__message-bar', isPrimary && 'pf-m-primary', hasAiIndicator && 'pf-v6-m-ai-indicator', isThinking && 'pf-v6-m-thinking', isMultiline && 'pf-m-multiline', className), children: messageBarContents }));
|
|
206
238
|
};
|
|
207
239
|
const MessageBar = forwardRef((props, ref) => (_jsx(MessageBarBase, Object.assign({ innerRef: ref }, props))));
|
|
208
240
|
export { MessageBar };
|
|
@@ -318,4 +318,24 @@ describe('Message bar', () => {
|
|
|
318
318
|
const { container } = render(_jsx(MessageBar, { isPrimary: true, onSendMessage: jest.fn }));
|
|
319
319
|
expect(container.querySelector('.pf-m-primary')).toBeTruthy();
|
|
320
320
|
});
|
|
321
|
+
it('Renders with class pf-v6-m-ai-indicator when hasAiIndicator is true', () => {
|
|
322
|
+
render(_jsx(MessageBar, { onSendMessage: jest.fn, hasAiIndicator: true }));
|
|
323
|
+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-ai-indicator');
|
|
324
|
+
});
|
|
325
|
+
it('Renders with class pf-v6-m-thinking when isThinking is true', () => {
|
|
326
|
+
render(_jsx(MessageBar, { onSendMessage: jest.fn, isThinking: true }));
|
|
327
|
+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-thinking');
|
|
328
|
+
});
|
|
329
|
+
it('Renders with flex-basis of auto by default', () => {
|
|
330
|
+
render(_jsx(MessageBar, { onSendMessage: jest.fn }));
|
|
331
|
+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: auto;');
|
|
332
|
+
});
|
|
333
|
+
it('Renders with flex-basis of 100% when forceMultilineLayout is true', () => {
|
|
334
|
+
render(_jsx(MessageBar, { forceMultilineLayout: true, onSendMessage: jest.fn }));
|
|
335
|
+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: 100%;');
|
|
336
|
+
});
|
|
337
|
+
it('Renders with flex-basis of 100% when additionalActions is truthy', () => {
|
|
338
|
+
render(_jsx(MessageBar, { additionalActions: "actions", onSendMessage: jest.fn }));
|
|
339
|
+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar-input')).toHaveAttribute('style', 'flex-basis: 100%;');
|
|
340
|
+
});
|
|
321
341
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import { ModalProps } from '@patternfly/react-core';
|
|
3
|
+
import { ChatbotDisplayMode } from '../Chatbot';
|
|
4
|
+
export interface OnboardingProps extends ModalProps {
|
|
5
|
+
/** Class applied to modal */
|
|
6
|
+
className?: string;
|
|
7
|
+
/** Action assigned to primary modal button */
|
|
8
|
+
onPrimaryAction?: (event: React.MouseEvent | MouseEvent | KeyboardEvent) => void;
|
|
9
|
+
/** Action assigned to secondary modal button */
|
|
10
|
+
onSecondaryAction: (event: React.MouseEvent | MouseEvent | KeyboardEvent) => void;
|
|
11
|
+
/** Name of primary modal button */
|
|
12
|
+
primaryActionBtn?: string;
|
|
13
|
+
/** Name of secondary modal button */
|
|
14
|
+
secondaryActionBtn?: string;
|
|
15
|
+
/** Function that handles modal toggle */
|
|
16
|
+
handleModalToggle: (event: React.MouseEvent | MouseEvent | KeyboardEvent) => void;
|
|
17
|
+
/** Whether modal is open */
|
|
18
|
+
isModalOpen: boolean;
|
|
19
|
+
/** Title of modal */
|
|
20
|
+
title?: string;
|
|
21
|
+
/** Display mode for the Chatbot parent; this influences the styles applied */
|
|
22
|
+
displayMode?: ChatbotDisplayMode;
|
|
23
|
+
/** Optional image displayed in header */
|
|
24
|
+
headerImage?: string;
|
|
25
|
+
/** Alt text for optional image displayed in header */
|
|
26
|
+
headerImageAltText?: string;
|
|
27
|
+
/** Ref applied to modal */
|
|
28
|
+
innerRef?: React.Ref<HTMLDivElement>;
|
|
29
|
+
/** OuiaID applied to modal */
|
|
30
|
+
ouiaId?: string;
|
|
31
|
+
/** Sets modal to compact styling. */
|
|
32
|
+
isCompact?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const OnboardingBase: FunctionComponent<OnboardingProps>;
|
|
35
|
+
declare const Onboarding: import("react").ForwardRefExoticComponent<Omit<OnboardingProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
36
|
+
export default Onboarding;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef } from 'react';
|
|
14
|
+
import { Button, Content, ModalBody, ModalFooter } from '@patternfly/react-core';
|
|
15
|
+
import { ChatbotDisplayMode } from '../Chatbot';
|
|
16
|
+
import ChatbotModal from '../ChatbotModal/ChatbotModal';
|
|
17
|
+
export const OnboardingBase = (_a) => {
|
|
18
|
+
var { handleModalToggle, isModalOpen, onPrimaryAction, onSecondaryAction, primaryActionBtn = 'Continue', secondaryActionBtn = 'Skip', title = 'Onboarding', headerImage, headerImageAltText = '', displayMode = ChatbotDisplayMode.default, className, children, innerRef, ouiaId = 'Onboarding', isCompact } = _a, props = __rest(_a, ["handleModalToggle", "isModalOpen", "onPrimaryAction", "onSecondaryAction", "primaryActionBtn", "secondaryActionBtn", "title", "headerImage", "headerImageAltText", "displayMode", "className", "children", "innerRef", "ouiaId", "isCompact"]);
|
|
19
|
+
const handlePrimaryAction = (_event) => {
|
|
20
|
+
handleModalToggle(_event);
|
|
21
|
+
onPrimaryAction && onPrimaryAction(_event);
|
|
22
|
+
};
|
|
23
|
+
const handleSecondaryAction = (_event) => {
|
|
24
|
+
onSecondaryAction(_event);
|
|
25
|
+
};
|
|
26
|
+
const modal = (_jsx(ChatbotModal, Object.assign({ isOpen: isModalOpen, ouiaId: ouiaId, "aria-labelledby": "onboarding-title", "aria-describedby": "onboarding-modal", className: `pf-chatbot__onboarding-modal pf-chatbot__onboarding-modal--${displayMode} ${isCompact ? 'pf-m-compact' : ''} ${className ? className : ''}`, displayMode: displayMode, onClose: handleModalToggle }, props, { children: _jsx("section", { className: `pf-chatbot__onboarding--section`, "aria-label": title, tabIndex: -1, ref: innerRef, children: _jsxs(_Fragment, { children: [_jsxs(ModalBody, { className: "pf-chatbot__onboarding--modal-body", children: [!isCompact && headerImage && (_jsx("div", { className: "pf-chatbot__onboarding--header", children: _jsx("img", { src: headerImage, className: "pf-chatbot__onboarding--image", alt: headerImageAltText }) })), _jsxs("div", { className: "pf-chatbot__onboarding--modal-text", children: [_jsx("h1", { className: "pf-chatbot__onboarding--title", children: title }), _jsx(Content, { children: children })] })] }), _jsxs(ModalFooter, { className: "pf-chatbot__onboarding--footer", children: [_jsx(Button, { isBlock: true, variant: "primary", onClick: handlePrimaryAction, form: "onboarding-form", size: "lg", children: primaryActionBtn }, "onboarding-modal-primary"), _jsx(Button, { isBlock: true, variant: "secondary", onClick: handleSecondaryAction, size: "lg", children: secondaryActionBtn }, "onboarding-modal-secondary")] })] }) }) })));
|
|
27
|
+
return modal;
|
|
28
|
+
};
|
|
29
|
+
const Onboarding = forwardRef((props, ref) => (_jsx(OnboardingBase, Object.assign({ innerRef: ref }, props))));
|
|
30
|
+
export default Onboarding;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { render, screen } from '@testing-library/react';
|
|
12
|
+
import '@testing-library/jest-dom';
|
|
13
|
+
import userEvent from '@testing-library/user-event';
|
|
14
|
+
import Onboarding from './Onboarding';
|
|
15
|
+
const handleModalToggle = jest.fn();
|
|
16
|
+
const onPrimaryAction = jest.fn();
|
|
17
|
+
const onSecondaryAction = jest.fn();
|
|
18
|
+
const body = 'Experience personalized assistance and seamless problem-solving, simplifying your journey with Red Hat every step of the way.';
|
|
19
|
+
describe('Onboarding', () => {
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
it('should render modal correctly', () => {
|
|
24
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, ouiaId: "Terms", children: body }));
|
|
25
|
+
expect(screen.getByRole('heading', { name: /Onboarding/i })).toBeTruthy();
|
|
26
|
+
expect(screen.getByRole('button', { name: /Continue/i })).toBeTruthy();
|
|
27
|
+
expect(screen.getByRole('button', { name: /Skip/i })).toBeTruthy();
|
|
28
|
+
expect(screen.getByText(body)).toBeTruthy();
|
|
29
|
+
expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__onboarding-modal');
|
|
30
|
+
expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__onboarding-modal--default');
|
|
31
|
+
});
|
|
32
|
+
it('should handle image and altText props', () => {
|
|
33
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, headerImage: "./image.png", headerImageAltText: "Test image", children: body }));
|
|
34
|
+
expect(screen.getByRole('img')).toBeTruthy();
|
|
35
|
+
expect(screen.getByRole('img')).toHaveAttribute('alt', 'Test image');
|
|
36
|
+
});
|
|
37
|
+
it('should handle className prop', () => {
|
|
38
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, className: "test", children: body }));
|
|
39
|
+
expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__onboarding-modal');
|
|
40
|
+
expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__onboarding-modal--default');
|
|
41
|
+
expect(screen.getByRole('dialog')).toHaveClass('test');
|
|
42
|
+
});
|
|
43
|
+
it('should handle title prop', () => {
|
|
44
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, title: "Updated title", children: body }));
|
|
45
|
+
expect(screen.getByRole('heading', { name: /Updated title/i })).toBeTruthy();
|
|
46
|
+
expect(screen.queryByRole('heading', { name: /Onboarding/i })).toBeFalsy();
|
|
47
|
+
});
|
|
48
|
+
it('should handle primary button prop', () => {
|
|
49
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, primaryActionBtn: "First", children: body }));
|
|
50
|
+
expect(screen.getByRole('button', { name: /First/i })).toBeTruthy();
|
|
51
|
+
expect(screen.queryByRole('button', { name: /Continue/i })).toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
it('should handle secondary button prop', () => {
|
|
54
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, secondaryActionBtn: "Second", children: body }));
|
|
55
|
+
expect(screen.getByRole('button', { name: /Second/i })).toBeTruthy();
|
|
56
|
+
expect(screen.queryByRole('button', { name: /Skip/i })).toBeFalsy();
|
|
57
|
+
});
|
|
58
|
+
it('should handle primary button click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
render(_jsx(Onboarding, { isModalOpen: true, onPrimaryAction: onPrimaryAction, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, children: body }));
|
|
60
|
+
yield userEvent.click(screen.getByRole('button', { name: /Continue/i }));
|
|
61
|
+
expect(onPrimaryAction).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(handleModalToggle).toHaveBeenCalledTimes(1);
|
|
63
|
+
}));
|
|
64
|
+
it('should handle secondary button click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, children: body }));
|
|
66
|
+
yield userEvent.click(screen.getByRole('button', { name: /Skip/i }));
|
|
67
|
+
expect(onSecondaryAction).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(handleModalToggle).not.toHaveBeenCalled();
|
|
69
|
+
}));
|
|
70
|
+
it('should handle isCompact prop', () => {
|
|
71
|
+
render(_jsx(Onboarding, { isModalOpen: true, onSecondaryAction: onSecondaryAction, handleModalToggle: handleModalToggle, isCompact: true, headerImage: "./image.png", headerImageAltText: "Test image", children: body }));
|
|
72
|
+
expect(screen.getByRole('dialog')).toHaveClass('pf-m-compact');
|
|
73
|
+
expect(screen.queryByRole('img')).toBeFalsy();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -29,6 +29,10 @@ export interface ActionProps extends Omit<ButtonProps, 'ref'> {
|
|
|
29
29
|
type ExtendedActionProps = ActionProps & {
|
|
30
30
|
[key: string]: any;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* The various actions that can be attached to a bot message for users to interact with.
|
|
34
|
+
* Use this component when passing children to Message to customize its structure.
|
|
35
|
+
*/
|
|
32
36
|
export interface ResponseActionProps {
|
|
33
37
|
/** Props for message actions, such as feedback (positive or negative), copy button, share, and listen */
|
|
34
38
|
actions: Record<string, ExtendedActionProps | undefined> & {
|
|
@@ -40,6 +44,9 @@ export interface ResponseActionProps {
|
|
|
40
44
|
listen?: ActionProps;
|
|
41
45
|
edit?: ActionProps;
|
|
42
46
|
};
|
|
47
|
+
/** When true, the selected action will persist even when clicking outside the component.
|
|
48
|
+
* When false (default), clicking outside or clicking another action will deselect the current selection. */
|
|
49
|
+
persistActionSelection?: boolean;
|
|
43
50
|
}
|
|
44
51
|
export declare const ResponseActions: FunctionComponent<ResponseActionProps>;
|
|
45
52
|
export default ResponseActions;
|
|
@@ -14,10 +14,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { useEffect, useRef, useState } from 'react';
|
|
15
15
|
import { ExternalLinkAltIcon, VolumeUpIcon, OutlinedThumbsUpIcon, OutlinedThumbsDownIcon, OutlinedCopyIcon, DownloadIcon, PencilAltIcon } from '@patternfly/react-icons';
|
|
16
16
|
import ResponseActionButton from './ResponseActionButton';
|
|
17
|
-
export const ResponseActions = ({ actions }) => {
|
|
17
|
+
export const ResponseActions = ({ actions, persistActionSelection = false }) => {
|
|
18
18
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
|
|
19
19
|
const [activeButton, setActiveButton] = useState();
|
|
20
20
|
const [clickStatePersisted, setClickStatePersisted] = useState(false);
|
|
21
|
+
const { positive, negative, copy, edit, share, download, listen } = actions, additionalActions = __rest(actions, ["positive", "negative", "copy", "edit", "share", "download", "listen"]);
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
// Define the order of precedence for checking initial `isClicked`
|
|
23
24
|
const actionPrecedence = ['positive', 'negative', 'copy', 'edit', 'share', 'download', 'listen'];
|
|
@@ -39,11 +40,18 @@ export const ResponseActions = ({ actions }) => {
|
|
|
39
40
|
// Click state is explicitly controlled by consumer.
|
|
40
41
|
setClickStatePersisted(true);
|
|
41
42
|
}
|
|
43
|
+
// If persistActionSelection is true, all selections are persisted
|
|
44
|
+
if (persistActionSelection) {
|
|
45
|
+
setClickStatePersisted(true);
|
|
46
|
+
}
|
|
42
47
|
setActiveButton(initialActive);
|
|
43
|
-
}, [actions]);
|
|
44
|
-
const { positive, negative, copy, edit, share, download, listen } = actions, additionalActions = __rest(actions, ["positive", "negative", "copy", "edit", "share", "download", "listen"]);
|
|
48
|
+
}, [actions, persistActionSelection]);
|
|
45
49
|
const responseActions = useRef(null);
|
|
46
50
|
useEffect(() => {
|
|
51
|
+
// Only add click outside listener if not persisting selection
|
|
52
|
+
if (persistActionSelection) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
47
55
|
const handleClickOutside = (e) => {
|
|
48
56
|
if (responseActions.current && !responseActions.current.contains(e.target) && !clickStatePersisted) {
|
|
49
57
|
setActiveButton(undefined);
|
|
@@ -53,13 +61,26 @@ export const ResponseActions = ({ actions }) => {
|
|
|
53
61
|
return () => {
|
|
54
62
|
window.removeEventListener('click', handleClickOutside);
|
|
55
63
|
};
|
|
56
|
-
}, [clickStatePersisted]);
|
|
64
|
+
}, [clickStatePersisted, persistActionSelection]);
|
|
57
65
|
const handleClick = (e, id, onClick) => {
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
if (persistActionSelection) {
|
|
67
|
+
if (activeButton === id) {
|
|
68
|
+
// Toggle off if clicking the same button
|
|
69
|
+
setActiveButton(undefined);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Set new active button
|
|
73
|
+
setActiveButton(id);
|
|
74
|
+
}
|
|
75
|
+
setClickStatePersisted(true);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
setClickStatePersisted(false);
|
|
79
|
+
setActiveButton(id);
|
|
80
|
+
}
|
|
60
81
|
onClick && onClick(e);
|
|
61
82
|
};
|
|
62
|
-
return (_jsxs("div", { ref: responseActions, className: "pf-chatbot__response-actions", children: [positive && (_jsx(ResponseActionButton, Object.assign({}, positive, { ariaLabel: (_a = positive.ariaLabel) !== null && _a !== void 0 ? _a : 'Good response', clickedAriaLabel: (_b = positive.ariaLabel) !== null && _b !== void 0 ? _b : '
|
|
83
|
+
return (_jsxs("div", { ref: responseActions, className: "pf-chatbot__response-actions", children: [positive && (_jsx(ResponseActionButton, Object.assign({}, positive, { ariaLabel: (_a = positive.ariaLabel) !== null && _a !== void 0 ? _a : 'Good response', clickedAriaLabel: (_b = positive.ariaLabel) !== null && _b !== void 0 ? _b : 'Good response recorded', onClick: (e) => handleClick(e, 'positive', positive.onClick), className: positive.className, isDisabled: positive.isDisabled, tooltipContent: (_c = positive.tooltipContent) !== null && _c !== void 0 ? _c : 'Good response', clickedTooltipContent: (_d = positive.clickedTooltipContent) !== null && _d !== void 0 ? _d : 'Good response recorded', tooltipProps: positive.tooltipProps, icon: _jsx(OutlinedThumbsUpIcon, {}), isClicked: activeButton === 'positive', ref: positive.ref, "aria-expanded": positive['aria-expanded'], "aria-controls": positive['aria-controls'] }))), negative && (_jsx(ResponseActionButton, Object.assign({}, negative, { ariaLabel: (_e = negative.ariaLabel) !== null && _e !== void 0 ? _e : 'Bad response', clickedAriaLabel: (_f = negative.ariaLabel) !== null && _f !== void 0 ? _f : 'Bad response recorded', onClick: (e) => handleClick(e, 'negative', negative.onClick), className: negative.className, isDisabled: negative.isDisabled, tooltipContent: (_g = negative.tooltipContent) !== null && _g !== void 0 ? _g : 'Bad response', clickedTooltipContent: (_h = negative.clickedTooltipContent) !== null && _h !== void 0 ? _h : 'Bad response recorded', tooltipProps: negative.tooltipProps, icon: _jsx(OutlinedThumbsDownIcon, {}), isClicked: activeButton === 'negative', ref: negative.ref, "aria-expanded": negative['aria-expanded'], "aria-controls": negative['aria-controls'] }))), copy && (_jsx(ResponseActionButton, Object.assign({}, copy, { ariaLabel: (_j = copy.ariaLabel) !== null && _j !== void 0 ? _j : 'Copy', clickedAriaLabel: (_k = copy.ariaLabel) !== null && _k !== void 0 ? _k : 'Copied', onClick: (e) => handleClick(e, 'copy', copy.onClick), className: copy.className, isDisabled: copy.isDisabled, tooltipContent: (_l = copy.tooltipContent) !== null && _l !== void 0 ? _l : 'Copy', clickedTooltipContent: (_m = copy.clickedTooltipContent) !== null && _m !== void 0 ? _m : 'Copied', tooltipProps: copy.tooltipProps, icon: _jsx(OutlinedCopyIcon, {}), isClicked: activeButton === 'copy', ref: copy.ref, "aria-expanded": copy['aria-expanded'], "aria-controls": copy['aria-controls'] }))), edit && (_jsx(ResponseActionButton, Object.assign({}, edit, { ariaLabel: (_o = edit.ariaLabel) !== null && _o !== void 0 ? _o : 'Edit', clickedAriaLabel: (_p = edit.ariaLabel) !== null && _p !== void 0 ? _p : 'Editing', onClick: (e) => handleClick(e, 'edit', edit.onClick), className: edit.className, isDisabled: edit.isDisabled, tooltipContent: (_q = edit.tooltipContent) !== null && _q !== void 0 ? _q : 'Edit ', clickedTooltipContent: (_r = edit.clickedTooltipContent) !== null && _r !== void 0 ? _r : 'Editing', tooltipProps: edit.tooltipProps, icon: _jsx(PencilAltIcon, {}), isClicked: activeButton === 'edit', ref: edit.ref, "aria-expanded": edit['aria-expanded'], "aria-controls": edit['aria-controls'] }))), share && (_jsx(ResponseActionButton, Object.assign({}, share, { ariaLabel: (_s = share.ariaLabel) !== null && _s !== void 0 ? _s : 'Share', clickedAriaLabel: (_t = share.ariaLabel) !== null && _t !== void 0 ? _t : 'Shared', onClick: (e) => handleClick(e, 'share', share.onClick), className: share.className, isDisabled: share.isDisabled, tooltipContent: (_u = share.tooltipContent) !== null && _u !== void 0 ? _u : 'Share', clickedTooltipContent: (_v = share.clickedTooltipContent) !== null && _v !== void 0 ? _v : 'Shared', tooltipProps: share.tooltipProps, icon: _jsx(ExternalLinkAltIcon, {}), isClicked: activeButton === 'share', ref: share.ref, "aria-expanded": share['aria-expanded'], "aria-controls": share['aria-controls'] }))), download && (_jsx(ResponseActionButton, Object.assign({}, download, { ariaLabel: (_w = download.ariaLabel) !== null && _w !== void 0 ? _w : 'Download', clickedAriaLabel: (_x = download.ariaLabel) !== null && _x !== void 0 ? _x : 'Downloaded', onClick: (e) => handleClick(e, 'download', download.onClick), className: download.className, isDisabled: download.isDisabled, tooltipContent: (_y = download.tooltipContent) !== null && _y !== void 0 ? _y : 'Download', clickedTooltipContent: (_z = download.clickedTooltipContent) !== null && _z !== void 0 ? _z : 'Downloaded', tooltipProps: download.tooltipProps, icon: _jsx(DownloadIcon, {}), isClicked: activeButton === 'download', ref: download.ref, "aria-expanded": download['aria-expanded'], "aria-controls": download['aria-controls'] }))), listen && (_jsx(ResponseActionButton, Object.assign({}, listen, { ariaLabel: (_0 = listen.ariaLabel) !== null && _0 !== void 0 ? _0 : 'Listen', clickedAriaLabel: (_1 = listen.ariaLabel) !== null && _1 !== void 0 ? _1 : 'Listening', onClick: (e) => handleClick(e, 'listen', listen.onClick), className: listen.className, isDisabled: listen.isDisabled, tooltipContent: (_2 = listen.tooltipContent) !== null && _2 !== void 0 ? _2 : 'Listen', clickedTooltipContent: (_3 = listen.clickedTooltipContent) !== null && _3 !== void 0 ? _3 : 'Listening', tooltipProps: listen.tooltipProps, icon: _jsx(VolumeUpIcon, {}), isClicked: activeButton === 'listen', ref: listen.ref, "aria-expanded": listen['aria-expanded'], "aria-controls": listen['aria-controls'] }))), Object.keys(additionalActions).map((action) => {
|
|
63
84
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
64
85
|
return (_createElement(ResponseActionButton, Object.assign({}, additionalActions[action], { key: action, ariaLabel: (_a = additionalActions[action]) === null || _a === void 0 ? void 0 : _a.ariaLabel, clickedAriaLabel: (_b = additionalActions[action]) === null || _b === void 0 ? void 0 : _b.clickedAriaLabel, onClick: (e) => { var _a; return handleClick(e, action, (_a = additionalActions[action]) === null || _a === void 0 ? void 0 : _a.onClick); }, className: (_c = additionalActions[action]) === null || _c === void 0 ? void 0 : _c.className, isDisabled: (_d = additionalActions[action]) === null || _d === void 0 ? void 0 : _d.isDisabled, tooltipContent: (_e = additionalActions[action]) === null || _e === void 0 ? void 0 : _e.tooltipContent, tooltipProps: (_f = additionalActions[action]) === null || _f === void 0 ? void 0 : _f.tooltipProps, clickedTooltipContent: (_g = additionalActions[action]) === null || _g === void 0 ? void 0 : _g.clickedTooltipContent, icon: (_h = additionalActions[action]) === null || _h === void 0 ? void 0 : _h.icon, isClicked: activeButton === action, ref: (_j = additionalActions[action]) === null || _j === void 0 ? void 0 : _j.ref, "aria-expanded": (_k = additionalActions[action]) === null || _k === void 0 ? void 0 : _k['aria-expanded'], "aria-controls": (_l = additionalActions[action]) === null || _l === void 0 ? void 0 : _l['aria-controls'] })));
|
|
65
86
|
})] }));
|
|
@@ -15,8 +15,8 @@ import userEvent from '@testing-library/user-event';
|
|
|
15
15
|
import { DownloadIcon, InfoCircleIcon, RedoIcon } from '@patternfly/react-icons';
|
|
16
16
|
import Message from '../Message';
|
|
17
17
|
const ALL_ACTIONS = [
|
|
18
|
-
{ type: 'positive', label: 'Good response', clickedLabel: '
|
|
19
|
-
{ type: 'negative', label: 'Bad response', clickedLabel: '
|
|
18
|
+
{ type: 'positive', label: 'Good response', clickedLabel: 'Good response recorded' },
|
|
19
|
+
{ type: 'negative', label: 'Bad response', clickedLabel: 'Bad response recorded' },
|
|
20
20
|
{ type: 'copy', label: 'Copy', clickedLabel: 'Copied' },
|
|
21
21
|
{ type: 'edit', label: 'Edit', clickedLabel: 'Editing' },
|
|
22
22
|
{ type: 'share', label: 'Share', clickedLabel: 'Shared' },
|
|
@@ -83,13 +83,13 @@ describe('ResponseActions', () => {
|
|
|
83
83
|
expect(button).toBeTruthy();
|
|
84
84
|
});
|
|
85
85
|
yield userEvent.click(goodBtn);
|
|
86
|
-
expect(screen.getByRole('button', { name: '
|
|
86
|
+
expect(screen.getByRole('button', { name: 'Good response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
87
87
|
let unclickedButtons = buttons.filter((button) => button !== goodBtn);
|
|
88
88
|
unclickedButtons.forEach((button) => {
|
|
89
89
|
expect(button).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
90
90
|
});
|
|
91
91
|
yield userEvent.click(badBtn);
|
|
92
|
-
expect(screen.getByRole('button', { name: '
|
|
92
|
+
expect(screen.getByRole('button', { name: 'Bad response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
93
93
|
unclickedButtons = buttons.filter((button) => button !== badBtn);
|
|
94
94
|
unclickedButtons.forEach((button) => {
|
|
95
95
|
expect(button).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
@@ -106,10 +106,10 @@ describe('ResponseActions', () => {
|
|
|
106
106
|
expect(goodBtn).toBeTruthy();
|
|
107
107
|
expect(badBtn).toBeTruthy();
|
|
108
108
|
yield userEvent.click(goodBtn);
|
|
109
|
-
expect(screen.getByRole('button', { name: '
|
|
109
|
+
expect(screen.getByRole('button', { name: 'Good response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
110
110
|
expect(badBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
111
111
|
yield userEvent.click(badBtn);
|
|
112
|
-
expect(screen.getByRole('button', { name: '
|
|
112
|
+
expect(screen.getByRole('button', { name: 'Bad response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
113
113
|
expect(goodBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
114
114
|
yield userEvent.click(screen.getByText("I updated your account with those settings. You're ready to set up your first dashboard!"));
|
|
115
115
|
expect(goodBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
@@ -182,28 +182,28 @@ describe('ResponseActions', () => {
|
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
184
|
it('should be able to call onClick correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
-
|
|
185
|
+
for (const { type, label } of ALL_ACTIONS) {
|
|
186
186
|
const spy = jest.fn();
|
|
187
187
|
render(_jsx(ResponseActions, { actions: { [type]: { onClick: spy } } }));
|
|
188
188
|
yield userEvent.click(screen.getByRole('button', { name: label }));
|
|
189
189
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
190
|
-
}
|
|
190
|
+
}
|
|
191
191
|
}));
|
|
192
192
|
it('should swap clicked and non-clicked aria labels on click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
|
|
193
|
+
for (const { type, label, clickedLabel } of ALL_ACTIONS) {
|
|
194
194
|
render(_jsx(ResponseActions, { actions: { [type]: { onClick: jest.fn() } } }));
|
|
195
195
|
expect(screen.getByRole('button', { name: label })).toBeTruthy();
|
|
196
196
|
yield userEvent.click(screen.getByRole('button', { name: label }));
|
|
197
197
|
expect(screen.getByRole('button', { name: clickedLabel })).toBeTruthy();
|
|
198
|
-
}
|
|
198
|
+
}
|
|
199
199
|
}));
|
|
200
200
|
it('should swap clicked and non-clicked tooltips on click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
|
|
201
|
+
for (const { type, label, clickedLabel } of ALL_ACTIONS) {
|
|
202
202
|
render(_jsx(ResponseActions, { actions: { [type]: { onClick: jest.fn() } } }));
|
|
203
203
|
expect(screen.getByRole('button', { name: label })).toBeTruthy();
|
|
204
204
|
yield userEvent.click(screen.getByRole('button', { name: label }));
|
|
205
205
|
expect(screen.getByRole('tooltip', { name: clickedLabel })).toBeTruthy();
|
|
206
|
-
}
|
|
206
|
+
}
|
|
207
207
|
}));
|
|
208
208
|
it('should be able to change aria labels', () => {
|
|
209
209
|
const actions = [
|
|
@@ -255,4 +255,59 @@ describe('ResponseActions', () => {
|
|
|
255
255
|
expect(screen.getByTestId(action[key])).toBeTruthy();
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
|
+
// we are testing for the reverse case already above
|
|
259
|
+
it('should not deselect when clicking outside when persistActionSelection is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
260
|
+
render(_jsx(Message, { name: "Bot", role: "bot", avatar: "", content: "Test content", actions: {
|
|
261
|
+
positive: {},
|
|
262
|
+
negative: {}
|
|
263
|
+
}, persistActionSelection: true }));
|
|
264
|
+
const goodBtn = screen.getByRole('button', { name: 'Good response' });
|
|
265
|
+
yield userEvent.click(goodBtn);
|
|
266
|
+
expect(screen.getByRole('button', { name: 'Good response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
267
|
+
yield userEvent.click(screen.getByText('Test content'));
|
|
268
|
+
expect(screen.getByRole('button', { name: 'Good response recorded' })).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
269
|
+
}));
|
|
270
|
+
it('should switch selection to another button when persistActionSelection is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
271
|
+
render(_jsx(Message, { name: "Bot", role: "bot", avatar: "", content: "Test content", actions: {
|
|
272
|
+
positive: {},
|
|
273
|
+
negative: {}
|
|
274
|
+
}, persistActionSelection: true }));
|
|
275
|
+
const goodBtn = screen.getByRole('button', { name: 'Good response' });
|
|
276
|
+
const badBtn = screen.getByRole('button', { name: 'Bad response' });
|
|
277
|
+
yield userEvent.click(goodBtn);
|
|
278
|
+
expect(goodBtn).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
279
|
+
yield userEvent.click(badBtn);
|
|
280
|
+
expect(badBtn).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
281
|
+
expect(goodBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
282
|
+
}));
|
|
283
|
+
it('should toggle off when clicking the same button when persistActionSelection is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
|
+
render(_jsx(Message, { name: "Bot", role: "bot", avatar: "", content: "Test content", actions: {
|
|
285
|
+
positive: {},
|
|
286
|
+
negative: {}
|
|
287
|
+
}, persistActionSelection: true }));
|
|
288
|
+
const goodBtn = screen.getByRole('button', { name: 'Good response' });
|
|
289
|
+
yield userEvent.click(goodBtn);
|
|
290
|
+
expect(goodBtn).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
291
|
+
yield userEvent.click(goodBtn);
|
|
292
|
+
expect(goodBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
293
|
+
}));
|
|
294
|
+
it('should work with custom actions when persistActionSelection is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
+
const actions = {
|
|
296
|
+
positive: { 'data-testid': 'positive', onClick: jest.fn() },
|
|
297
|
+
negative: { 'data-testid': 'negative', onClick: jest.fn() },
|
|
298
|
+
custom: {
|
|
299
|
+
'data-testid': 'custom',
|
|
300
|
+
onClick: jest.fn(),
|
|
301
|
+
ariaLabel: 'Custom',
|
|
302
|
+
tooltipContent: 'Custom action',
|
|
303
|
+
icon: _jsx(DownloadIcon, {})
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
render(_jsx(ResponseActions, { actions: actions, persistActionSelection: true }));
|
|
307
|
+
const customBtn = screen.getByTestId('custom');
|
|
308
|
+
yield userEvent.click(customBtn);
|
|
309
|
+
expect(customBtn).toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
310
|
+
yield userEvent.click(customBtn);
|
|
311
|
+
expect(customBtn).not.toHaveClass('pf-chatbot__button--response-action-clicked');
|
|
312
|
+
}));
|
|
258
313
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The container for grouping multiple related ResponseActions components, typically used for having different persistence states amongst groups.
|
|
4
|
+
* Use this component when passing children to Message to customize its structure.
|
|
5
|
+
*/
|
|
6
|
+
export interface ResponseActionsGroupsProps extends HTMLProps<HTMLDivElement> {
|
|
7
|
+
/** Content to render inside the response actions groups container */
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** Additional classes applied to the response actions groups container. */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const ResponseActionsGroups: FunctionComponent<ResponseActionsGroupsProps>;
|
|
13
|
+
export default ResponseActionsGroups;
|