@patternfly/chatbot 6.4.0-prerelease.15 → 6.4.0-prerelease.17

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 (48) hide show
  1. package/dist/cjs/Message/Message.d.ts +3 -0
  2. package/dist/cjs/Message/Message.js +3 -2
  3. package/dist/cjs/Message/Message.test.js +14 -0
  4. package/dist/cjs/SourcesCard/SourcesCard.d.ts +13 -1
  5. package/dist/cjs/SourcesCard/SourcesCard.js +6 -6
  6. package/dist/cjs/SourcesCard/SourcesCard.test.js +49 -0
  7. package/dist/cjs/ToolResponse/ToolResponse.d.ts +30 -0
  8. package/dist/cjs/ToolResponse/ToolResponse.js +18 -0
  9. package/dist/cjs/ToolResponse/ToolResponse.test.d.ts +1 -0
  10. package/dist/cjs/ToolResponse/ToolResponse.test.js +60 -0
  11. package/dist/cjs/ToolResponse/index.d.ts +2 -0
  12. package/dist/cjs/ToolResponse/index.js +23 -0
  13. package/dist/cjs/index.d.ts +2 -0
  14. package/dist/cjs/index.js +4 -1
  15. package/dist/css/main.css +53 -0
  16. package/dist/css/main.css.map +1 -1
  17. package/dist/dynamic/ToolResponse/package.json +1 -0
  18. package/dist/esm/Message/Message.d.ts +3 -0
  19. package/dist/esm/Message/Message.js +3 -2
  20. package/dist/esm/Message/Message.test.js +14 -0
  21. package/dist/esm/SourcesCard/SourcesCard.d.ts +13 -1
  22. package/dist/esm/SourcesCard/SourcesCard.js +6 -6
  23. package/dist/esm/SourcesCard/SourcesCard.test.js +50 -1
  24. package/dist/esm/ToolResponse/ToolResponse.d.ts +30 -0
  25. package/dist/esm/ToolResponse/ToolResponse.js +14 -0
  26. package/dist/esm/ToolResponse/ToolResponse.test.d.ts +1 -0
  27. package/dist/esm/ToolResponse/ToolResponse.test.js +55 -0
  28. package/dist/esm/ToolResponse/index.d.ts +2 -0
  29. package/dist/esm/ToolResponse/index.js +2 -0
  30. package/dist/esm/index.d.ts +2 -0
  31. package/dist/esm/index.js +2 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +2 -2
  34. package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx +70 -0
  35. package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolResponse.tsx +135 -0
  36. package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +9 -1
  37. package/patternfly-docs/patternfly-docs.config.js +1 -1
  38. package/src/Message/Message.test.tsx +22 -0
  39. package/src/Message/Message.tsx +5 -0
  40. package/src/SourcesCard/SourcesCard.scss +17 -0
  41. package/src/SourcesCard/SourcesCard.test.tsx +93 -0
  42. package/src/SourcesCard/SourcesCard.tsx +116 -80
  43. package/src/ToolResponse/ToolResponse.scss +36 -0
  44. package/src/ToolResponse/ToolResponse.test.tsx +78 -0
  45. package/src/ToolResponse/ToolResponse.tsx +95 -0
  46. package/src/ToolResponse/index.ts +3 -0
  47. package/src/index.ts +3 -0
  48. package/src/main.scss +1 -0
@@ -675,6 +675,28 @@ describe('Message', () => {
675
675
  );
676
676
  expect(screen.getAllByRole('img')[1]).toHaveAttribute('src', 'test.png');
677
677
  });
