@patternfly/chatbot 6.3.0-prerelease.7 → 6.3.0-prerelease.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/Chatbot/Chatbot.test.js +4 -0
  2. package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +1 -1
  3. package/dist/cjs/ChatbotFooter/ChatbotFooter.d.ts +1 -0
  4. package/dist/cjs/ChatbotFooter/ChatbotFooter.js +2 -2
  5. package/dist/cjs/ChatbotFooter/ChatbotFooter.test.d.ts +1 -1
  6. package/dist/cjs/ChatbotFooter/ChatbotFooter.test.js +5 -0
  7. package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.d.ts +3 -2
  8. package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.js +20 -6
  9. package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.test.d.ts +1 -1
  10. package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.test.js +5 -0
  11. package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.d.ts +1 -0
  12. package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.js +3 -3
  13. package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.d.ts +1 -1
  14. package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.js +5 -0
  15. package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.d.ts +1 -0
  16. package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.js +2 -2
  17. package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.d.ts +1 -1
  18. package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.js +5 -0
  19. package/dist/cjs/ChatbotPopover/ChatbotPopover.js +1 -1
  20. package/dist/cjs/ChatbotWelcomePrompt/ChatbotWelcomePrompt.d.ts +1 -0
  21. package/dist/cjs/ChatbotWelcomePrompt/ChatbotWelcomePrompt.js +3 -3
  22. package/dist/cjs/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.js +4 -0
  23. package/dist/cjs/MessageBar/AttachButton.d.ts +1 -0
  24. package/dist/cjs/MessageBar/AttachButton.js +3 -3
  25. package/dist/cjs/MessageBar/AttachButton.test.js +4 -0
  26. package/dist/cjs/MessageBar/MessageBar.d.ts +1 -0
  27. package/dist/cjs/MessageBar/MessageBar.js +13 -12
  28. package/dist/cjs/MessageBar/MicrophoneButton.d.ts +1 -0
  29. package/dist/cjs/MessageBar/MicrophoneButton.js +3 -3
  30. package/dist/cjs/MessageBar/SendButton.d.ts +1 -0
  31. package/dist/cjs/MessageBar/SendButton.js +3 -3
  32. package/dist/cjs/MessageBar/SendButton.test.js +4 -0
  33. package/dist/cjs/MessageBar/StopButton.d.ts +1 -0
  34. package/dist/cjs/MessageBar/StopButton.js +3 -3
  35. package/dist/cjs/MessageBar/StopButton.test.js +4 -0
  36. package/dist/cjs/MessageBox/MessageBox.js +14 -2
  37. package/dist/css/main.css +128 -2
  38. package/dist/css/main.css.map +1 -1
  39. package/dist/esm/Chatbot/Chatbot.test.js +4 -0
  40. package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +1 -1
  41. package/dist/esm/ChatbotFooter/ChatbotFooter.d.ts +1 -0
  42. package/dist/esm/ChatbotFooter/ChatbotFooter.js +2 -2
  43. package/dist/esm/ChatbotFooter/ChatbotFooter.test.d.ts +1 -1
  44. package/dist/esm/ChatbotFooter/ChatbotFooter.test.js +5 -0
  45. package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.d.ts +3 -2
  46. package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.js +20 -6
  47. package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.test.d.ts +1 -1
  48. package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.test.js +5 -0
  49. package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.d.ts +1 -0
  50. package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.js +3 -3
  51. package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.d.ts +1 -1
  52. package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.js +5 -0
  53. package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.d.ts +1 -0
  54. package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.js +2 -2
  55. package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.d.ts +1 -1
  56. package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.js +5 -0
  57. package/dist/esm/ChatbotPopover/ChatbotPopover.js +1 -1
  58. package/dist/esm/ChatbotWelcomePrompt/ChatbotWelcomePrompt.d.ts +1 -0
  59. package/dist/esm/ChatbotWelcomePrompt/ChatbotWelcomePrompt.js +3 -3
  60. package/dist/esm/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.js +4 -0
  61. package/dist/esm/MessageBar/AttachButton.d.ts +1 -0
  62. package/dist/esm/MessageBar/AttachButton.js +3 -3
  63. package/dist/esm/MessageBar/AttachButton.test.js +4 -0
  64. package/dist/esm/MessageBar/MessageBar.d.ts +1 -0
  65. package/dist/esm/MessageBar/MessageBar.js +13 -12
  66. package/dist/esm/MessageBar/MicrophoneButton.d.ts +1 -0
  67. package/dist/esm/MessageBar/MicrophoneButton.js +3 -3
  68. package/dist/esm/MessageBar/SendButton.d.ts +1 -0
  69. package/dist/esm/MessageBar/SendButton.js +3 -3
  70. package/dist/esm/MessageBar/SendButton.test.js +4 -0
  71. package/dist/esm/MessageBar/StopButton.d.ts +1 -0
  72. package/dist/esm/MessageBar/StopButton.js +3 -3
  73. package/dist/esm/MessageBar/StopButton.test.js +4 -0
  74. package/dist/esm/MessageBox/MessageBox.js +14 -2
  75. package/package.json +1 -1
  76. package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +8 -1
  77. package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotCompact.tsx +481 -0
  78. package/src/Chatbot/Chatbot.test.tsx +9 -0
  79. package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +10 -1
  80. package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +5 -1
  81. package/src/ChatbotFooter/ChatbotFooter.scss +5 -0
  82. package/src/ChatbotFooter/ChatbotFooter.test.tsx +10 -0
  83. package/src/ChatbotFooter/ChatbotFooter.tsx +3 -1
  84. package/src/ChatbotHeader/ChatbotHeader.scss +17 -0
  85. package/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx +8 -0
  86. package/src/ChatbotHeader/ChatbotHeaderMenu.tsx +10 -5
  87. package/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx +6 -0
  88. package/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.tsx +5 -2
  89. package/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx +10 -0
  90. package/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.tsx +4 -0
  91. package/src/ChatbotPopover/ChatbotPopover.scss +9 -5
  92. package/src/ChatbotPopover/ChatbotPopover.tsx +1 -1
  93. package/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.scss +9 -1
  94. package/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.tsx +13 -0
  95. package/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.tsx +13 -2
  96. package/src/ChatbotWelcomePrompt/__snapshots__/ChatbotWelcomePrompt.test.tsx.snap +1 -1
  97. package/src/Message/Message.scss +27 -0
  98. package/src/Message/TextMessage/TextMessage.scss +25 -0
  99. package/src/MessageBar/AttachButton.scss +10 -0
  100. package/src/MessageBar/AttachButton.test.tsx +4 -0
  101. package/src/MessageBar/AttachButton.tsx +5 -2
  102. package/src/MessageBar/MessageBar.scss +17 -0
  103. package/src/MessageBar/MessageBar.tsx +15 -6
  104. package/src/MessageBar/MicrophoneButton.scss +10 -0
  105. package/src/MessageBar/MicrophoneButton.tsx +5 -2
  106. package/src/MessageBar/SendButton.scss +10 -0
  107. package/src/MessageBar/SendButton.test.tsx +5 -1
  108. package/src/MessageBar/SendButton.tsx +5 -2
  109. package/src/MessageBar/StopButton.scss +10 -0
  110. package/src/MessageBar/StopButton.test.tsx +5 -1
  111. package/src/MessageBar/StopButton.tsx +5 -2
  112. package/src/MessageBox/MessageBox.scss +6 -0
  113. package/src/MessageBox/MessageBox.tsx +3 -1
