diff --git a/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md b/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md index 21dc1625c..73a6789bf 100644 --- a/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +++ b/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md @@ -59,7 +59,6 @@ import userAvatar from '../Messages/user_avatar.svg'; import patternflyAvatar from '../Messages/patternfly_avatar.jpg'; import { getTrackingProviders } from "@patternfly/chatbot/dist/dynamic/tracking"; - ### Basic ChatBot This demo displays a basic ChatBot, which includes: @@ -87,6 +86,14 @@ This demo displays a basic ChatBot, which includes: ``` +### Compact ChatBot + +This demo displays a basic compact ChatBot + +```js file="./ChatbotCompact.tsx" isFullscreen + +``` + ### Embedded ChatBot This demo displays an embedded ChatBot. Embedded ChatBots are meant to be placed within a page in your product. This demo includes: diff --git a/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotCompact.tsx b/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotCompact.tsx new file mode 100644 index 000000000..60ce55c04 --- /dev/null +++ b/packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotCompact.tsx @@ -0,0 +1,481 @@ +import React from 'react'; + +import { Bullseye, Brand, DropdownList, DropdownItem, DropdownGroup, SkipToContent } from '@patternfly/react-core'; + +import ChatbotToggle from '@patternfly/chatbot/dist/dynamic/ChatbotToggle'; +import Chatbot, { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot'; +import ChatbotContent from '@patternfly/chatbot/dist/dynamic/ChatbotContent'; +import ChatbotWelcomePrompt from '@patternfly/chatbot/dist/dynamic/ChatbotWelcomePrompt'; +import ChatbotFooter, { ChatbotFootnote } from '@patternfly/chatbot/dist/dynamic/ChatbotFooter'; +import MessageBar from '@patternfly/chatbot/dist/dynamic/MessageBar'; +import MessageBox from '@patternfly/chatbot/dist/dynamic/MessageBox'; +import Message, { MessageProps } from '@patternfly/chatbot/dist/dynamic/Message'; +import ChatbotConversationHistoryNav, { + Conversation +} from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav'; +import ChatbotHeader, { + ChatbotHeaderMenu, + ChatbotHeaderMain, + ChatbotHeaderTitle, + ChatbotHeaderActions, + ChatbotHeaderSelectorDropdown, + ChatbotHeaderOptionsDropdown +} from '@patternfly/chatbot/dist/dynamic/ChatbotHeader'; + +import ExpandIcon from '@patternfly/react-icons/dist/esm/icons/expand-icon'; +import OpenDrawerRightIcon from '@patternfly/react-icons/dist/esm/icons/open-drawer-right-icon'; +import OutlinedWindowRestoreIcon from '@patternfly/react-icons/dist/esm/icons/outlined-window-restore-icon'; + +import PFHorizontalLogoColor from '../UI/PF-HorizontalLogo-Color.svg'; +import PFHorizontalLogoReverse from '../UI/PF-HorizontalLogo-Reverse.svg'; +import PFIconLogoColor from '../UI/PF-IconLogo-Color.svg'; +import PFIconLogoReverse from '../UI/PF-IconLogo-Reverse.svg'; +import userAvatar from '../Messages/user_avatar.svg'; +import patternflyAvatar from '../Messages/patternfly_avatar.jpg'; + +const footnoteProps = { + label: 'ChatBot uses AI. Check for mistakes.', + popover: { + title: 'Verify information', + 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.`, + bannerImage: { + src: 'https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif', + alt: 'Example image for footnote popover' + }, + cta: { + label: 'Dismiss', + onClick: () => { + alert('Do something!'); + } + }, + link: { + label: 'View AI policy', + url: 'https://www.redhat.com/' + } + } +}; + +const markdown = `A paragraph with *emphasis* and **strong importance**. + +> A block quote with ~strikethrough~ and a URL: https://reactjs.org. + +Here is an inline code - \`() => void\` + +Here is some YAML code: + +~~~yaml +apiVersion: helm.openshift.io/v1beta1/ +kind: HelmChartRepository +metadata: + name: azure-sample-repo0oooo00ooo +spec: + connectionConfig: + url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs +~~~ + +Here is some JavaScript code: + +~~~js +import React from 'react'; + +const MessageLoading = () => ( +
+ + Loading message + +
+); + +export default MessageLoading; + +~~~ +`; + +// It's important to set a date and timestamp prop since the Message components re-render. +// The timestamps re-render with them. +const date = new Date(); + +const initialMessages: MessageProps[] = [ + { + id: '1', + role: 'user', + content: 'Hello, can you give me an example of what you can do?', + name: 'User', + avatar: userAvatar, + timestamp: date.toLocaleString(), + avatarProps: { isBordered: true } + }, + { + id: '2', + role: 'bot', + content: markdown, + name: 'Bot', + avatar: patternflyAvatar, + timestamp: date.toLocaleString(), + actions: { + // eslint-disable-next-line no-console + positive: { onClick: () => console.log('Good response') }, + // eslint-disable-next-line no-console + negative: { onClick: () => console.log('Bad response') }, + // eslint-disable-next-line no-console + copy: { onClick: () => console.log('Copy') }, + // eslint-disable-next-line no-console + share: { onClick: () => console.log('Share') }, + // eslint-disable-next-line no-console + listen: { onClick: () => console.log('Listen') } + } + } +]; + +const welcomePrompts = [ + { + title: 'Set up account', + message: 'Choose the necessary settings and preferences for your account.' + }, + { + title: 'Troubleshoot issue', + message: 'Find documentation and instructions to resolve your issue.' + } +]; + +const initialConversations = { + Today: [{ id: '1', text: 'Hello, can you give me an example of what you can do?' }], + 'This month': [ + { + id: '2', + text: 'Enterprise Linux installation and setup' + }, + { id: '3', text: 'Troubleshoot system crash' } + ], + March: [ + { id: '4', text: 'Ansible security and updates' }, + { id: '5', text: 'Red Hat certification' }, + { id: '6', text: 'Lightspeed user documentation' } + ], + February: [ + { id: '7', text: 'Crashing pod assistance' }, + { id: '8', text: 'OpenShift AI pipelines' }, + { id: '9', text: 'Updating subscription plan' }, + { id: '10', text: 'Red Hat licensing options' } + ], + January: [ + { id: '11', text: 'RHEL system performance' }, + { id: '12', text: 'Manage user accounts' } + ] +}; + +export const ChatbotDemo: React.FunctionComponent = () => { + const [chatbotVisible, setChatbotVisible] = React.useState(true); + const [displayMode, setDisplayMode] = React.useState(ChatbotDisplayMode.default); + const [messages, setMessages] = React.useState(initialMessages); + const [selectedModel, setSelectedModel] = React.useState('Granite 7B'); + const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(false); + const [isDrawerOpen, setIsDrawerOpen] = React.useState(false); + const [conversations, setConversations] = React.useState( + initialConversations + ); + const [announcement, setAnnouncement] = React.useState(); + const scrollToBottomRef = React.useRef(null); + const toggleRef = React.useRef(null); + const chatbotRef = React.useRef(null); + const historyRef = React.useRef(null); + + // Auto-scrolls to the latest message + React.useEffect(() => { + // don't scroll the first load - in this demo, we know we start with two messages + if (messages.length > 2) { + scrollToBottomRef.current?.scrollIntoView({ behavior: 'smooth' }); + } + }, [messages]); + + const onSelectModel = ( + _event: React.MouseEvent | undefined, + value: string | number | undefined + ) => { + setSelectedModel(value as string); + }; + + const onSelectDisplayMode = ( + _event: React.MouseEvent | undefined, + value: string | number | undefined + ) => { + setDisplayMode(value as ChatbotDisplayMode); + }; + + // you will likely want to come up with your own unique id function; this is for demo purposes only + const generateId = () => { + const id = Date.now() + Math.random(); + return id.toString(); + }; + + const handleSend = (message: string) => { + setIsSendButtonDisabled(true); + const newMessages: MessageProps[] = []; + // We can't use structuredClone since messages contains functions, but we can't mutate + // items that are going into state or the UI won't update correctly + messages.forEach((message) => newMessages.push(message)); + // It's important to set a timestamp prop since the Message components re-render. + // The timestamps re-render with them. + const date = new Date(); + newMessages.push({ + id: generateId(), + role: 'user', + content: message, + name: 'User', + avatar: userAvatar, + timestamp: date.toLocaleString(), + avatarProps: { isBordered: true } + }); + newMessages.push({ + id: generateId(), + role: 'bot', + content: 'API response goes here', + name: 'Bot', + isLoading: true, + avatar: patternflyAvatar, + timestamp: date.toLocaleString() + }); + setMessages(newMessages); + // make announcement to assistive devices that new messages have been added + setAnnouncement(`Message from User: ${message}. Message from Bot is loading.`); + + // this is for demo purposes only; in a real situation, there would be an API response we would wait for + setTimeout(() => { + const loadedMessages: MessageProps[] = []; + // We can't use structuredClone since messages contains functions, but we can't mutate + // items that are going into state or the UI won't update correctly + newMessages.forEach((message) => loadedMessages.push(message)); + loadedMessages.pop(); + loadedMessages.push({ + id: generateId(), + role: 'bot', + content: 'API response goes here', + name: 'Bot', + isLoading: false, + avatar: patternflyAvatar, + timestamp: date.toLocaleString(), + actions: { + // eslint-disable-next-line no-console + positive: { onClick: () => console.log('Good response') }, + // eslint-disable-next-line no-console + negative: { onClick: () => console.log('Bad response') }, + // eslint-disable-next-line no-console + copy: { onClick: () => console.log('Copy') }, + // eslint-disable-next-line no-console + share: { onClick: () => console.log('Share') }, + // eslint-disable-next-line no-console + listen: { onClick: () => console.log('Listen') } + } + }); + setMessages(loadedMessages); + // make announcement to assistive devices that new message has loaded + setAnnouncement(`Message from Bot: API response goes here`); + setIsSendButtonDisabled(false); + }, 5000); + }; + + const findMatchingItems = (targetValue: string) => { + let filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => { + const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase())); + if (filteredItems.length > 0) { + acc[key] = filteredItems; + } + return acc; + }, {}); + + // append message if no items are found + if (Object.keys(filteredConversations).length === 0) { + filteredConversations = [{ id: '13', noIcon: true, text: 'No results found' }]; + } + return filteredConversations; + }; + + const horizontalLogo = ( + + + + + ); + + const iconLogo = ( + <> + + + + ); + + const handleSkipToContent = (e) => { + e.preventDefault(); + /* eslint-disable indent */ + switch (displayMode) { + case ChatbotDisplayMode.default: + if (!chatbotVisible && toggleRef.current) { + toggleRef.current.focus(); + } + if (chatbotVisible && chatbotRef.current) { + chatbotRef.current.focus(); + } + break; + + case ChatbotDisplayMode.docked: + if (chatbotRef.current) { + chatbotRef.current.focus(); + } + break; + default: + if (historyRef.current) { + historyRef.current.focus(); + } + break; + } + /* eslint-enable indent */ + }; + + return ( + <> + + Skip to chatbot + + + + { + setIsDrawerOpen(!isDrawerOpen); + setConversations(initialConversations); + }} + isDrawerOpen={isDrawerOpen} + setIsDrawerOpen={setIsDrawerOpen} + activeItemId="1" + // eslint-disable-next-line no-console + onSelectActiveItem={(e, selectedItem) => console.log(`Selected history item with id ${selectedItem}`)} + conversations={conversations} + onNewChat={() => { + setIsDrawerOpen(!isDrawerOpen); + setMessages([]); + setConversations(initialConversations); + }} + handleTextInputChange={(value: string) => { + if (value === '') { + setConversations(initialConversations); + } + // this is where you would perform search on the items in the drawer + // and update the state + const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value); + setConversations(newConversations); + }} + isCompact + drawerContent={ + <> + + + setIsDrawerOpen(!isDrawerOpen)} + isCompact + /> + + + + + + + Granite 7B + + + Llama 3.0 + + + Mistral 3B + + + + + + + } + isSelected={displayMode === ChatbotDisplayMode.default} + > + Overlay + + } + isSelected={displayMode === ChatbotDisplayMode.docked} + > + Dock to window + + } + isSelected={displayMode === ChatbotDisplayMode.fullscreen} + > + Fullscreen + + + + + + + + {/* Update the announcement prop on MessageBox whenever a new message is sent + so that users of assistive devices receive sufficient context */} + + + {/* This code block enables scrolling to the top of the last message. + You can instead choose to move the div with scrollToBottomRef on it below + the map of messages, so that users are forced to scroll to the bottom. + If you are using streaming, you will want to take a different approach; + see: https://github.com/patternfly/chatbot/issues/201#issuecomment-2400725173 */} + {messages.map((message, index) => { + if (index === messages.length - 1) { + return ( + <> +
+ + + ); + } + return ; + })} +
+
+ + + + + + } + >
+
+ + ); +}; diff --git a/packages/module/patternfly-docs/generated/patternfly-ai/chatbot/overview/demo/compact-chatbot.png b/packages/module/patternfly-docs/generated/patternfly-ai/chatbot/overview/demo/compact-chatbot.png new file mode 100644 index 000000000..2a154c0b6 Binary files /dev/null and b/packages/module/patternfly-docs/generated/patternfly-ai/chatbot/overview/demo/compact-chatbot.png differ diff --git a/packages/module/src/Chatbot/Chatbot.test.tsx b/packages/module/src/Chatbot/Chatbot.test.tsx index 2efe8e2fb..26992b16b 100644 --- a/packages/module/src/Chatbot/Chatbot.test.tsx +++ b/packages/module/src/Chatbot/Chatbot.test.tsx @@ -28,4 +28,13 @@ describe('Chatbot', () => { render(Chatbot Content); expect(screen.queryByLabelText('Chatbot')).toBeFalsy(); }); + + it('should handle isCompact', () => { + render( + + Chatbot Content + + ); + expect(screen.getByTestId('chatbot')).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss b/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss index c2554b5f1..292f23c30 100644 --- a/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +++ b/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss @@ -118,7 +118,6 @@ border-radius: var(--pf-t--global--border--radius--pill); justify-content: center; align-items: center; - border-radius: var(--pf-t--global--border--radius--small); } } @@ -230,4 +229,14 @@ --pf-v6-c-drawer__head--PaddingInlineStart: var(--pf-t--global--spacer--lg); --pf-v6-c-drawer__head--PaddingInlineEnd: var(--pf-t--global--spacer--lg); } + .pf-v6-c-drawer__close { + .pf-v6-c-button { + width: 2rem; + height: 2rem; + --pf-v6-c-button--m-plain--PaddingInlineEnd: var(--pf-t--global--spacer--xs); + --pf-v6-c-button--m-plain--PaddingInlineStart: var(--pf-t--global--spacer--xs); + --pf-v6-c-button--PaddingBlockStart: var(--pf-t--global--spacer--xs); + --pf-v6-c-button--PaddingBlockEnd: var(--pf-t--global--spacer--xs); + } + } } diff --git a/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx b/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx index 20ac7eda0..46c0f8b55 100644 --- a/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +++ b/packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx @@ -259,7 +259,11 @@ export const ChatbotConversationHistoryNav: React.FunctionComponent - {onNewChat && } + {onNewChat && ( + + )} {isLoading ? : renderDrawerContent()} diff --git a/packages/module/src/ChatbotFooter/ChatbotFooter.scss b/packages/module/src/ChatbotFooter/ChatbotFooter.scss index 7ef6eedea..52297f84f 100644 --- a/packages/module/src/ChatbotFooter/ChatbotFooter.scss +++ b/packages/module/src/ChatbotFooter/ChatbotFooter.scss @@ -57,3 +57,8 @@ padding: var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--lg); } } + +.pf-chatbot__footer.pf-m-compact .pf-chatbot__footer-container { + padding: 0 var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--sm); + row-gap: var(--pf-t--global--spacer--sm); +} diff --git a/packages/module/src/ChatbotFooter/ChatbotFooter.test.tsx b/packages/module/src/ChatbotFooter/ChatbotFooter.test.tsx index 46992454a..c44595a57 100644 --- a/packages/module/src/ChatbotFooter/ChatbotFooter.test.tsx +++ b/packages/module/src/ChatbotFooter/ChatbotFooter.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import ChatbotFooter from './ChatbotFooter'; +import '@testing-library/jest-dom'; describe('ChatbotFooter', () => { it('should render ChatbotFooter with children', () => { @@ -12,4 +13,13 @@ describe('ChatbotFooter', () => { const { container } = render(Chatbot Content); expect(container.querySelector('.custom-class')).toBeTruthy(); }); + + it('should handle isCompact', () => { + render( + + Chatbot Content + + ); + expect(screen.getByTestId('footer')).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotFooter/ChatbotFooter.tsx b/packages/module/src/ChatbotFooter/ChatbotFooter.tsx index f166c0109..81e4e693c 100644 --- a/packages/module/src/ChatbotFooter/ChatbotFooter.tsx +++ b/packages/module/src/ChatbotFooter/ChatbotFooter.tsx @@ -17,14 +17,16 @@ export interface ChatbotFooterProps extends React.HTMLProps { children?: React.ReactNode; /** Custom classname for the Footer component */ className?: string; + isCompact?: boolean; } export const ChatbotFooter: React.FunctionComponent = ({ children, className, + isCompact, ...props }: ChatbotFooterProps) => ( -
+
{children}
diff --git a/packages/module/src/ChatbotHeader/ChatbotHeader.scss b/packages/module/src/ChatbotHeader/ChatbotHeader.scss index e259c1311..baeddc1fb 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeader.scss +++ b/packages/module/src/ChatbotHeader/ChatbotHeader.scss @@ -141,7 +141,24 @@ // ============================================================================ // Information density styles // ============================================================================ +.pf-chatbot.pf-m-compact { + .pf-chatbot__header { + gap: var(--pf-t--global--spacer--sm); + padding: var(--pf-t--global--spacer--sm); + } + + .pf-chatbot__header .pf-chatbot__title img { + max-height: 24px; + vertical-align: middle; + } +} + +.pf-v6-c-menu-toggle.pf-chatbot__button--toggle-options.pf-m-compact, .pf-chatbot__button--toggle-menu.pf-m-compact { width: 2rem; height: 2rem; } + +.pf-chatbot__header .pf-chatbot__actions .pf-v6-c-menu-toggle.pf-m-secondary.pf-m-compact { + width: initial; +} diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx index dc935f815..1526e4b2d 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { fireEvent, render, screen } from '@testing-library/react'; import { ChatbotHeaderMenu } from './ChatbotHeaderMenu'; +import '@testing-library/jest-dom'; describe('ChatbotHeaderMenu', () => { it('should render ChatbotHeaderMenu with custom class', () => { @@ -16,4 +17,11 @@ describe('ChatbotHeaderMenu', () => { expect(onMenuToggle).toHaveBeenCalled(); }); + + it('should handle isCompact', () => { + render( + + ); + expect(screen.getByTestId('button')).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.tsx index a590af834..7630b9708 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderMenu.tsx @@ -1,9 +1,9 @@ import React from 'react'; -import { Button, Icon, Tooltip, TooltipProps } from '@patternfly/react-core'; +import { Button, ButtonProps, Icon, Tooltip, TooltipProps } from '@patternfly/react-core'; import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon'; -export interface ChatbotHeaderMenuProps { +export interface ChatbotHeaderMenuProps extends ButtonProps { /** Callback function to attach to menu toggle on top right of chatbot header. */ onMenuToggle: () => void; /** Custom classname for the header component */ @@ -16,6 +16,7 @@ export interface ChatbotHeaderMenuProps { innerRef?: React.Ref; /** Content used in tooltip */ tooltipContent?: string; + isCompact?: boolean; } const ChatbotHeaderMenuBase: React.FunctionComponent = ({ @@ -24,7 +25,9 @@ const ChatbotHeaderMenuBase: React.FunctionComponent = ( tooltipProps, menuAriaLabel = 'Toggle menu', innerRef, - tooltipContent = 'Menu' + tooltipContent = 'Menu', + isCompact, + ...props }: ChatbotHeaderMenuProps) => (
= ( {...tooltipProps} >
diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx index 484bef704..408ea134b 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { DropdownItem } from '@patternfly/react-core'; import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; import { ChatbotHeaderOptionsDropdown } from './ChatbotHeaderOptionsDropdown'; +import '@testing-library/jest-dom'; describe('ChatbotHeaderOptionsDropdown', () => { const dropdownItems = ( @@ -42,4 +43,9 @@ describe('ChatbotHeaderOptionsDropdown', () => { expect(onSelect).toHaveBeenCalled(); }); }); + + it('should handle isCompact', () => { + render({dropdownItems}); + expect(screen.getByRole('button', { name: 'Chatbot options' })).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.tsx index e8e1fe9c8..a4ca4771e 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.tsx @@ -20,6 +20,7 @@ export interface ChatbotHeaderOptionsDropdownProps extends Omit = ({ @@ -28,6 +29,7 @@ export const ChatbotHeaderOptionsDropdown: React.FunctionComponent { const [isOptionsMenuOpen, setIsOptionsMenuOpen] = React.useState(false); @@ -42,17 +44,18 @@ export const ChatbotHeaderOptionsDropdown: React.FunctionComponent + } isExpanded={isOptionsMenuOpen} onClick={() => setIsOptionsMenuOpen(!isOptionsMenuOpen)} + size={isCompact ? 'sm' : undefined} /> ); diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx index 7d18bf3ff..778703435 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { DropdownItem } from '@patternfly/react-core'; import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; import { ChatbotHeaderSelectorDropdown } from './ChatbotHeaderSelectorDropdown'; +import '@testing-library/jest-dom'; describe('ChatbotHeaderSelectorDropdown', () => { const dropdownItems = ( @@ -40,4 +41,13 @@ describe('ChatbotHeaderSelectorDropdown', () => { expect(onSelect).toHaveBeenCalled(); }); }); + + it('should handle isCompact', () => { + render( + + {dropdownItems} + + ); + expect(screen.getByRole('button', { name: /Select model/i })).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.tsx b/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.tsx index a5884c279..3eafb70b4 100644 --- a/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.tsx +++ b/packages/module/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.tsx @@ -15,6 +15,7 @@ export interface ChatbotHeaderSelectorDropdownProps extends Omit = ({ @@ -25,6 +26,7 @@ export const ChatbotHeaderSelectorDropdown: React.FunctionComponent { const [isOptionsMenuOpen, setIsOptionsMenuOpen] = React.useState(false); @@ -45,6 +47,8 @@ export const ChatbotHeaderSelectorDropdown: React.FunctionComponent setIsOptionsMenuOpen(!isOptionsMenuOpen)} + size={isCompact ? 'sm' : undefined} + className={`${isCompact ? 'pf-m-compact' : ''}`} > {value} diff --git a/packages/module/src/ChatbotPopover/ChatbotPopover.scss b/packages/module/src/ChatbotPopover/ChatbotPopover.scss index 83476ecb9..19d64bbec 100644 --- a/packages/module/src/ChatbotPopover/ChatbotPopover.scss +++ b/packages/module/src/ChatbotPopover/ChatbotPopover.scss @@ -2,14 +2,19 @@ // Chatbot Popover // ============================================================================ .pf-chatbot__popover { - .pf-v6-c-popover__arrow { display: none; } + .pf-v6-c-popover__arrow { + display: none; + } // Footnote popover &--footnote.pf-chatbot__popover { - // Contents - img { border-radius: var(--pf-t--global--border--radius--small); } - .pf-v6-c-content--h3 { font-weight: var(--pf-t--global--font--weight--body--bold); } + img { + border-radius: var(--pf-t--global--border--radius--small); + } + .pf-v6-c-content--h3 { + font-weight: var(--pf-t--global--font--weight--body--bold); + } .pf-v6-c-content--p { font-size: var(--pf-t--global--font--size--body--lg); } @@ -23,5 +28,4 @@ font-size: var(--pf-t--global--font--size--body--lg); } } - } diff --git a/packages/module/src/ChatbotPopover/ChatbotPopover.tsx b/packages/module/src/ChatbotPopover/ChatbotPopover.tsx index 6627a3e81..ee92461b9 100644 --- a/packages/module/src/ChatbotPopover/ChatbotPopover.tsx +++ b/packages/module/src/ChatbotPopover/ChatbotPopover.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { Popover, PopoverProps } from '@patternfly/react-core'; export const ChatbotPopover: React.FunctionComponent = ({ children, className, ...props }) => ( - + {children} ); diff --git a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.scss b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.scss index 0a37e02d0..8aa3e6138 100644 --- a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.scss +++ b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.scss @@ -8,7 +8,6 @@ gap: var(--pf-t--global--spacer--lg); .pf-v6-c-content--h1 { - --pf-v6-c-content--h1--FontSize: var(--pf-t--global--font--size--3xl); // larger than any of our semantic tokens --pf-v6-c-content--h1--FontWeight: var(--pf-t--global--font--weight--400); --pf-v6-c-content--h1--MarginBlockEnd: 0; } @@ -34,6 +33,15 @@ } } +.pf-chatbot--layout--welcome.pf-m-compact { + gap: var(--pf-t--global--spacer--md); + padding-block-end: var(--pf-t--global--spacer--md); + + .pf-chatbot__prompt-suggestions { + gap: var(--pf-t--global--spacer--md); + } +} + // ============================================================================ // Chatbot Display Mode - Fullscreen and Embedded // ============================================================================ diff --git a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.tsx b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.tsx index ea67fede6..0dc5ecc02 100644 --- a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.tsx +++ b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.test.tsx @@ -69,4 +69,17 @@ describe('ChatbotWelcomePrompt', () => { const element = screen.getByTestId('welcome-prompt'); expect(element).toHaveClass('test'); }); + + it('should handle isCompact', () => { + render( + + ); + expect(screen.getByTestId('welcome-prompt')).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.tsx b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.tsx index afe7a6e2a..e9808cb63 100644 --- a/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.tsx +++ b/packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.tsx @@ -16,6 +16,7 @@ export interface ChatbotWelcomePromptProps extends React.HTMLProps ( -
+
{title}
@@ -45,7 +51,12 @@ export const ChatbotWelcomePrompt: React.FunctionComponent {prompts?.map((prompt, index) => ( - +

{ expect(input.files).toHaveLength(1); expect(spy).toHaveBeenCalledTimes(1); }); + it('should handle isCompact', () => { + render(); + expect(screen.getByTestId('button')).toHaveClass('pf-m-compact'); + }); }); diff --git a/packages/module/src/MessageBar/AttachButton.tsx b/packages/module/src/MessageBar/AttachButton.tsx index f5275b7cd..15d4c6e47 100644 --- a/packages/module/src/MessageBar/AttachButton.tsx +++ b/packages/module/src/MessageBar/AttachButton.tsx @@ -25,6 +25,7 @@ export interface AttachButtonProps extends ButtonProps { tooltipContent?: string; /** Test id applied to input */ inputTestId?: string; + isCompact?: boolean; } const AttachButtonBase: React.FunctionComponent = ({ @@ -36,6 +37,7 @@ const AttachButtonBase: React.FunctionComponent = ({ innerRef, tooltipContent = 'Attach', inputTestId, + isCompact, ...props }: AttachButtonProps) => { const { open, getInputProps } = useDropzone({ @@ -62,15 +64,16 @@ const AttachButtonBase: React.FunctionComponent = ({