678
+ it('should handle tool response correctly', async () => {
679
+ render(
680
+ <Message
681
+ avatar="./img"
682
+ role="user"
683
+ name="User"
684
+ content="Hi"
685
+ toolResponse={{
686
+ toggleContent: 'Tool response: Name',
687
+ subheading: 'Thought for 3 seconds',
688
+ body: 'Lorem ipsum dolor sit amet',
689
+ cardTitle: 'Card title',
690
+ cardBody: 'Card body'
691
+ }}
692
+ />
693
+ );
694
+ expect(screen.getByRole('button', { name: /Tool response: Name/i })).toBeTruthy();
695
+ expect(screen.getByText('Thought for 3 seconds')).toBeTruthy();
696
+ expect(screen.getByText('Lorem ipsum dolor sit amet')).toBeTruthy();
697
+ expect(screen.getByText('Card title')).toBeTruthy();
698
+ expect(screen.getByText('Card body')).toBeTruthy();
699
+ });
678
700
  it('should handle block quote correctly', () => {
679
701
  render(<Message avatar="./img" role="user" name="User" content={BLOCK_QUOTES} />);
680
702
  expect(screen.getByText(/Blockquotes can also be nested.../)).toBeTruthy();
@@ -49,6 +49,7 @@ import LinkMessage from './LinkMessage/LinkMessage';
49
49
  import ErrorMessage from './ErrorMessage/ErrorMessage';
50
50
  import MessageInput from './MessageInput';
51
51
  import { rehypeMoveImagesOutOfParagraphs } from './Plugins/rehypeMoveImagesOutOfParagraphs';
52
+ import ToolResponse, { ToolResponseProps } from '../ToolResponse';
52
53
 
53
54
  export interface MessageAttachment {
54
55
  /** Name of file attached to the message */
@@ -189,6 +190,8 @@ export interface MessageProps extends Omit<HTMLProps<HTMLDivElement>, 'role'> {
189
190
  isMarkdownDisabled?: boolean;
190
191
  /** Allows passing additional props down to markdown parser react-markdown, such as allowedElements and disallowedElements. See https://github.com/remarkjs/react-markdown?tab=readme-ov-file#options for options */
191
192
  reactMarkdownProps?: Options;
193
+ /** Props for tool response card */
194
+ toolResponse?: ToolResponseProps;
192
195
  }
193
196
 
194
197
  export const MessageBase: FunctionComponent<MessageProps> = ({
@@ -230,6 +233,7 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
230
233
  isCompact,
231
234
  isMarkdownDisabled,
232
235
  reactMarkdownProps,
236
+ toolResponse,
233
237
  ...props
234
238
  }: MessageProps) => {
235
239
  const [messageText, setMessageText] = useState(content);
@@ -376,6 +380,7 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
376
380
  <div className="pf-chatbot__message-and-actions">
377
381
  {renderMessage()}
378
382
  {afterMainContent && <>{afterMainContent}</>}
383
+ {toolResponse && <ToolResponse {...toolResponse} />}
379
384
  {!isLoading && sources && <SourcesCard {...sources} isCompact={isCompact} />}
380
385
  {quickStarts && quickStarts.quickStart && (
381
386
  <QuickStartTile
@@ -16,6 +16,17 @@
16
16
  box-shadow: var(--pf-t--global--box-shadow--sm);
17
17
  }
18
18
 
19
+ .pf-chatbot__compact-sources-card-body {
20
+ --pf-v6-c-card--child--PaddingBlockEnd: var(--pf-t--global--spacer--xs);
21
+ }
22
+
23
+ .pf-chatbot__sources-card-subtitle,
24
+ .pf-chatbot__sources-card-subtle {
25
+ color: var(--pf-t--global--text--color--subtle);
26
+ font-size: var(--pf-t--global--font--size--body--sm);
27
+ font-weight: var(--pf-t--global--font--weight--body--default);
28
+ }
29
+
19
30
  .pf-chatbot__sources-card-body-text {
20
31
  display: block;
21
32
  display: -webkit-box;
@@ -27,6 +38,12 @@
27
38
  text-overflow: ellipsis;
28
39
  }
29
40
 
41
+ .pf-chatbot__sources-card-title-container {
42
+ display: flex;
43
+ flex-direction: column;
44
+ gap: var(--pf-t--global--spacer--xs);
45
+ }
46
+
30
47
  .pf-chatbot__sources-card-footer-container {
31
48
  border-top: var(--pf-t--global--border--width--regular) solid var(--pf-t--global--border--color--default);
32
49
  padding: var(--pf-t--global--spacer--sm) var(--pf-t--global--spacer--md) var(--pf-t--global--spacer--sm)
@@ -256,4 +256,97 @@ describe('SourcesCard', () => {
256
256
  );
257
257
  expect(screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test');
258
258
  });
259
+
260
+ it('should apply cardTitleProps appropriately', () => {
261
+ render(
262
+ <SourcesCard
263
+ cardTitleProps={{ 'data-testid': 'card-title', className: 'test' } as any}
264
+ sources={[{ title: 'How to make an apple pie', link: '' }]}
265
+ />
266
+ );
267
+ expect(screen.getByTestId('card-title')).toHaveClass('test');
268
+ });
269
+
270
+ it('should apply cardBodyProps appropriately', () => {
271
+ render(
272
+ <SourcesCard
273
+ cardBodyProps={
274
+ { 'data-testid': 'card-body', body: 'To make an apple pie, you must first...', className: 'test' } as any
275
+ }
276
+ sources={[{ title: 'How to make an apple pie', link: '', body: 'To make an apple pie, you must first...' }]}
277
+ />
278
+ );
279
+ expect(screen.getByTestId('card-body')).toHaveClass('test');
280
+ });
281
+
282
+ it('should apply cardFooterProps appropriately', () => {
283
+ render(
284
+ <SourcesCard
285
+ cardFooterProps={{ 'data-testid': 'card-footer', className: 'test' } as any}
286
+ sources={[
287
+ { title: 'How to make an apple pie', link: '' },
288
+ { title: 'How to make cookies', link: '' }
289
+ ]}
290
+ />
291
+ );
292
+ expect(screen.getByTestId('card-footer')).toHaveClass('test');
293
+ });
294
+
295
+ it('should apply truncateProps appropriately', () => {
296
+ render(
297
+ <SourcesCard
298
+ sources={[
299
+ {
300
+ title: 'How to make an apple pie',
301
+ link: '',
302
+ truncateProps: { 'data-testid': 'card-truncate', className: 'test' } as any
303
+ }
304
+ ]}
305
+ />
306
+ );
307
+ expect(screen.getByTestId('card-truncate')).toHaveClass('test');
308
+ });
309
+
310
+ it('should apply custom footer appropriately when there is one source', () => {
311
+ render(
312
+ <SourcesCard sources={[{ title: 'How to make an apple pie', link: '', footer: <>I am a custom footer</> }]} />
313
+ );
314
+ expect(screen.getByText('I am a custom footer'));
315
+ expect(screen.queryByText('1/1')).toBeFalsy();
316
+ });
317
+
318
+ it('should apply custom footer appropriately when are multiple sources', () => {
319
+ render(
320
+ <SourcesCard
321
+ sources={[
322
+ { title: 'How to make an apple pie', link: '', footer: <>I am a custom footer</> },
323
+ { title: 'How to bake bread', link: '' }
324
+ ]}
325
+ />
326
+ );
327
+ expect(screen.getByText('I am a custom footer'));
328
+ // does not show navigation bar
329
+ expect(screen.queryByText('1/2')).toBeFalsy();
330
+ });
331
+
332
+ it('should apply footer props to custom footer appropriately', () => {
333
+ render(
334
+ <SourcesCard
335
+ cardFooterProps={{ 'data-testid': 'card-footer', className: 'test' } as any}
336
+ sources={[{ title: 'How to make an apple pie', link: '', footer: <>I am a custom footer</> }]}
337
+ />
338
+ );
339
+ expect(screen.getByText('I am a custom footer'));
340
+ expect(screen.getByTestId('card-footer')).toHaveClass('test');
341
+ });
342
+
343
+ it('should apply subtitle appropriately', () => {
344
+ render(
345
+ <SourcesCard
346
+ sources={[{ title: 'How to make an apple pie', link: '', subtitle: 'You must first create the universe' }]}
347
+ />
348
+ );
349
+ expect(screen.getByText('How to make an apple pie'));
350
+ expect(screen.getByText('You must first create the universe'));
351
+ });
259
352
  });
@@ -10,14 +10,18 @@ import {
10
10
  ButtonVariant,
11
11
  Card,
12
12
  CardBody,
13
+ CardBodyProps,
13
14
  CardFooter,
15
+ CardFooterProps,
14
16
  CardProps,
15
17
  CardTitle,
18
+ CardTitleProps,
16
19
  ExpandableSection,
17
20
  ExpandableSectionVariant,
18
21
  Icon,
19
22
  pluralize,
20
- Truncate
23
+ Truncate,
24
+ TruncateProps
21
25
  } from '@patternfly/react-core';
22
26
  import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
23
27
 
@@ -34,6 +38,8 @@ export interface SourcesCardProps extends CardProps {
34
38
  sources: {
35
39
  /** Title of sources card */
36
40
  title?: string;
41
+ /** Subtitle of sources card */
42
+ subtitle?: string;
37
43
  /** Link to source */
38
44
  link: string;
39
45
  /** Body of sources card */
@@ -46,6 +52,10 @@ export interface SourcesCardProps extends CardProps {
46
52
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
47
53
  /** Any additional props applied to the title of the Sources card */
48
54
  titleProps?: ButtonProps;
55
+ /** Custom footer applied to the Sources card */
56
+ footer?: React.ReactNode;
57
+ /** Additional props passed to Truncate component */
58
+ truncateProps?: TruncateProps;
49
59
  }[];
50
60
  /** Label for the English word "source" */
51
61
  sourceWord?: string;
@@ -65,6 +75,12 @@ export interface SourcesCardProps extends CardProps {
65
75
  showMoreWords?: string;
66
76
  /** Label for English words "show less" */
67
77
  showLessWords?: string;
78
+ /** Additional props passed to card title */
79
+ cardTitleProps?: CardTitleProps;
80
+ /** Additional props passed to card body */
81
+ cardBodyProps?: CardBodyProps;
82
+ /** Additional props passed to card footer */
83
+ cardFooterProps?: CardFooterProps;
68
84
  }
69
85
 
70
86
  const SourcesCard: FunctionComponent<SourcesCardProps> = ({
@@ -82,6 +98,9 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
82
98
  showMoreWords = 'show more',
83
99
  showLessWords = 'show less',
84
100
  isCompact,
101
+ cardTitleProps,
102
+ cardBodyProps,
103
+ cardFooterProps,
85
104
  ...props
86
105
  }: SourcesCardProps) => {
87
106
  const [page, setPage] = useState(1);
@@ -96,9 +115,9 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
96
115
  onSetPage && onSetPage(_evt, newPage);
97
116
  };
98
117
 
99
- const renderTitle = (title?: string) => {
118
+ const renderTitle = (title?: string, truncateProps?: TruncateProps) => {
100
119
  if (title) {
101
- return <Truncate content={title} />;
120
+ return <Truncate content={title} {...truncateProps} />;
102
121
  }
103
122
  return `Source ${page}`;
104
123
  };
@@ -107,24 +126,32 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
107
126
  <div className="pf-chatbot__source">
108
127
  <span>{pluralize(sources.length, sourceWord, sourceWordPlural)}</span>
109
128
  <Card isCompact={isCompact} className="pf-chatbot__sources-card" {...props}>
110
- <CardTitle className="pf-chatbot__sources-card-title">
111
- <Button
112
- component="a"
113
- variant={ButtonVariant.link}
114
- href={sources[page - 1].link}
115
- icon={sources[page - 1].isExternal ? <ExternalLinkSquareAltIcon /> : undefined}
116
- iconPosition="end"
117
- isInline
118
- rel={sources[page - 1].isExternal ? 'noreferrer' : undefined}
119
- target={sources[page - 1].isExternal ? '_blank' : undefined}
120
- onClick={sources[page - 1].onClick ?? undefined}
121
- {...sources[page - 1].titleProps}
122
- >
123
- {renderTitle(sources[page - 1].title)}
124
- </Button>
129
+ <CardTitle className="pf-chatbot__sources-card-title" {...cardTitleProps}>
130
+ <div className="pf-chatbot__sources-card-title-container">
131
+ <Button
132
+ component="a"
133
+ variant={ButtonVariant.link}
134
+ href={sources[page - 1].link}
135
+ icon={sources[page - 1].isExternal ? <ExternalLinkSquareAltIcon /> : undefined}
136
+ iconPosition="end"
137
+ isInline
138
+ rel={sources[page - 1].isExternal ? 'noreferrer' : undefined}
139
+ target={sources[page - 1].isExternal ? '_blank' : undefined}
140
+ onClick={sources[page - 1].onClick ?? undefined}
141
+ {...sources[page - 1].titleProps}
142
+ >
143
+ {renderTitle(sources[page - 1].title, sources[page - 1].truncateProps)}
144
+ </Button>
145
+ {sources[page - 1].subtitle && (
146
+ <span className="pf-chatbot__sources-card-subtitle">{sources[page - 1].subtitle}</span>
147
+ )}
148
+ </div>
125
149
  </CardTitle>
126
150
  {sources[page - 1].body && (
127
- <CardBody className={`pf-chatbot__sources-card-body`}>
151
+ <CardBody
152
+ className={`pf-chatbot__sources-card-body ${sources[page - 1].footer ? 'pf-chatbot__compact-sources-card-body' : undefined}`}
153
+ {...cardBodyProps}
154
+ >
128
155
  {sources[page - 1].hasShowMore ? (
129
156
  // prevents extra VO announcements of button text - parent Message has aria-live
130
157
  <div aria-live="off">
@@ -143,68 +170,77 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
143
170
  )}
144
171
  </CardBody>
145
172
  )}
146
- {sources.length > 1 && (
147
- <CardFooter className="pf-chatbot__sources-card-footer-container">
148
- <div className="pf-chatbot__sources-card-footer">
149
- <nav className={`pf-chatbot__sources-card-footer-buttons ${className}`} aria-label={paginationAriaLabel}>
150
- <Button
151
- variant={ButtonVariant.plain}
152
- isDisabled={isDisabled || page === 1}
153
- data-action="previous"
154
- onClick={(event) => {
155
- const newPage = page >= 1 ? page - 1 : 1;
156
- onPreviousClick && onPreviousClick(event, newPage);
157
- handleNewPage(event, newPage);
158
- }}
159
- aria-label={toPreviousPageAriaLabel}
160
- >
161
- <Icon iconSize="lg">
162
- {/* these are inline because the viewBox that works in a round icon is different than the PatternFly default */}
163
- <svg
164
- className="pf-v6-svg"
165
- viewBox="0 0 280 500"
166
- fill="currentColor"
167
- aria-hidden="true"
168
- role="img"
169
- width="1em"
170
- height="1em"
171
- >
172
- <path d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"></path>
173
- </svg>
174
- </Icon>
175
- </Button>
176
- <span aria-hidden="true">
177
- {page}/{sources.length}
178
- </span>
179
- <Button
180
- variant={ButtonVariant.plain}
181
- isDisabled={isDisabled || page === sources.length}
182
- aria-label={toNextPageAriaLabel}
183
- data-action="next"
184
- onClick={(event) => {
185
- const newPage = page + 1 <= sources.length ? page + 1 : sources.length;
186
- onNextClick && onNextClick(event, newPage);
187
- handleNewPage(event, newPage);
188
- }}
189
- >
190
- <Icon isInline iconSize="lg">
191
- {/* these are inline because the viewBox that works in a round icon is different than the PatternFly default */}
192
- <svg
193
- className="pf-v6-svg"
194
- viewBox="0 0 180 500"
195
- fill="currentColor"
196
- aria-hidden="true"
197
- role="img"
198
- width="1em"
199
- height="1em"
200
- >
201
- <path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path>
202
- </svg>
203
- </Icon>
204
- </Button>
205
- </nav>
206
- </div>
173
+ {sources[page - 1].footer ? (
174
+ <CardFooter className="pf-chatbot__sources-card-footer" {...cardFooterProps}>
175
+ {sources[page - 1].footer}
207
176
  </CardFooter>
177
+ ) : (
178
+ sources.length > 1 && (
179
+ <CardFooter className="pf-chatbot__sources-card-footer-container" {...cardFooterProps}>
180
+ <div className="pf-chatbot__sources-card-footer">
181
+ <nav
182
+ className={`pf-chatbot__sources-card-footer-buttons ${className}`}
183
+ aria-label={paginationAriaLabel}
184
+ >
185
+ <Button
186
+ variant={ButtonVariant.plain}
187
+ isDisabled={isDisabled || page === 1}
188
+ data-action="previous"
189
+ onClick={(event) => {
190
+ const newPage = page >= 1 ? page - 1 : 1;
191
+ onPreviousClick && onPreviousClick(event, newPage);
192
+ handleNewPage(event, newPage);
193
+ }}
194
+ aria-label={toPreviousPageAriaLabel}
195
+ >
196
+ <Icon iconSize="lg">
197
+ {/* these are inline because the viewBox that works in a round icon is different than the PatternFly default */}
198
+ <svg
199
+ className="pf-v6-svg"
200
+ viewBox="0 0 280 500"
201
+ fill="currentColor"
202
+ aria-hidden="true"
203
+ role="img"
204
+ width="1em"
205
+ height="1em"
206
+ >
207
+ <path d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"></path>
208
+ </svg>
209
+ </Icon>
210
+ </Button>
211
+ <span aria-hidden="true">
212
+ {page}/{sources.length}
213
+ </span>
214
+ <Button
215
+ variant={ButtonVariant.plain}
216
+ isDisabled={isDisabled || page === sources.length}
217
+ aria-label={toNextPageAriaLabel}
218
+ data-action="next"
219
+ onClick={(event) => {
220
+ const newPage = page + 1 <= sources.length ? page + 1 : sources.length;
221
+ onNextClick && onNextClick(event, newPage);
222
+ handleNewPage(event, newPage);
223
+ }}
224
+ >
225
+ <Icon isInline iconSize="lg">
226
+ {/* these are inline because the viewBox that works in a round icon is different than the PatternFly default */}
227
+ <svg
228
+ className="pf-v6-svg"
229
+ viewBox="0 0 180 500"
230
+ fill="currentColor"
231
+ aria-hidden="true"
232
+ role="img"
233
+ width="1em"
234
+ height="1em"
235
+ >
236
+ <path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path>
237
+ </svg>
238
+ </Icon>
239
+ </Button>
240
+ </nav>
241
+ </div>
242
+ </CardFooter>
243
+ )
208
244
  )}
209
245
  </Card>
210
246
  </div>
@@ -0,0 +1,36 @@
1
+ .pf-chatbot__tool-response {
2
+ --pf-v6-c-card--BorderColor: var(--pf-t--global--border--color--control--read-only);
3
+ overflow: unset;
4
+ }
5
+
6
+ .pf-chatbot__tool-response-expandable-section {
7
+ --pf-v6-c-expandable-section--Gap: var(--pf-t--global--spacer--xs);
8
+ }
9
+
10
+ .pf-chatbot__tool-response-section {
11
+ display: flex;
12
+ flex-direction: column;
13
+ gap: var(--pf-t--global--spacer--xs);
14
+ }
15
+
16
+ .pf-chatbot__tool-response-subheading {
17
+ font-size: var(--pf-t--global--font--size--body--sm);
18
+ font-weight: var(--pf-t--global--font--weight--body--default);
19
+ color: var(--pf-t--global--text--color--subtle);
20
+ }
21
+
22
+ .pf-chatbot__tool-response-body {
23
+ color: var(--pf-t--global--text--color--subtle);
24
+ margin-block-end: var(--pf-t--global--spacer--xs);
25
+ }
26
+
27
+ .pf-chatbot__tool-response-card {
28
+ --pf-v6-c-card--BorderColor: var(--pf-t--global--border--color--control--read-only);
29
+ --pf-v6-c-card--first-child--PaddingBlockStart: var(--pf-t--global--spacer--sm);
30
+ --pf-v6-c-card__title--not--last-child--PaddingBlockEnd: var(--pf-t--global--spacer--sm);
31
+ --pf-v6-c-card--c-divider--child--PaddingBlockStart: var(--pf-t--global--spacer--sm);
32
+
33
+ .pf-v6-c-divider {
34
+ --pf-v6-c-divider--Color: var(--pf-t--global--border--color--control--read-only);
35
+ }
36
+ }
@@ -0,0 +1,78 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import '@testing-library/jest-dom';
3
+ import ToolResponse from './ToolResponse';
4
+
5
+ describe('ToolResponse', () => {
6
+ const defaultProps = {
7
+ toggleContent: 'Tool response: toolName',
8
+ cardTitle: 'Title',
9
+ cardBody: 'Body'
10
+ };
11
+
12
+ it('should render with required props only', () => {
13
+ render(<ToolResponse {...defaultProps} />);
14
+ expect(screen.getByText('Title')).toBeTruthy();
15
+ expect(screen.getByText('Body')).toBeTruthy();
16
+ expect(screen.getByText('Tool response: toolName')).toBeTruthy();
17
+ });
18
+
19
+ it('should render subheading when provided', () => {
20
+ const subheading = 'Tool execution result';
21
+ render(<ToolResponse {...defaultProps} subheading={subheading} />);
22
+ expect(screen.getByText(subheading)).toBeTruthy();
23
+ });
24
+
25
+ it('should render body content when provided', () => {
26
+ const body = 'This is the tool response body content';
27
+ render(<ToolResponse {...defaultProps} body={body} />);
28
+ expect(screen.getByText(body)).toBeTruthy();
29
+ });
30
+
31
+ it('should render with complex content including React elements', () => {
32
+ const body = (
33
+ <div>
34
+ <p>Complex body content</p>
35
+ <ul>
36
+ <li>Item 1</li>
37
+ <li>Item 2</li>
38
+ </ul>
39
+ </div>
40
+ );
41
+ const cardTitle = <strong>API Response</strong>;
42
+ const cardBody = (
43
+ <div>
44
+ <code>{"{ status: 'success' }"}</code>
45
+ </div>
46
+ );
47
+
48
+ render(<ToolResponse {...defaultProps} body={body} cardTitle={cardTitle} cardBody={cardBody} />);
49
+ expect(screen.getByText('Complex body content')).toBeTruthy();
50
+ expect(screen.getByText('Item 1')).toBeTruthy();
51
+ expect(screen.getByText('Item 2')).toBeTruthy();
52
+ expect(screen.getByText('API Response')).toBeTruthy();
53
+ expect(screen.getByText("{ status: 'success' }")).toBeTruthy();
54
+ });
55
+
56
+ it('should apply custom className from cardProps', () => {
57
+ const { container } = render(
58
+ <ToolResponse {...defaultProps} cardProps={{ className: 'custom-tool-response-class' }} />
59
+ );
60
+ expect(container.querySelector('.custom-tool-response-class')).toBeTruthy();
61
+ });
62
+
63
+ it('should pass through expandableSectionProps', () => {
64
+ render(<ToolResponse {...defaultProps} expandableSectionProps={{ className: 'custom-expandable-class' }} />);
65
+ expect(document.querySelector('.custom-expandable-class')).toBeTruthy();
66
+ });
67
+
68
+ it('should pass through toolResponseCardProps', () => {
69
+ render(<ToolResponse {...defaultProps} toolResponseCardProps={{ className: 'custom-card-class' }} />);
70
+ expect(document.querySelector('.custom-card-class')).toBeTruthy();
71
+ });
72
+
73
+ it('should not render subheading span when subheading is not provided', () => {
74
+ const { container } = render(<ToolResponse {...defaultProps} />);
75
+ const subheadingContainer = container.querySelector('.pf-chatbot__tool-response-subheading');
76
+ expect(subheadingContainer).toBeFalsy();
77
+ });
78
+ });
@@ -0,0 +1,95 @@
1
+ // ============================================================================
2
+ // Tool Response Card
3
+ // ============================================================================
4
+ import {
5
+ Card,
6
+ CardBody,
7
+ CardBodyProps,
8
+ CardProps,
9
+ CardTitle,
10
+ CardTitleProps,
11
+ Divider,
12
+ DividerProps,
13
+ ExpandableSection,
14
+ ExpandableSectionProps
15
+ } from '@patternfly/react-core';
16
+ import { useState, type FunctionComponent } from 'react';
17
+
18
+ export interface ToolResponseProps {
19
+ /** Toggle content shown for expandable section */
20
+ toggleContent: React.ReactNode;
21
+ /** Additional props passed to expandable section */
22
+ expandableSectionProps?: Omit<ExpandableSectionProps, 'ref'>;
23
+ /** Subheading rendered inside expandable section */
24
+ subheading?: string;
25
+ /** Body text rendered inside expandable section */
26
+ body?: React.ReactNode | string;
27
+ /** Content passed into tool response card body */
28
+ cardBody: React.ReactNode;
29
+ /** Content passed into tool response card title */
30
+ cardTitle: React.ReactNode;
31
+ /** Additional props passed to main card */
32
+ cardProps?: CardProps;
33
+ /** Additional props passed to main card body */
34
+ cardBodyProps?: CardBodyProps;
35
+ /** Additional props passed to tool response card */
36
+ toolResponseCardProps?: CardProps;
37
+ /** Additional props passed to tool response card body */
38
+ toolResponseCardBodyProps?: CardBodyProps;
39
+ /** Additional props passed to tool response card divider */
40
+ toolResponseCardDividerProps?: DividerProps;
41
+ /** Additional props passed to tool response card title */
42
+ toolResponseCardTitleProps?: CardTitleProps;
43
+ }
44
+
45
+ export const ToolResponse: FunctionComponent<ToolResponseProps> = ({
46
+ body,
47
+ cardProps,
48
+ expandableSectionProps,
49
+ subheading,
50
+ cardBody,
51
+ cardTitle,
52
+ cardBodyProps,
53
+ toggleContent,
54
+ toolResponseCardBodyProps,
55
+ toolResponseCardDividerProps,
56
+ toolResponseCardProps,
57
+ toolResponseCardTitleProps
58
+ }: ToolResponseProps) => {
59
+ const [isExpanded, setIsExpanded] = useState(true);
60
+
61
+ const onToggle = (_event: React.MouseEvent, isExpanded: boolean) => {
62
+ setIsExpanded(isExpanded);
63
+ };
64
+
65
+ return (
66
+ <Card isCompact className="pf-chatbot__tool-response" {...cardProps}>
67
+ <CardBody {...cardBodyProps}>
68
+ <ExpandableSection
69
+ toggleContent={toggleContent}
70
+ onToggle={onToggle}
71
+ isExpanded={isExpanded}
72
+ isIndented
73
+ className="pf-chatbot__tool-response-expandable-section"
74
+ {...expandableSectionProps}
75
+ >
76
+ <div className="pf-chatbot__tool-response-section">
77
+ {subheading && (
78
+ <div className="pf-chatbot__tool-response-subheading">
79
+ <span>{subheading}</span>
80
+ </div>
81
+ )}
82
+ {body && <div className="pf-chatbot__tool-response-body">{body}</div>}
83
+ <Card isCompact className="pf-chatbot__tool-response-card" {...toolResponseCardProps}>
84
+ <CardTitle {...toolResponseCardTitleProps}>{cardTitle}</CardTitle>
85
+ <Divider {...toolResponseCardDividerProps} />
86
+ <CardBody {...toolResponseCardBodyProps}>{cardBody}</CardBody>
87
+ </Card>
88
+ </div>
89
+ </ExpandableSection>
90
+ </CardBody>
91
+ </Card>
92
+ );
93
+ };
94
+
95
+ export default ToolResponse;
@@ -0,0 +1,3 @@
1
+ export { default } from './ToolResponse';
2
+
3
+ export * from './ToolResponse';
package/src/index.ts CHANGED
@@ -84,5 +84,8 @@ export * from './SourcesCard';
84
84
  export { default as TermsOfUse } from './TermsOfUse';
85
85
  export * from './TermsOfUse';
86
86
 
87
+ export { default as ToolResponse } from './ToolResponse';
88
+ export * from './ToolResponse';
89
+
87
90
  export { default as tracking } from './tracking';
88
91
  export * from './tracking';