@@ -0,0 +1,481 @@
1
+ import React from 'react';
2
+
3
+ import { Bullseye, Brand, DropdownList, DropdownItem, DropdownGroup, SkipToContent } from '@patternfly/react-core';
4
+
5
+ import ChatbotToggle from '@patternfly/chatbot/dist/dynamic/ChatbotToggle';
6
+ import Chatbot, { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot';
7
+ import ChatbotContent from '@patternfly/chatbot/dist/dynamic/ChatbotContent';
8
+ import ChatbotWelcomePrompt from '@patternfly/chatbot/dist/dynamic/ChatbotWelcomePrompt';
9
+ import ChatbotFooter, { ChatbotFootnote } from '@patternfly/chatbot/dist/dynamic/ChatbotFooter';
10
+ import MessageBar from '@patternfly/chatbot/dist/dynamic/MessageBar';
11
+ import MessageBox from '@patternfly/chatbot/dist/dynamic/MessageBox';
12
+ import Message, { MessageProps } from '@patternfly/chatbot/dist/dynamic/Message';
13
+ import ChatbotConversationHistoryNav, {
14
+ Conversation
15
+ } from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
16
+ import ChatbotHeader, {
17
+ ChatbotHeaderMenu,
18
+ ChatbotHeaderMain,
19
+ ChatbotHeaderTitle,
20
+ ChatbotHeaderActions,
21
+ ChatbotHeaderSelectorDropdown,
22
+ ChatbotHeaderOptionsDropdown
23
+ } from '@patternfly/chatbot/dist/dynamic/ChatbotHeader';
24
+
25
+ import ExpandIcon from '@patternfly/react-icons/dist/esm/icons/expand-icon';
26
+ import OpenDrawerRightIcon from '@patternfly/react-icons/dist/esm/icons/open-drawer-right-icon';
27
+ import OutlinedWindowRestoreIcon from '@patternfly/react-icons/dist/esm/icons/outlined-window-restore-icon';
28
+
29
+ import PFHorizontalLogoColor from '../UI/PF-HorizontalLogo-Color.svg';
30
+ import PFHorizontalLogoReverse from '../UI/PF-HorizontalLogo-Reverse.svg';
31
+ import PFIconLogoColor from '../UI/PF-IconLogo-Color.svg';
32
+ import PFIconLogoReverse from '../UI/PF-IconLogo-Reverse.svg';
33
+ import userAvatar from '../Messages/user_avatar.svg';
34
+ import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
35
+
36
+ const footnoteProps = {
37
+ label: 'ChatBot uses AI. Check for mistakes.',
38
+ popover: {
39
+ title: 'Verify information',
40
+ description: `While ChatBot strives for accuracy, AI is experimental and can make mistakes. We cannot guarantee that all information provided by ChatBot is up to date or without error. You should always verify responses using reliable sources, especially for crucial information and decision making.`,
41
+ bannerImage: {
42
+ src: 'https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif',
43
+ alt: 'Example image for footnote popover'
44
+ },
45
+ cta: {
46
+ label: 'Dismiss',
47
+ onClick: () => {
48
+ alert('Do something!');
49
+ }
50
+ },
51
+ link: {
52
+ label: 'View AI policy',
53
+ url: 'https://www.redhat.com/'
54
+ }
55
+ }
56
+ };
57
+
58
+ const markdown = `A paragraph with *emphasis* and **strong importance**.
59
+
60
+ > A block quote with ~strikethrough~ and a URL: https://reactjs.org.
61
+
62
+ Here is an inline code - \`() => void\`
63
+
64
+ Here is some YAML code:
65
+
66
+ ~~~yaml
67
+ apiVersion: helm.openshift.io/v1beta1/
68
+ kind: HelmChartRepository
69
+ metadata:
70
+ name: azure-sample-repo0oooo00ooo
71
+ spec:
72
+ connectionConfig:
73
+ url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs
74
+ ~~~
75
+
76
+ Here is some JavaScript code:
77
+
78
+ ~~~js
79
+ import React from 'react';
80
+
81
+ const MessageLoading = () => (
82
+ <div className="pf-chatbot__message-loading">
83
+ <span className="pf-chatbot__message-loading-dots">
84
+ <span className="pf-v6-screen-reader">Loading message</span>
85
+ </span>
86
+ </div>
87
+ );
88
+
89
+ export default MessageLoading;
90
+
91
+ ~~~
92
+ `;
93
+
94
+ // It's important to set a date and timestamp prop since the Message components re-render.
95
+ // The timestamps re-render with them.
96
+ const date = new Date();
97
+
98
+ const initialMessages: MessageProps[] = [
99
+ {
100
+ id: '1',
101
+ role: 'user',
102
+ content: 'Hello, can you give me an example of what you can do?',
103
+ name: 'User',
104
+ avatar: userAvatar,
105
+ timestamp: date.toLocaleString(),
106
+ avatarProps: { isBordered: true }
107
+ },
108
+ {
109
+ id: '2',
110
+ role: 'bot',
111
+ content: markdown,
112
+ name: 'Bot',
113
+ avatar: patternflyAvatar,
114
+ timestamp: date.toLocaleString(),
115
+ actions: {
116
+ // eslint-disable-next-line no-console
117
+ positive: { onClick: () => console.log('Good response') },
118
+ // eslint-disable-next-line no-console
119
+ negative: { onClick: () => console.log('Bad response') },
120
+ // eslint-disable-next-line no-console
121
+ copy: { onClick: () => console.log('Copy') },
122
+ // eslint-disable-next-line no-console
123
+ share: { onClick: () => console.log('Share') },
124
+ // eslint-disable-next-line no-console
125
+ listen: { onClick: () => console.log('Listen') }
126
+ }
127
+ }
128
+ ];
129
+
130
+ const welcomePrompts = [
131
+ {
132
+ title: 'Set up account',
133
+ message: 'Choose the necessary settings and preferences for your account.'
134
+ },
135
+ {
136
+ title: 'Troubleshoot issue',
137
+ message: 'Find documentation and instructions to resolve your issue.'
138
+ }
139
+ ];
140
+
141
+ const initialConversations = {
142
+ Today: [{ id: '1', text: 'Hello, can you give me an example of what you can do?' }],
143
+ 'This month': [
144
+ {
145
+ id: '2',
146
+ text: 'Enterprise Linux installation and setup'
147
+ },
148
+ { id: '3', text: 'Troubleshoot system crash' }
149
+ ],
150
+ March: [
151
+ { id: '4', text: 'Ansible security and updates' },
152
+ { id: '5', text: 'Red Hat certification' },
153
+ { id: '6', text: 'Lightspeed user documentation' }
154
+ ],
155
+ February: [
156
+ { id: '7', text: 'Crashing pod assistance' },
157
+ { id: '8', text: 'OpenShift AI pipelines' },
158
+ { id: '9', text: 'Updating subscription plan' },
159
+ { id: '10', text: 'Red Hat licensing options' }
160
+ ],
161
+ January: [
162
+ { id: '11', text: 'RHEL system performance' },
163
+ { id: '12', text: 'Manage user accounts' }
164
+ ]
165
+ };
166
+
167
+ export const ChatbotDemo: React.FunctionComponent = () => {
168
+ const [chatbotVisible, setChatbotVisible] = React.useState<boolean>(true);
169
+ const [displayMode, setDisplayMode] = React.useState<ChatbotDisplayMode>(ChatbotDisplayMode.default);
170
+ const [messages, setMessages] = React.useState<MessageProps[]>(initialMessages);
171
+ const [selectedModel, setSelectedModel] = React.useState('Granite 7B');
172
+ const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(false);
173
+ const [isDrawerOpen, setIsDrawerOpen] = React.useState(false);
174
+ const [conversations, setConversations] = React.useState<Conversation[] | { [key: string]: Conversation[] }>(
175
+ initialConversations
176
+ );
177
+ const [announcement, setAnnouncement] = React.useState<string>();
178
+ const scrollToBottomRef = React.useRef<HTMLDivElement>(null);
179
+ const toggleRef = React.useRef<HTMLButtonElement>(null);
180
+ const chatbotRef = React.useRef<HTMLDivElement>(null);
181
+ const historyRef = React.useRef<HTMLButtonElement>(null);
182
+
183
+ // Auto-scrolls to the latest message
184
+ React.useEffect(() => {
185
+ // don't scroll the first load - in this demo, we know we start with two messages
186
+ if (messages.length > 2) {
187
+ scrollToBottomRef.current?.scrollIntoView({ behavior: 'smooth' });
188
+ }
189
+ }, [messages]);
190
+
191
+ const onSelectModel = (
192
+ _event: React.MouseEvent<Element, MouseEvent> | undefined,
193
+ value: string | number | undefined
194
+ ) => {
195
+ setSelectedModel(value as string);
196
+ };
197
+
198
+ const onSelectDisplayMode = (
199
+ _event: React.MouseEvent<Element, MouseEvent> | undefined,
200
+ value: string | number | undefined
201
+ ) => {
202
+ setDisplayMode(value as ChatbotDisplayMode);
203
+ };
204
+
205
+ // you will likely want to come up with your own unique id function; this is for demo purposes only
206
+ const generateId = () => {
207
+ const id = Date.now() + Math.random();
208
+ return id.toString();
209
+ };
210
+
211
+ const handleSend = (message: string) => {
212
+ setIsSendButtonDisabled(true);
213
+ const newMessages: MessageProps[] = [];
214
+ // We can't use structuredClone since messages contains functions, but we can't mutate
215
+ // items that are going into state or the UI won't update correctly
216
+ messages.forEach((message) => newMessages.push(message));
217
+ // It's important to set a timestamp prop since the Message components re-render.
218
+ // The timestamps re-render with them.
219
+ const date = new Date();
220
+ newMessages.push({
221
+ id: generateId(),
222
+ role: 'user',
223
+ content: message,
224
+ name: 'User',
225
+ avatar: userAvatar,
226
+ timestamp: date.toLocaleString(),
227
+ avatarProps: { isBordered: true }
228
+ });
229
+ newMessages.push({
230
+ id: generateId(),
231
+ role: 'bot',
232
+ content: 'API response goes here',
233
+ name: 'Bot',
234
+ isLoading: true,
235
+ avatar: patternflyAvatar,
236
+ timestamp: date.toLocaleString()
237
+ });
238
+ setMessages(newMessages);
239
+ // make announcement to assistive devices that new messages have been added
240
+ setAnnouncement(`Message from User: ${message}. Message from Bot is loading.`);
241
+
242
+ // this is for demo purposes only; in a real situation, there would be an API response we would wait for
243
+ setTimeout(() => {
244
+ const loadedMessages: MessageProps[] = [];
245
+ // We can't use structuredClone since messages contains functions, but we can't mutate
246
+ // items that are going into state or the UI won't update correctly
247
+ newMessages.forEach((message) => loadedMessages.push(message));
248
+ loadedMessages.pop();
249
+ loadedMessages.push({
250
+ id: generateId(),
251
+ role: 'bot',
252
+ content: 'API response goes here',
253
+ name: 'Bot',
254
+ isLoading: false,
255
+ avatar: patternflyAvatar,
256
+ timestamp: date.toLocaleString(),
257
+ actions: {
258
+ // eslint-disable-next-line no-console
259
+ positive: { onClick: () => console.log('Good response') },
260
+ // eslint-disable-next-line no-console
261
+ negative: { onClick: () => console.log('Bad response') },
262
+ // eslint-disable-next-line no-console
263
+ copy: { onClick: () => console.log('Copy') },
264
+ // eslint-disable-next-line no-console
265
+ share: { onClick: () => console.log('Share') },
266
+ // eslint-disable-next-line no-console
267
+ listen: { onClick: () => console.log('Listen') }
268
+ }
269
+ });
270
+ setMessages(loadedMessages);
271
+ // make announcement to assistive devices that new message has loaded
272
+ setAnnouncement(`Message from Bot: API response goes here`);
273
+ setIsSendButtonDisabled(false);
274
+ }, 5000);
275
+ };
276
+
277
+ const findMatchingItems = (targetValue: string) => {
278
+ let filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => {
279
+ const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase()));
280
+ if (filteredItems.length > 0) {
281
+ acc[key] = filteredItems;
282
+ }
283
+ return acc;
284
+ }, {});
285
+
286
+ // append message if no items are found
287
+ if (Object.keys(filteredConversations).length === 0) {
288
+ filteredConversations = [{ id: '13', noIcon: true, text: 'No results found' }];
289
+ }
290
+ return filteredConversations;
291
+ };
292
+
293
+ const horizontalLogo = (
294
+ <Bullseye>
295
+ <Brand className="show-light" src={PFHorizontalLogoColor} alt="PatternFly" />
296
+ <Brand className="show-dark" src={PFHorizontalLogoReverse} alt="PatternFly" />
297
+ </Bullseye>
298
+ );
299
+
300
+ const iconLogo = (
301
+ <>
302
+ <Brand className="show-light" src={PFIconLogoColor} alt="PatternFly" />
303
+ <Brand className="show-dark" src={PFIconLogoReverse} alt="PatternFly" />
304
+ </>
305
+ );
306
+
307
+ const handleSkipToContent = (e) => {
308
+ e.preventDefault();
309
+ /* eslint-disable indent */
310
+ switch (displayMode) {
311
+ case ChatbotDisplayMode.default:
312
+ if (!chatbotVisible && toggleRef.current) {
313
+ toggleRef.current.focus();
314
+ }
315
+ if (chatbotVisible && chatbotRef.current) {
316
+ chatbotRef.current.focus();
317
+ }
318
+ break;
319
+
320
+ case ChatbotDisplayMode.docked:
321
+ if (chatbotRef.current) {
322
+ chatbotRef.current.focus();
323
+ }
324
+ break;
325
+ default:
326
+ if (historyRef.current) {
327
+ historyRef.current.focus();
328
+ }
329
+ break;
330
+ }
331
+ /* eslint-enable indent */
332
+ };
333
+
334
+ return (
335
+ <>
336
+ <SkipToContent onClick={handleSkipToContent} href="#">
337
+ Skip to chatbot
338
+ </SkipToContent>
339
+ <ChatbotToggle
340
+ tooltipLabel="Chatbot"
341
+ isChatbotVisible={chatbotVisible}
342
+ onToggleChatbot={function () {
343
+ setChatbotVisible(!chatbotVisible);
344
+ }}
345
+ id="chatbot-toggle"
346
+ ref={toggleRef}
347
+ />
348
+ <Chatbot isCompact isVisible={chatbotVisible} displayMode={displayMode} ref={chatbotRef}>
349
+ <ChatbotConversationHistoryNav
350
+ displayMode={displayMode}
351
+ onDrawerToggle={() => {
352
+ setIsDrawerOpen(!isDrawerOpen);
353
+ setConversations(initialConversations);
354
+ }}
355
+ isDrawerOpen={isDrawerOpen}
356
+ setIsDrawerOpen={setIsDrawerOpen}
357
+ activeItemId="1"
358
+ // eslint-disable-next-line no-console
359
+ onSelectActiveItem={(e, selectedItem) => console.log(`Selected history item with id ${selectedItem}`)}
360
+ conversations={conversations}
361
+ onNewChat={() => {
362
+ setIsDrawerOpen(!isDrawerOpen);
363
+ setMessages([]);
364
+ setConversations(initialConversations);
365
+ }}
366
+ handleTextInputChange={(value: string) => {
367
+ if (value === '') {
368
+ setConversations(initialConversations);
369
+ }
370
+ // this is where you would perform search on the items in the drawer
371
+ // and update the state
372
+ const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value);
373
+ setConversations(newConversations);
374
+ }}
375
+ isCompact
376
+ drawerContent={
377
+ <>
378
+ <ChatbotHeader>
379
+ <ChatbotHeaderMain>
380
+ <ChatbotHeaderMenu
381
+ ref={historyRef}
382
+ aria-expanded={isDrawerOpen}
383
+ onMenuToggle={() => setIsDrawerOpen(!isDrawerOpen)}
384
+ isCompact
385
+ />
386
+ <ChatbotHeaderTitle
387
+ displayMode={displayMode}
388
+ showOnFullScreen={horizontalLogo}
389
+ showOnDefault={iconLogo}
390
+ ></ChatbotHeaderTitle>
391
+ </ChatbotHeaderMain>
392
+ <ChatbotHeaderActions>
393
+ <ChatbotHeaderSelectorDropdown value={selectedModel} onSelect={onSelectModel} isCompact>
394
+ <DropdownList>
395
+ <DropdownItem value="Granite 7B" key="granite">
396
+ Granite 7B
397
+ </DropdownItem>
398
+ <DropdownItem value="Llama 3.0" key="llama">
399
+ Llama 3.0
400
+ </DropdownItem>
401
+ <DropdownItem value="Mistral 3B" key="mistral">
402
+ Mistral 3B
403
+ </DropdownItem>
404
+ </DropdownList>
405
+ </ChatbotHeaderSelectorDropdown>
406
+ <ChatbotHeaderOptionsDropdown onSelect={onSelectDisplayMode} isCompact>
407
+ <DropdownGroup label="Display mode">
408
+ <DropdownList>
409
+ <DropdownItem
410
+ value={ChatbotDisplayMode.default}
411
+ key="switchDisplayOverlay"
412
+ icon={<OutlinedWindowRestoreIcon aria-hidden />}
413
+ isSelected={displayMode === ChatbotDisplayMode.default}
414
+ >
415
+ <span>Overlay</span>
416
+ </DropdownItem>
417
+ <DropdownItem
418
+ value={ChatbotDisplayMode.docked}
419
+ key="switchDisplayDock"
420
+ icon={<OpenDrawerRightIcon aria-hidden />}
421
+ isSelected={displayMode === ChatbotDisplayMode.docked}
422
+ >
423
+ <span>Dock to window</span>
424
+ </DropdownItem>
425
+ <DropdownItem
426
+ value={ChatbotDisplayMode.fullscreen}
427
+ key="switchDisplayFullscreen"
428
+ icon={<ExpandIcon aria-hidden />}
429
+ isSelected={displayMode === ChatbotDisplayMode.fullscreen}
430
+ >
431
+ <span>Fullscreen</span>
432
+ </DropdownItem>
433
+ </DropdownList>
434
+ </DropdownGroup>
435
+ </ChatbotHeaderOptionsDropdown>
436
+ </ChatbotHeaderActions>
437
+ </ChatbotHeader>
438
+ <ChatbotContent>
439
+ {/* Update the announcement prop on MessageBox whenever a new message is sent
440
+ so that users of assistive devices receive sufficient context */}
441
+ <MessageBox announcement={announcement}>
442
+ <ChatbotWelcomePrompt
443
+ title="Hi, ChatBot User!"
444
+ description="How can I help you today?"
445
+ prompts={welcomePrompts}
446
+ isCompact
447
+ />
448
+ {/* This code block enables scrolling to the top of the last message.
449
+ You can instead choose to move the div with scrollToBottomRef on it below
450
+ the map of messages, so that users are forced to scroll to the bottom.
451
+ If you are using streaming, you will want to take a different approach;
452
+ see: https://github.com/patternfly/chatbot/issues/201#issuecomment-2400725173 */}
453
+ {messages.map((message, index) => {
454
+ if (index === messages.length - 1) {
455
+ return (
456
+ <>
457
+ <div ref={scrollToBottomRef}></div>
458
+ <Message key={message.id} {...message} />
459
+ </>
460
+ );
461
+ }
462
+ return <Message key={message.id} {...message} />;
463
+ })}
464
+ </MessageBox>
465
+ </ChatbotContent>
466
+ <ChatbotFooter isCompact>
467
+ <MessageBar
468
+ onSendMessage={handleSend}
469
+ hasMicrophoneButton
470
+ isSendButtonDisabled={isSendButtonDisabled}
471
+ isCompact
472
+ />
473
+ <ChatbotFootnote {...footnoteProps} />
474
+ </ChatbotFooter>
475
+ </>
476
+ }
477
+ ></ChatbotConversationHistoryNav>
478
+ </Chatbot>
479
+ </>
480
+ );
481
+ };
@@ -28,4 +28,13 @@ describe('Chatbot', () => {
28
28
  render(<Chatbot isVisible={false}>Chatbot Content</Chatbot>);
29
29
  expect(screen.queryByLabelText('Chatbot')).toBeFalsy();
30
30
  });
