@patternfly/chatbot 6.7.0-prerelease.4 → 6.7.0
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/Message/Message.d.ts +4 -2
- package/dist/cjs/Message/Message.js +19 -2
- package/dist/cjs/Message/Message.test.js +13 -1
- package/dist/css/main.css +4 -0
- package/dist/css/main.css.map +1 -1
- package/dist/esm/Message/Message.d.ts +4 -2
- package/dist/esm/Message/Message.js +19 -2
- package/dist/esm/Message/Message.test.js +13 -1
- package/package.json +8 -8
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx +3 -13
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithClickedResponseActions.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithCustomResponseActions.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithCustomStructure.tsx +1 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithDeepThinking.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithDividers.tsx +1 -8
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithFeedback.tsx +0 -5
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithFeedbackTimeout.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithIconSwapping.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownDeepThinking.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolCall.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolResponse.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMultipleActionGroups.tsx +0 -3
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithPersistedActions.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithQuickResponses.tsx +0 -8
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithQuickStart.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithResponseActions.tsx +0 -3
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx +0 -10
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolCall.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolResponse.tsx +0 -3
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +6 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessageWithExtraContent.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotWelcomeInteraction.tsx +0 -3
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotAttachment.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotAttachmentMenu.tsx +1 -3
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotCompact.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotDisplayMode.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotInDrawer.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotScrolling.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotTranscripts.tsx +0 -7
- package/patternfly-docs/content/extensions/chatbot/examples/demos/EmbeddedChatbot.tsx +0 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/EmbeddedComparisonChatbot.tsx +0 -3
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Feedback.tsx +0 -2
- package/patternfly-docs/content/extensions/chatbot/examples/demos/WhiteEmbeddedChatbot.tsx +0 -4
- package/src/Message/Message.scss +5 -0
- package/src/Message/Message.test.tsx +13 -1
- package/src/Message/Message.tsx +37 -11
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FunctionComponent, useState, useRef } from 'react';
|
|
2
2
|
import Message from '@patternfly/chatbot/dist/dynamic/Message';
|
|
3
|
-
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
|
4
3
|
import '@patternfly/react-core/dist/styles/base.css';
|
|
5
4
|
import '@patternfly/chatbot/dist/css/main.css';
|
|
6
5
|
|
|
@@ -37,7 +36,6 @@ export const MessageWithFeedbackExample: FunctionComponent = () => {
|
|
|
37
36
|
<Message
|
|
38
37
|
name="Bot"
|
|
39
38
|
role="bot"
|
|
40
|
-
avatar={patternflyAvatar}
|
|
41
39
|
content="Bot message with user feedback flow; click on a message action to launch the feedback flow. Click submit to see the thank-you message."
|
|
42
40
|
actions={{
|
|
43
41
|
positive: {
|
|
@@ -39,7 +39,6 @@ import PFHorizontalLogoColor from '../UI/PF-HorizontalLogo-Color.svg';
|
|
|
39
39
|
import PFHorizontalLogoReverse from '../UI/PF-HorizontalLogo-Reverse.svg';
|
|
40
40
|
import { BarsIcon } from '@patternfly/react-icons';
|
|
41
41
|
import userAvatar from '../Messages/user_avatar.svg';
|
|
42
|
-
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
|
43
42
|
import '@patternfly/react-core/dist/styles/base.css';
|
|
44
43
|
import '@patternfly/chatbot/dist/css/main.css';
|
|
45
44
|
|
|
@@ -109,7 +108,6 @@ const initialMessages: MessageProps[] = [
|
|
|
109
108
|
role: 'bot',
|
|
110
109
|
content: markdown,
|
|
111
110
|
name: 'Bot',
|
|
112
|
-
avatar: patternflyAvatar,
|
|
113
111
|
timestamp: date.toLocaleString(),
|
|
114
112
|
actions: {
|
|
115
113
|
// eslint-disable-next-line no-console
|
|
@@ -221,7 +219,6 @@ export const EmbeddedChatbotDemo: FunctionComponent = () => {
|
|
|
221
219
|
role: 'bot',
|
|
222
220
|
content: 'API response goes here',
|
|
223
221
|
name: 'Bot',
|
|
224
|
-
avatar: patternflyAvatar,
|
|
225
222
|
isLoading: true,
|
|
226
223
|
timestamp: date.toLocaleString(),
|
|
227
224
|
isPrimary: true
|
|
@@ -242,7 +239,6 @@ export const EmbeddedChatbotDemo: FunctionComponent = () => {
|
|
|
242
239
|
role: 'bot',
|
|
243
240
|
content: 'API response goes here',
|
|
244
241
|
name: 'Bot',
|
|
245
|
-
avatar: patternflyAvatar,
|
|
246
242
|
isLoading: false,
|
|
247
243
|
actions: {
|
|
248
244
|
// eslint-disable-next-line no-console
|
package/src/Message/Message.scss
CHANGED
|
@@ -11,12 +11,17 @@
|
|
|
11
11
|
// --------------------------------------------------------------------------
|
|
12
12
|
&-avatar.pf-v6-c-avatar {
|
|
13
13
|
--pf-v6-c-avatar--BorderRadius: 0;
|
|
14
|
+
flex-shrink: 0;
|
|
14
15
|
position: sticky;
|
|
15
16
|
top: var(--pf-t--global--spacer--md);
|
|
16
17
|
object-fit: cover;
|
|
17
18
|
pointer-events: none; // prevent dragging - interferes with FileDropZone
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
&-avatar.pf-v6-c-avatar:not(.pf-m-colorful) {
|
|
22
|
+
--pf-v6-c-avatar--BackgroundColor: var(--pf-t--global--background--color--floating--default);
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
&-avatar.pf-chatbot__message-avatar--round.pf-v6-c-avatar {
|
|
21
26
|
&:not(.pf-m-xl, .pf-m-lg, .pf-m-md, .pf-m-sm) {
|
|
22
27
|
--pf-v6-c-avatar--Width: 3rem;
|
|
@@ -242,11 +242,23 @@ describe('Message', () => {
|
|
|
242
242
|
).toBeInTheDocument();
|
|
243
243
|
});
|
|
244
244
|
it('should render avatar correctly', () => {
|
|
245
|
-
render(<Message avatar="./testImg" role="
|
|
245
|
+
render(<Message avatar="./testImg" role="user" name="A" content="Hi" />);
|
|
246
246
|
expect(screen.getByRole('img')).toHaveAttribute('src', './testImg');
|
|
247
247
|
});
|
|
248
248
|
it('should not render avatar if no avatar prop is passed', () => {
|
|
249
|
+
render(<Message role="user" name="A" content="Hi" />);
|
|
250
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
251
|
+
});
|
|
252
|
+
it('should render bot avatar if no avatar prop is passed', () => {
|
|
249
253
|
render(<Message role="bot" name="Bot" content="Hi" />);
|
|
254
|
+
expect(screen.queryAllByRole('img', { hidden: true })[0]).toBeVisible();
|
|
255
|
+
});
|
|
256
|
+
it('should not render avatar if isAvatarHidden is passed', () => {
|
|
257
|
+
render(<Message role="user" name="A" content="Hi" isAvatarHidden />);
|
|
258
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
259
|
+
});
|
|
260
|
+
it('should not render bot avatar if isAvatarHidden is passed', () => {
|
|
261
|
+
render(<Message role="bot" name="Bot" content="Hi" isAvatarHidden />);
|
|
250
262
|
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
251
263
|
});
|
|
252
264
|
it('should render botWord correctly', () => {
|
package/src/Message/Message.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import DeepThinking, { DeepThinkingProps } from '../DeepThinking';
|
|
|
36
36
|
import ToolCall, { ToolCallProps } from '../ToolCall';
|
|
37
37
|
import MarkdownContent from '../MarkdownContent';
|
|
38
38
|
import { css } from '@patternfly/react-styles';
|
|
39
|
+
import RhUiAiChatbotIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ai-chatbot-icon';
|
|
39
40
|
|
|
40
41
|
export interface MessageAttachment {
|
|
41
42
|
/** Name of file attached to the message */
|
|
@@ -84,8 +85,10 @@ export interface MessageProps extends Omit<HTMLProps<HTMLDivElement>, 'role'> {
|
|
|
84
85
|
extraContent?: MessageExtraContent;
|
|
85
86
|
/** Name of the user */
|
|
86
87
|
name?: string;
|
|
87
|
-
/** Avatar
|
|
88
|
-
avatar?: string;
|
|
88
|
+
/** Avatar for the user. Pass a string for an image src, or a ReactNode for custom content like an svg or icon. Avatars for Messages with role="bot" are pre-defined and not customizable. */
|
|
89
|
+
avatar?: string | ReactNode;
|
|
90
|
+
/** Flag indicating whether the avatar is hidden */
|
|
91
|
+
isAvatarHidden?: boolean;
|
|
89
92
|
/** Timestamp for the message */
|
|
90
93
|
timestamp?: string;
|
|
91
94
|
/** Set this to true if message is being loaded */
|
|
@@ -214,6 +217,7 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
|
|
|
214
217
|
extraContent,
|
|
215
218
|
name,
|
|
216
219
|
avatar,
|
|
220
|
+
isAvatarHidden = false,
|
|
217
221
|
timestamp,
|
|
218
222
|
isLoading,
|
|
219
223
|
actions,
|
|
@@ -326,6 +330,36 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
|
|
|
326
330
|
);
|
|
327
331
|
};
|
|
328
332
|
|
|
333
|
+
const avatarClasses = css(
|
|
334
|
+
`pf-chatbot__message-avatar ${hasRoundAvatar ? 'pf-chatbot__message-avatar--round' : ''} ${avatarClassName ? avatarClassName : ''}`
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
/* We are using an empty alt tag intentionally in order to reduce noise on screen readers */
|
|
338
|
+
const botAvatar = (
|
|
339
|
+
<Avatar className={avatarClasses} alt="" isBordered {...avatarProps} src={undefined} initials={undefined}>
|
|
340
|
+
<RhUiAiChatbotIcon />
|
|
341
|
+
</Avatar>
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
let _avatar: ReactNode | undefined;
|
|
345
|
+
|
|
346
|
+
if (!isAvatarHidden) {
|
|
347
|
+
if (role === 'bot') {
|
|
348
|
+
_avatar = botAvatar;
|
|
349
|
+
} else if (avatar) {
|
|
350
|
+
_avatar =
|
|
351
|
+
typeof avatar === 'string' ? (
|
|
352
|
+
<Avatar className={avatarClasses} src={avatar} alt="" {...avatarProps} />
|
|
353
|
+
) : (
|
|
354
|
+
<Avatar className={avatarClasses} alt="" {...avatarProps}>
|
|
355
|
+
{avatar}
|
|
356
|
+
</Avatar>
|
|
357
|
+
);
|
|
358
|
+
} else if (avatarProps?.initials) {
|
|
359
|
+
_avatar = <Avatar className={avatarClasses} alt="" {...avatarProps} />;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
329
363
|
return (
|
|
330
364
|
<section
|
|
331
365
|
aria-label={`Message from ${role} - ${dateString}`}
|
|
@@ -335,15 +369,7 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
|
|
|
335
369
|
ref={innerRef}
|
|
336
370
|
{...props}
|
|
337
371
|
>
|
|
338
|
-
{
|
|
339
|
-
{avatar && (
|
|
340
|
-
<Avatar
|
|
341
|
-
className={`pf-chatbot__message-avatar ${hasRoundAvatar ? 'pf-chatbot__message-avatar--round' : ''} ${avatarClassName ? avatarClassName : ''}`}
|
|
342
|
-
src={avatar}
|
|
343
|
-
alt=""
|
|
344
|
-
{...avatarProps}
|
|
345
|
-
/>
|
|
346
|
-
)}
|
|
372
|
+
{_avatar && _avatar}
|
|
347
373
|
<div className="pf-chatbot__message-contents">
|
|
348
374
|
{isMetadataVisible && (
|
|
349
375
|
<div className="pf-chatbot__message-meta">
|