Skip to content

Commit 943ff93

Browse files
committed
feat(Message): Add compact sources, quick starts, and quick responses
Added isCompact prop used to control information density in Sources cards, Quick Starts tiles, and quick response labels.
1 parent 90b4479 commit 943ff93

File tree

8 files changed

+82
-4
lines changed

8 files changed

+82
-4
lines changed

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithQuickResponses.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,29 @@ export const MessageWithQuickResponsesExample: React.FunctionComponent = () => (
5050
{ id: '2', content: 'No', onClick: () => alert('Clicked no') }
5151
]}
5252
/>
53+
<Message
54+
name="Bot"
55+
role="bot"
56+
avatar={patternflyAvatar}
57+
content="Welcome back, User! How can I help you today?"
58+
quickResponses={[
59+
{ id: '1', content: 'Help me with an access issue', onClick: () => alert('Clicked id 1') },
60+
{ id: '2', content: 'Show my critical vulnerabilities', onClick: () => alert('Clicked id 2') },
61+
{ id: '3', content: 'Create new integrations', onClick: () => alert('Clicked id 3') },
62+
{ id: '4', content: 'Get recommendations from an advisor', onClick: () => alert('Clicked id 4') },
63+
{ id: '5', content: 'Something else', onClick: () => alert('Clicked id 5') }
64+
]}
65+
/>
66+
<Message
67+
name="Bot"
68+
role="bot"
69+
avatar={patternflyAvatar}
70+
content="Example with compact responses"
71+
quickResponses={[
72+
{ id: '1', content: 'Yes', onClick: () => alert('Clicked id 1') },
73+
{ id: '2', content: 'No', onClick: () => alert('Clicked id 2') }
74+
]}
75+
isCompact
76+
/>
5377
</>
5478
);

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithQuickStart.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@ export const MessageWithQuickStartExample: React.FunctionComponent = () => (
2727
onSelectQuickStart: (id) => alert(id)
2828
}}
2929
/>
30+
<Message
31+
name="Bot"
32+
role="bot"
33+
avatar={patternflyAvatar}
34+
content="This quick start tile is compact"
35+
quickStarts={{
36+
quickStart: monitorSampleAppQuickStart,
37+
onSelectQuickStart: (id) => alert(id)
38+
}}
39+
isCompact
40+
/>
3041
</>
3142
);

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ export const MessageWithSourcesExample: React.FunctionComponent = () => {
150150
onSetPage
151151
}}
152152
/>
153+
<Message
154+
name="Bot"
155+
role="bot"
156+
avatar={patternflyAvatar}
157+
content="This example displays a compact sources card"
158+
sources={{
159+
sources: [
160+
{
161+
link: '#'
162+
},
163+
{
164+
link: '#'
165+
},
166+
{
167+
link: '#'
168+
}
169+
],
170+
onSetPage
171+
}}
172+
isCompact
173+
/>
153174
</>
154175
);
155176
};

packages/module/src/Message/Message.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ export interface MessageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'rol
164164
onEditCancel?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
165165
/** Props for edit form */
166166
editFormProps?: FormProps;
167+
/** Sets message to compact styling. */
168+
isCompact?: boolean;
167169
}
168170

169171
export const MessageBase: React.FunctionComponent<MessageProps> = ({
@@ -201,6 +203,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
201203
onEditUpdate,
202204
onEditCancel,
203205
editFormProps,
206+
isCompact,
204207
...props
205208
}: MessageProps) => {
206209
const [messageText, setMessageText] = React.useState(content);
@@ -336,7 +339,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
336339
<div className="pf-chatbot__message-and-actions">
337340
{renderMessage()}
338341
{afterMainContent && <>{afterMainContent}</>}
339-
{!isLoading && sources && <SourcesCard {...sources} />}
342+
{!isLoading && sources && <SourcesCard {...sources} isCompact={isCompact} />}
340343
{quickStarts && quickStarts.quickStart && (
341344
<QuickStartTile
342345
quickStart={quickStarts.quickStart}
@@ -346,6 +349,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
346349
prerequisiteWord={quickStarts.prerequisiteWord}
347350
prerequisiteWordPlural={quickStarts.prerequisiteWordPlural}
348351
quickStartButtonAriaLabel={quickStarts.quickStartButtonAriaLabel}
352+
isCompact={isCompact}
349353
/>
350354
)}
351355
{!isLoading && actions && <ResponseActions actions={actions} />}
@@ -355,6 +359,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
355359
<QuickResponse
356360
quickResponses={quickResponses}
357361
quickResponseContainerProps={quickResponseContainerProps}
362+
isCompact={isCompact}
358363
/>
359364
)}
360365
</div>

