Structure
Container
The PatternFly ChatBot is a separate window that overlays or is embedded within other UI content. This container can be shown and hidden via the ChatBot toggle.
The <Chatbot>
component is the container that encompasses the ChatBot experience. It adapts to various display modes (overlay/default, docked, fullscreen, and embedded) and supports both light and dark themes.
The "embedded" display mode is meant to be used within a PatternFly page or other container within your product.
Content and message box
The <ChatbotContent>
component is the container that is placed within the <Chatbot>
, between the <ChatbotHeader>
and <ChatbotFooter>
.
<ChatbotContent>
usually contains a <ChatbotMessageBox>
for displaying messages.
Your code structure should look like this:
<Chatbot>
<ChatbotHeader ... />
<ChatbotContent>
<ChatbotMessageBox>
...
<ChatbotMessageBox>
</ChatbotContent>
<ChatbotFooter ... />
</Chatbot>
Note: When messages update, it is important to announce new messages to users of assistive technology. To do this, make sure to set the announcement
prop on <MessageBox>
whenever you display a new message in <MessageBox>
. You can view this in action in our basic ChatBot and embedded ChatBot demos.
Welcome message
To introduce users to the ChatBot experience, display a welcome message before they input their first message. This brief message should follow our conversation design guidelines to welcome users to the ChatBot experience and encourage them to interact.
This message can be dismissed once a user sends their first message. To change the arrangement of the message within the message box, specify the position
in the <MessageBox>
component.
Welcome prompt
To provide users with a more specific direction, you can also include optional welcome prompts.
Hello, Chatbot User
How may I help you today?
Skip to content
To provide page context, we recommend using a "Skip to chatbot" button. This allows you to skip past other content on the page, directly to the ChatBot content, using a PatternFly skip to content component. To display this button, you must tab into the main window.
When using default or docked modes, we recommend putting focus on the toggle if the ChatBot is closed, and the ChatBot when it is open. For fullscreen and embedded, we recommend putting the focus on the first focusable item in the ChatBot, such as a menu toggle. This can be seen in our more fully-featured demos for the default, embedded, and fullscreen ChatBot and the embedded ChatBot.
Toggle
Custom toggle icon
A custom icon can be passed to the toggle. To ensure the icon is visible in both light and dark themes, use an SVG image and set fill="currentColor"
.
Custom toggle shape
A custom shape can be set for the toggle. To override the default circle shape, set isRound
to false
. This will set the toggle to a square shape, but you can pass in additional classes to further customize the shape.
Header
Header sections
The ChatBot header is persistent, and contains the title for the ChatBot window, as well as any related controls and actions.
The <ChatbotHeader>
has 2 sections:
<ChatbotHeaderMain>
contains the title and an optional menu toggle:<ChatbotHeaderTitle>
handles the layout and display of a title or image at different responsive sizes.<ChatbotHeaderMenu>
(optional) is placed on the left side of the header and used to toggle a chat history menu.
<ChatbotHeaderActions>
contains any additional controls:- The
<ChatbotHeaderSelectorDropdown>
component is a standard PatternFly dropdown that matches the ChatBot styles. - The
<ChatbotHeaderOptionsDropdown>
component is a dropdown with a menu toggle that is intended to be used to update ChatBot settings (like the display mode).
- The
Your <ChatbotHeader>
code structure should look like this:
<ChatbotHeader>
<ChatbotHeaderMain>
<ChatbotHeaderMenu ... />
<ChatbotHeaderTitle ... />
</ChatbotHeaderMain>
<ChatbotHeaderActions>
<ChatbotHeaderSelectorDropdown ... />
<ChatbotHeaderOptionsDropdown ... />
</ChatbotHeaderActions>
</ChatbotHeader>
Header title
By default, <HeaderTitle>
renders any children that are passed in. Optionally, you can pass in a displayMode
, showOnEmbedded
, showOnDocked
, showOnFullScreen
, and/or showOnDefault
to render content conditionally.
Header options
There are a variety of options and customizations you can make to the header, to adjust how information is displayed, or to add additional controls.
In this example, select the respective checkbox to toggle these features:
- Menu: Users can select the menu toggle to open a menu of additional options or actions.
- Left-aligned logo
- Centered logo
- Selector dropdown: Users can choose from preselected options in a dropdown menu. For example, they can toggle between AI models.
- Options dropdown: Users can select ChatBot options from a menu. For example, they can switch between ChatBot display modes.
ChatBot Extension
Footer
Footnote with popover
A footnote can be placed in the ChatBot footer to communicate any legal disclaimers or information about the ChatBot. Footnotes can be static text or a button that opens a popover.
Message bar with speech recognition and file attachment
In Safari and Chrome, you will see a microphone button in the message bar if hasMicrophoneButton
is passed to <MessageBar>
. The button will only appear if 'SpeechRecognition'
or 'webkitSpeechRecognition'
are available in window
. This does not currently work in Firefox.
By default the message bar supports file uploads via an attach button. Setting hasAttachButton
to false
will disable that feature.
Message bar with speech recognition in a different language
Speech recognition defaults to en-US. You can update the locale as needed. Locale codes are a combination of the ISO 639-1 language code and the ISO 3166-1 country code, separated by a hyphen.
In this example, the locale is set to to ja-JP. You can try it out by saying "hajimemashite" (初めまして).
Message bar with attach menu appended to attach button
You can change the behavior of the attach button to open a menu, rather than the default file viewer for your operating system. This menu can display different actions related to attachments.
Attachments can also be added to the ChatBot via drag and drop.
Footer with message bar and footnote
A simple footer with a message bar and footnote would have this code structure:
<ChatbotFooter>
<MessageBar ... />
<ChatbotFootnote .../>
</ChatbotFooter>
Message bar with stop button
If you are using streaming, you can add a stop button to the message bar that allows users to stop a response from a ChatBot.
To enable the stop button, set hasStopButton
to true
and pass in a handleStopButton
callback function. You can use this callback to trigger an AbortController configured as part of your API call.
Navigation
Side nav in a drawer
The ChatBot conversation history is contained in an interactive drawer, where users can interact with previous conversations or start a new conversation.
The <ChatbotConversationHistoryNav>
component is a wrapper placed within <Chatbot>
, which contains all other ChatBot components in drawerContent
. There is a focus trap so users can only tab within the drawer while it is open.
The code structure will look like this:
<Chatbot>
<ChatbotConversationHistoryNav
...
drawerContent={
<>
<ChatbotContent>
<ChatbotMessageBox>
...
<ChatbotMessageBox>
</ChatbotContent>
<ChatbotFooter ... />
</>
}>
</ChatbotConversationHistoryNav>
</Chatbot>
The conversation history drawer looks different depending on the displayMode
of the parent <Chatbot>
. (As shown in the main ChatBot demo.):
Default
anddocked
display modes display the conversation history on top of the rest of the ChatBot content, with a PatternFly backdrop between the drawer panel and drawer content.Fullscreen
andembedded
display modes display the conversation history in line with the drawer content.
Drawer with search and "new chat" button
In the conversation history drawer, users can search previous ChatBot conversations via an input field. To customize the placeholder text, use searchInputPlaceholder
. Provide an aria label via searchInputAriaLabel
.
They can also start new conversations via a "New chat" button. To customize the button label, use newChatButtonText
.
Both the search input field and "New chat" buttons are optional. The reverseButtonOrder
prop allows you to invert the positions of the Close and "New chat" buttons within the drawer when set to true
.
Drawer with conversation actions
Actions can be added to conversations with menuItems
. Optionally, you can also add a className
to the menu via menuClassName
, change the default aria-label and tooltip content via label
, or add an onSelect
callback for when a user selects an item.
Modal
Based on the PatternFly modal, this modal adapts to the ChatBot display mode and accepts components typically used in a modal. It is primarily used and tested in the context of the attachment modals, but you can customize this modal to adapt it to other use cases as needed. The modal will overlay the ChatBot in default and docked modes, and will behave more like a traditional PatternFly modal in fullscreen and embedded modes.
Props
Chatbot
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot | |
ariaLabel | string | Custom aria label applied to focusable container | |
className | string | Custom classname for the Chatbot component | |
displayMode | ChatbotDisplayMode | Display Mode for the Chatbot | |
innerRef | React.Ref<HTMLDivElement> | Ref applied to chatbot | |
isVisible | boolean | Visibility flag for the chatbot |
ChatbotContent
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot | |
className | string | Custom classname for the ChatbotContent component |
MessageBox
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the message box | |
announcement | string | Content that can be announced, such as a new message, for screen readers | |
ariaLabel | string | Custom aria-label for scrollable portion of message box | |
className | string | Custom classname for the MessageBox component | |
innerRef | React.Ref<HTMLDivElement> | Ref applied to message box | |
position | 'top' | 'bottom' | Modifier that controls how content in MessageBox is positioned within the container |
ChatbotWelcomePrompt
Name | Type | Default | Description |
---|---|---|---|
descriptionrequired | string | Welcome message | |
titlerequired | string | Title for the welcome message | |
className | string | Custom classname for the WelcomePrompt component | |
prompts | WelcomePrompt[] | Custom basic prompts to help users coming for the first time to chatbot | |
testId | string | Custom test id for the WelcomePrompt component |
WelcomePrompt
Name | Type | Default | Description |
---|---|---|---|
titlerequired | string | Title for the welcome prompt | |
message | string | Message for the welcome prompt | |
onClick | () => void | Callback handler for the onClick event for welcome prompt |
ChatbotToggle
Name | Type | Default | Description |
---|---|---|---|
tooltipLabelrequired | React.ReactNode | Contents of the tooltip applied to the toggle button | |
className | string | Class name applied to toggle | |
closedToggleIcon | () => JSX.Element | An image displayed in the chatbot toggle when it is closed | |
innerRef | React.Ref<HTMLButtonElement> | Ref applied to toggle | |
isChatbotVisible | boolean | Flag indicating visibility of the chatbot appended to the toggle | |
isRound | boolean | Whether toggle is a circle | |
onToggleChatbot | () => void | Callback fired when toggle button is clicked | |
openIconTestId | string | Test id applied to default open icon | |
toggleButtonLabel | string | Accessible label for the toggle button | |
tooltipProps | Omit<TooltipProps, 'content'> | Props spread to the PF Tooltip component |
ChatbotHeader
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot header | |
className | string | Custom classname for the header component |
ChatbotHeaderMain
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Menu and/or chatbot header components | |
className | string | Custom classname for the header component |
ChatbotHeaderMenu
Name | Type | Default | Description |
---|---|---|---|
onMenuTogglerequired | () => void | Callback function to attach to menu toggle on top right of chatbot header. | |
className | string | Custom classname for the header component | |
innerRef | React.Ref<HTMLButtonElement> | Ref applied to menu | |
menuAriaLabel | string | Aria label for menu | |
tooltipProps | TooltipProps | Props spread to the PF Tooltip component wrapping the display mode dropdown |
ChatbotHeaderActions
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot header | |
className | string | Custom classname for the header component |
ChatbotHeaderTitle
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | Content to be displayed in the chatbot header | |
className | string | Custom classname for the header component | |
displayMode | ChatbotDisplayMode | Display mode of chatbot, in case you want to conditionally show a title | |
showOnDefault | React.ReactNode | string | Content to display by default; this will be shown if a case is not explicitly set | |
showOnDocked | React.ReactNode | string | Content to display on docked screen | |
showOnEmbedded | React.ReactNode | string | Content to display on overlay screen | |
showOnFullScreen | React.ReactNode | string | Content to display on full screen |
ChatbotHeaderOptionsDropdown
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot header | |
className | string | Custom classname for the header component | |
menuToggleAriaLabel | string | 'Chatbot options' | Aria label for menu toggle |
tooltipProps | TooltipProps | Props spread to the PF Tooltip component wrapping the display mode dropdown |
ChatbotHeaderSelectorDropdown
Name | Type | Default | Description |
---|---|---|---|
childrenrequired | React.ReactNode | Content to be displayed in the chatbot header | |
valuerequired | string | Value of the selected dropdown item | |
className | string | Custom classname for the header component | |
menuToggleAriaLabel | string | Aria label for menu toggle | |
tooltipContent | string | 'Chatbot selector' | Text displayed in Tooltip wrapping the display mode dropdown |
tooltipProps | TooltipProps | Props spread to the PF Tooltip component wrapping the display mode dropdown |
ChatbotFooter
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | Children for the Footer that supports MessageBar and FootNote components | |
className | string | Custom classname for the Footer component |
MessageBar
Name | Type | Default | Description |
---|---|---|---|
onSendMessagerequired | (message: string) => void | Callback to get the value of input message by user | |
alwayShowSendButton | boolean | Flag to always to show the send button. By default send button is shown when there is a message in the input field | |
attachMenuProps | MessageBarWithAttachMenuProps | Props to enable a menu that opens when the Attach button is clicked, instead of the attachment window | |
buttonProps | { attach?: { tooltipContent?: string; props?: ButtonProps; inputTestId?: string }; stop?: { tooltipContent?: string; props?: ButtonProps }; send?: { tooltipContent?: string; props?: ButtonProps }; microphone?: { tooltipContent?: { active?: string; inactive?: string }; language?: string; props?: ButtonProps; }; } | Prop to allow passage of additional props to buttons | |
className | string | Class Name for the MessageBar component | |
handleAttach | (data: File[], event: DropEvent) => void | Callback function for when attach button is used to upload a file | |
handleStopButton | (event: React.MouseEvent<HTMLButtonElement>) => void | Callback function for when stop button is clicked | |
hasAttachButton | boolean | true | Flag to disable/enable the Attach button |
hasMicrophoneButton | boolean | Flag to enable the Microphone button | |
hasStopButton | boolean | Flag to enable the Stop button, used for streaming content | |
isSendButtonDisabled | boolean | Flag to provide manual control over whether send button is disabled | |
onChange | (event: React.ChangeEvent<HTMLDivElement>, value: string) => void | A callback for when the text area value changes. |
ChatbotFootnote
Name | Type | Default | Description |
---|---|---|---|
labelrequired | string | Label to show for the footnote | |
className | string | Custom classname for the Footnote component | |
popover | ChatbotFootnotePopover | Config for the popover which opens up when footnote is clicked |
ChatbotFootnotePopover
Name | Type | Default | Description |
---|---|---|---|
descriptionrequired | string | Description for the Footnote popover | |
titlerequired | string | Title for the Footnote popover | |
bannerImage | ChatbotFootnotePopoverBannerImage | Optional Banner Image that can be shown in the Footnote Popover | |
cta | ChatbotFootnotePopoverCTA | Optional CTA button that can be used to trigger an action and close the popover | |
link | ChatbotFootnotePopoverLink | Optional link that can be used to show and external link like **Learn More** | |
popoverProps | PopoverProps | Props for PF Popover |
ChatbotFootnotePopoverCTA
Name | Type | Default | Description |
---|---|---|---|
labelrequired | string | Label for the CTA | |
onClickrequired | () => void | Callback for the CTA |
ChatbotFootnotePopoverBannerImage
Name | Type | Default | Description |
---|---|---|---|
altrequired | string | Alternate text for the banner image | |
srcrequired | string | Source for the banner image |
ChatbotFootnotePopoverLink
Name | Type | Default | Description |
---|---|---|---|
labelrequired | string | Label for the Link | |
urlrequired | string | URL for the Link |
MessageBarWithAttachMenuProps
Name | Type | Default | Description |
---|---|---|---|
attachMenuItemsrequired | React.ReactNode | Items in menu | |
isAttachMenuOpenrequired | boolean | Flag to enable whether attach menu is open | |
onAttachMenuInputChangerequired | (value: string) => void | A callback for when the input value in the menu changes. | |
onAttachMenuToggleClickrequired | () => void | A callback for when the attachment menu toggle is clicked | |
setIsAttachMenuOpenrequired | (isOpen: boolean) => void | Callback to close attach menu | |
attachMenuInputPlaceholder | string | Placeholder for search input | |
onAttachMenuOnOpenChangeKeys | string[] | Keys that trigger onOpenChange, defaults to tab and escape. It is highly recommended to include Escape in the array, while Tab may be omitted if the menu contains non-menu items that are focusable. | |
onAttachMenuOpenChange | (isOpen: boolean) => void | Callback to change the open state of the menu. Triggered by clicking outside of the menu. | |
onAttachMenuSelect | (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void | Function callback called when user selects item in menu. |
SourceDetailsMenuItem
Name | Type | Default | Description |
---|---|---|---|
iconrequired | React.ReactNode | Icon | |
namerequired | string | Name of source | |
type | string | Description of source |
ChatbotConversationHistoryNav
Name | Type | Default | Description |
---|---|---|---|
conversationsrequired | Conversation[] | { [key: string]: Conversation[] } | Items shown in conversation history | |
displayModerequired | ChatbotDisplayMode | Display mode of chatbot | |
isDrawerOpenrequired | boolean | Flag to indicate whether drawer is open | |
onDrawerTogglerequired | (event: React.KeyboardEvent | React.MouseEvent | React.TransitionEvent) => void | Function called to toggle drawer | |
setIsDrawerOpenrequired | (bool: boolean) => void | Function called to close drawer | |
activeItemId | string | number | ||
drawerActionsTestId | string | 'chatbot-nav-drawer-actions' | Custom test id for the drawer actions |
drawerContent | React.ReactNode | Content wrapped by conversation history nav | |
handleTextInputChange | (value: string) => void | A callback for when the input value changes. Omit to hide input field | |
newChatButtonText | string | 'New chat' | Text shown in blue button |
onNewChat | () => void | Callback function for when blue button is clicked. Omit to hide blue "new chat button" | |
onSelectActiveItem | (event?: React.MouseEvent, itemId?: string | number) => void | Callback function for when an item is selected | |
reverseButtonOrder | boolean | false | Reverses the order of the drawer action buttons |
searchInputAriaLabel | string | 'Filter menu items' | Aria label for search input |
searchInputPlaceholder | string | 'Search...' | Placeholder for search input |
Conversation
Name | Type | Default | Description |
---|---|---|---|
idrequired | string | Conversation id | |
textrequired | string | Conversation | |
icon | React.ReactNode | Conversation icon | |
label | string | Tooltip content and aria-label applied to conversation options dropdown | |
menuClassName | string | Optional classname applied to conversation options dropdown | |
menuItems | React.ReactNode | Dropdown items rendered in conversation options dropdown | |
noIcon | boolean | Flag for no icon | |
onSelect | (event?: React.MouseEvent, value?: string | number) => void | Callback for when user selects item. |