31
+
32
+ it('should handle isCompact', () => {
33
+ render(
34
+ <Chatbot data-testid="chatbot" isVisible={true} isCompact>
35
+ Chatbot Content
36
+ </Chatbot>
37
+ );
38
+ expect(screen.getByTestId('chatbot')).toHaveClass('pf-m-compact');
39
+ });
31
40
  });
@@ -118,7 +118,6 @@
118
118
  border-radius: var(--pf-t--global--border--radius--pill);
119
119
  justify-content: center;
120
120
  align-items: center;
121
- border-radius: var(--pf-t--global--border--radius--small);
122
121
  }
123
122
  }
124
123
 
@@ -230,4 +229,14 @@
230
229
  --pf-v6-c-drawer__head--PaddingInlineStart: var(--pf-t--global--spacer--lg);
231
230
  --pf-v6-c-drawer__head--PaddingInlineEnd: var(--pf-t--global--spacer--lg);
232
231
  }
232
+ .pf-v6-c-drawer__close {
233
+ .pf-v6-c-button {
234
+ width: 2rem;
235
+ height: 2rem;
236
+ --pf-v6-c-button--m-plain--PaddingInlineEnd: var(--pf-t--global--spacer--xs);
237
+ --pf-v6-c-button--m-plain--PaddingInlineStart: var(--pf-t--global--spacer--xs);
238
+ --pf-v6-c-button--PaddingBlockStart: var(--pf-t--global--spacer--xs);
239
+ --pf-v6-c-button--PaddingBlockEnd: var(--pf-t--global--spacer--xs);
240
+ }
241
+ }
233
242
  }