packages/module/src/Message/QuickResponse/QuickResponse.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export interface QuickResponseProps {
1515
quickResponseContainerProps?: Omit<LabelGroupProps, 'ref'>;
1616
/** Callback when a response is clicked; used in feedback cards */
1717
onSelect?: (id: string) => void;
18+
/** Sets the quick responses to compact styling */
19+
isCompact?: boolean;
1820
}
1921

2022
export const QuickResponse: React.FunctionComponent<QuickResponseProps> = ({
2123
quickResponses,
2224
quickResponseContainerProps = { numLabels: 5 },
23-
onSelect
25+
onSelect,
26+
isCompact
2427
}: QuickResponseProps) => {
2528
const [selectedQuickResponse, setSelectedQuickResponse] = React.useState<string>();
2629

@@ -42,6 +45,7 @@ export const QuickResponse: React.FunctionComponent<QuickResponseProps> = ({
4245
key={id}
4346
onClick={() => handleQuickResponseClick(id, onClick)}
4447
className={`${id === selectedQuickResponse ? 'pf-chatbot__message-quick-response--selected' : ''} ${className ? className : ''}`}
48+
isCompact={isCompact}
4549
{...props}
4650
>
4751
{content}

packages/module/src/Message/QuickStarts/QuickStartTile.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface QuickStartTileProps {
4949
prerequisiteWordPlural?: string;
5050
/** Aria-label for the quick start description button */
5151
quickStartButtonAriaLabel?: string;
52+
/** Sets the tile to compact styling */
53+
isCompact?: boolean;
5254
}
5355

5456
const QuickStartTile: React.FC<QuickStartTileProps> = ({
@@ -61,7 +63,8 @@ const QuickStartTile: React.FC<QuickStartTileProps> = ({
6163
prerequisiteWord,
6264
prerequisiteWordPlural,
6365
quickStartButtonAriaLabel,
64-
action
66+
action,
67+
isCompact
6568
}) => {
6669
const {
6770
metadata: { name: id },
@@ -105,6 +108,7 @@ const QuickStartTile: React.FC<QuickStartTileProps> = ({
105108
id={`${id}-chatbot-qs-tile`}
106109
style={{ height: '100%' }}
107110
data-testid={`chatbot-qs-card-${camelize(displayName)}`}
111+
isCompact={isCompact}
108112
>
109113
<CardHeader
110114
{...(action && {

packages/module/src/SourcesCard/SourcesCard.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@
7474
}
7575
}
7676
}
77+
78+
.pf-v6-c-card.pf-m-compact.pf-chatbot__sources-card {
79+
.pf-v6-c-card__footer.pf-chatbot__sources-card-footer-container {
80+
border-top: var(--pf-t--global--border--width--regular) solid var(--pf-t--global--border--color--default);
81+
padding: var(--pf-t--global--spacer--xs) var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--xs)
82+
var(--pf-t--global--spacer--xs) !important;
83+
}
84+
}

packages/module/src/SourcesCard/SourcesCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
7171
onSetPage,
7272
showMoreWords = 'show more',
7373
showLessWords = 'show less',
74+
isCompact,
7475
...props
7576
}: SourcesCardProps) => {
7677
const [page, setPage] = React.useState(1);
@@ -95,7 +96,7 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
9596
return (
9697
<div className="pf-chatbot__source">
9798
<span>{pluralize(sources.length, sourceWord, sourceWordPlural)}</span>
98-
<Card className="pf-chatbot__sources-card" {...props}>
99+
<Card isCompact={isCompact} className="pf-chatbot__sources-card" {...props}>
99100
<CardTitle className="pf-chatbot__sources-card-title">
100101
<Button
101102
component="a"

0 commit comments

Comments
 (0)