Skip to content

Commit 383b96a

Browse files
fix(ChatbotConversationHistoryNav): Make title icon and heading customizable (#616)
Also change spacing between icon and title to 0.5rem.
1 parent 819ecfa commit 383b96a

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99

1010
// Drawer title
1111
// ----------------------------------------------------------------------------
12-
.pf-chatbot__title-container {
12+
.pf-chatbot__heading-container {
1313
padding-inline-start: var(--pf-t--global--spacer--lg);
1414
padding-inline-end: var(--pf-t--global--spacer--lg);
1515
display: flex;
1616
flex-direction: column;
1717
row-gap: var(--pf-t--global--spacer--sm);
1818
}
19-
// Drawer title icon
20-
// ----------------------------------------------------------------------------
21-
.pf-chatbot__title-icon {
22-
padding-inline-end: var(--pf-t--global--spacer--md);
23-
padding-inline-start: var(--pf-t--global--spacer--sm);
19+
.pf-chatbot__title {
20+
font-size: var(--pf-v6-c-title--m-h3--FontSize);
21+
font-weight: var(--pf-v6-c-title--m-h3--FontWeight);
22+
line-height: var(--pf-v6-c-title--m-h3--LineHeight);
23+
}
24+
.pf-chatbot__title-container {
25+
display: flex;
26+
flex-direction: row;
27+
align-items: baseline;
28+
justify-content: flex-start;
29+
gap: var(--pf-t--global--spacer--gap--text-to-element--default);
2430
}
2531
// Drawer menu
2632
// ----------------------------------------------------------------------------

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
44
import { ChatbotDisplayMode } from '../Chatbot/Chatbot';
55
import ChatbotConversationHistoryNav, { Conversation } from './ChatbotConversationHistoryNav';
66
import { EmptyStateStatus, Spinner } from '@patternfly/react-core';
7-
import { OutlinedCommentsIcon, SearchIcon } from '@patternfly/react-icons';
7+
import { BellIcon, OutlinedCommentsIcon, SearchIcon } from '@patternfly/react-icons';
88
import { ComponentType } from 'react';
99

1010
const ERROR = {
@@ -492,29 +492,29 @@ describe('ChatbotConversationHistoryNav', () => {
492492
expect(iconElement).toBeInTheDocument();
493493
});
494494

495-
it('Passes titleProps to Title', () => {
495+
it('Passes listTitleProps to Title', () => {
496496
render(
497497
<ChatbotConversationHistoryNav
498498
onDrawerToggle={onDrawerToggle}
499499
isDrawerOpen={true}
500500
displayMode={ChatbotDisplayMode.fullscreen}
501501
setIsDrawerOpen={jest.fn()}
502502
conversations={{ Today: initialConversations }}
503-
titleProps={{ className: 'test' }}
503+
listTitleProps={{ className: 'test' }}
504504
/>
505505
);
506506
expect(screen.getByRole('heading', { name: /Today/i })).toHaveClass('test');
507507
});
508508

509-
it('Overrides Title heading level when titleProps.headingLevel is passed', () => {
509+
it('Overrides list title heading level when titleProps.headingLevel is passed', () => {
510510
render(
511511
<ChatbotConversationHistoryNav
512512
onDrawerToggle={onDrawerToggle}
513513
isDrawerOpen={true}
514514
displayMode={ChatbotDisplayMode.fullscreen}
515515
setIsDrawerOpen={jest.fn()}
516516
conversations={{ Today: initialConversations }}
517-
titleProps={{ headingLevel: 'h2' }}
517+
listTitleProps={{ headingLevel: 'h2' }}
518518
/>
519519
);
520520
expect(screen.queryByRole('heading', { name: /Today/i, level: 4 })).not.toBeInTheDocument();
@@ -577,4 +577,33 @@ describe('ChatbotConversationHistoryNav', () => {
577577

578578
expect(screen.getByRole('dialog', { name: /Chat history I am a sample search/i })).toBeInTheDocument();
579579
});
580+
581+
it('overrides nav title heading level when navTitleProps.headingLevel is passed', () => {
582+
render(
583+
<ChatbotConversationHistoryNav
584+
onDrawerToggle={onDrawerToggle}
585+
isDrawerOpen={true}
586+
displayMode={ChatbotDisplayMode.fullscreen}
587+
setIsDrawerOpen={jest.fn()}
588+
conversations={{ Today: initialConversations }}
589+
navTitleProps={{ headingLevel: 'h1' }}
590+
/>
591+
);
592+
expect(screen.queryByRole('heading', { name: /Chat history/i, level: 2 })).not.toBeInTheDocument();
593+
expect(screen.getByRole('heading', { name: /Chat history/i, level: 1 })).toBeInTheDocument();
594+
});
595+
596+
it('overrides nav title icon when navTitleIcon is passed in', () => {
597+
render(
598+
<ChatbotConversationHistoryNav
599+
onDrawerToggle={onDrawerToggle}
600+
isDrawerOpen={true}
601+
displayMode={ChatbotDisplayMode.fullscreen}
602+
setIsDrawerOpen={jest.fn()}
603+
conversations={initialConversations}
604+
navTitleIcon={<BellIcon data-testid="bell" />}
605+
/>
606+
);
607+
expect(screen.getByTestId('bell')).toBeInTheDocument();
608+
});
580609
});

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
8484
/** Additional button props for new chat button. */
8585
newChatButtonProps?: ButtonProps;
8686
/** Additional props applied to all conversation list headers */
87-
titleProps?: Partial<TitleProps>;
87+
listTitleProps?: Partial<TitleProps>;
8888
/** Additional props applied to conversation list. If conversations is an object, you should pass an object of ListProps for each group. */
8989
listProps?: ListProps | { [key: string]: ListProps };
9090
/** Text shown in blue button */
@@ -137,6 +137,10 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
137137
isCompact?: boolean;
138138
/** Display title */
139139
title?: string;
140+
/** Icon displayed in title */
141+
navTitleIcon?: React.ReactNode;
142+
/** Title header level */
143+
navTitleProps?: Partial<TitleProps>;
140144
}
141145

142146
export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversationHistoryNavProps> = ({
@@ -146,7 +150,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
146150
activeItemId,
147151
onSelectActiveItem,
148152
conversations,
149-
titleProps,
153+
listTitleProps,
150154
listProps,
151155
newChatButtonText = 'New chat',
152156
drawerContent,
@@ -173,6 +177,8 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
173177
noResultsState,
174178
isCompact,
175179
title = 'Chat history',
180+
navTitleProps,
181+
navTitleIcon = <OutlinedClockIcon />,
176182
...props
177183
}: ChatbotConversationHistoryNavProps) => {
178184
const drawerRef = useRef<HTMLDivElement>(null);
@@ -225,7 +231,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
225231
<div>
226232
{Object.keys(conversations).map((navGroup) => (
227233
<section key={navGroup}>
228-
<Title headingLevel="h4" className="pf-chatbot__conversation-list-header" {...titleProps}>
234+
<Title headingLevel="h4" className="pf-chatbot__conversation-list-header" {...listTitleProps}>
229235
{navGroup}
230236
</Title>
231237
<List className="pf-chatbot__conversation-list" isPlain {...listProps?.[navGroup]}>
@@ -286,13 +292,15 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
286292
)}
287293
</DrawerActions>
288294
</DrawerHead>
289-
<div className="pf-chatbot__title-container">
290-
<Title headingLevel="h3">
295+
<div className="pf-chatbot__heading-container">
296+
<div className="pf-chatbot__title-container">
291297
<Icon size="lg" className="pf-chatbot__title-icon">
292-
<OutlinedClockIcon />
298+
{navTitleIcon}
293299
</Icon>
294-
{title}
295-
</Title>
300+
<Title className="pf-chatbot__title" headingLevel="h2" {...navTitleProps}>
301+
{title}
302+
</Title>
303+
</div>
296304
{!isLoading && handleTextInputChange && (
297305
<div className="pf-chatbot__input">
298306
<SearchInput

0 commit comments

Comments
 (0)