@@ -259,7 +259,11 @@ export const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConve
259
259
  {...drawerActionsProps}
260
260
  >
261
261
  <DrawerCloseButton onClick={onDrawerToggle} {...drawerCloseButtonProps} />
262
- {onNewChat && <Button onClick={onNewChat}>{newChatButtonText}</Button>}
262
+ {onNewChat && (
263
+ <Button size={isCompact ? 'sm' : undefined} onClick={onNewChat}>
264
+ {newChatButtonText}
265
+ </Button>
266
+ )}
263
267
  </DrawerActions>
264
268
  </DrawerHead>
265
269
  {isLoading ? <LoadingState {...loadingState} /> : renderDrawerContent()}
@@ -57,3 +57,8 @@
57
57
  padding: var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--lg);
58
58
  }
59
59
  }
60
+
61
+ .pf-chatbot__footer.pf-m-compact .pf-chatbot__footer-container {
62
+ padding: 0 var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--sm);
63
+ row-gap: var(--pf-t--global--spacer--sm);
64
+ }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
3
  import ChatbotFooter from './ChatbotFooter';
4
+ import '@testing-library/jest-dom';
4
5
 
5
6
  describe('ChatbotFooter', () => {
6
7
  it('should render ChatbotFooter with children', () => {
@@ -12,4 +13,13 @@ describe('ChatbotFooter', () => {
12
13
  const { container } = render(<ChatbotFooter className="custom-class">Chatbot Content</ChatbotFooter>);
13
14
  expect(container.querySelector('.custom-class')).toBeTruthy();
14
15
  });
16
+
17
+ it('should handle isCompact', () => {
18
+ render(
19
+ <ChatbotFooter className="custom-class" isCompact data-testid="footer">
20
+ Chatbot Content
21
+ </ChatbotFooter>
22
+ );
23
+ expect(screen.getByTestId('footer')).toHaveClass('pf-m-compact');
24
+ });
15
25
  });
@@ -17,14 +17,16 @@ export interface ChatbotFooterProps extends React.HTMLProps<HTMLDivElement> {
17
17
  children?: React.ReactNode;
18
18
  /** Custom classname for the Footer component */
19
19
  className?: string;
20
+ isCompact?: boolean;
20
21
  }
21
22
 
22
23
  export const ChatbotFooter: React.FunctionComponent<ChatbotFooterProps> = ({
23
24
  children,
24
25
  className,
26
+ isCompact,
25
27
  ...props
26
28
  }: ChatbotFooterProps) => (
27
- <div className={`pf-chatbot__footer ${className ?? ''}`} {...props}>
29
+ <div className={`pf-chatbot__footer ${isCompact ? 'pf-m-compact' : ''} ${className ?? ''}`} {...props}>
28
30
  <Divider />
29
31
  <div className="pf-chatbot__footer-container">{children}</div>
30
32
  </div>
@@ -141,7 +141,24 @@
141
141
  // ============================================================================
142
142
  // Information density styles
143
143
  // ============================================================================
144
+ .pf-chatbot.pf-m-compact {
145
+ .pf-chatbot__header {
146
+ gap: var(--pf-t--global--spacer--sm);
147
+ padding: var(--pf-t--global--spacer--sm);
148
+ }
149
+
150
+ .pf-chatbot__header .pf-chatbot__title img {
151
+ max-height: 24px;
152
+ vertical-align: middle;
153
+ }
154
+ }
155
+
156
+ .pf-v6-c-menu-toggle.pf-chatbot__button--toggle-options.pf-m-compact,
144
157
  .pf-chatbot__button--toggle-menu.pf-m-compact {
145
158
  width: 2rem;
146
159
  height: 2rem;
147
160
  }
161
+
162
+ .pf-chatbot__header .pf-chatbot__actions .pf-v6-c-menu-toggle.pf-m-secondary.pf-m-compact {
163
+ width: initial;
164
+ }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { fireEvent, render, screen } from '@testing-library/react';
3
3
  import { ChatbotHeaderMenu } from './ChatbotHeaderMenu';
4
+ import '@testing-library/jest-dom';
4
5
 
5
6
  describe('ChatbotHeaderMenu', () => {
6
7
  it('should render ChatbotHeaderMenu with custom class', () => {
@@ -16,4 +17,11 @@ describe('ChatbotHeaderMenu', () => {
16
17
 
17
18
  expect(onMenuToggle).toHaveBeenCalled();
18
19
  });
20
+
21
+ it('should handle isCompact', () => {
22
+ render(
23
+ <ChatbotHeaderMenu className="custom-header-menu" onMenuToggle={jest.fn()} isCompact data-testid="button" />
24
+ );
25
+ expect(screen.getByTestId('button')).toHaveClass('pf-m-compact');
26
+ });
19
27
  });
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { Button, Icon, Tooltip, TooltipProps } from '@patternfly/react-core';
3
+ import { Button, ButtonProps, Icon, Tooltip, TooltipProps } from '@patternfly/react-core';
4
4
  import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon';
5
5
 
6
- export interface ChatbotHeaderMenuProps {
6
+ export interface ChatbotHeaderMenuProps extends ButtonProps {
7
7
  /** Callback function to attach to menu toggle on top right of chatbot header. */
8
8
  onMenuToggle: () => void;
9
9
  /** Custom classname for the header component */
@@ -16,6 +16,7 @@ export interface ChatbotHeaderMenuProps {
16
16
  innerRef?: React.Ref<HTMLButtonElement>;
17
17
  /** Content used in tooltip */
18
18
  tooltipContent?: string;
19
+ isCompact?: boolean;
19
20
  }
20
21
 
21
22
  const ChatbotHeaderMenuBase: React.FunctionComponent<ChatbotHeaderMenuProps> = ({
@@ -24,7 +25,9 @@ const ChatbotHeaderMenuBase: React.FunctionComponent<ChatbotHeaderMenuProps> = (
24
25
  tooltipProps,
25
26
  menuAriaLabel = 'Toggle menu',
26
27
  innerRef,
27
- tooltipContent = 'Menu'
28
+ tooltipContent = 'Menu',
29
+ isCompact,
30
+ ...props
28
31
  }: ChatbotHeaderMenuProps) => (
29
32
  <div className={`pf-chatbot__menu ${className}`}>
30
33
  <Tooltip
@@ -35,16 +38,18 @@ const ChatbotHeaderMenuBase: React.FunctionComponent<ChatbotHeaderMenuProps> = (
35
38
  {...tooltipProps}
36
39
  >
37
40
  <Button
38
- className="pf-chatbot__button--toggle-menu"
41
+ className={`pf-chatbot__button--toggle-menu ${isCompact ? 'pf-m-compact' : ''}`}
39
42
  variant="plain"
40
43
  onClick={onMenuToggle}
41
44
  aria-label={menuAriaLabel}
42
45
  ref={innerRef}
43
46
  icon={
44
- <Icon size="xl" isInline>
47
+ <Icon size={isCompact ? 'lg' : 'xl'} isInline>
45
48
  <BarsIcon />
46
49
  </Icon>
47
50
  }
51
+ size={isCompact ? 'sm' : undefined}
52
+ {...props}
48
53
  />
49
54
  </Tooltip>
50
55
  </div>