@patternfly/chatbot 6.5.0-prerelease.26 → 6.5.0-prerelease.28
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.
- package/dist/cjs/MarkdownContent/MarkdownContent.d.ts +7 -2
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.d.ts +15 -1
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.js +5 -3
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.test.d.ts +1 -0
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.test.js +30 -0
- package/dist/cjs/Message/Message.d.ts +2 -0
- package/dist/cjs/Message/Message.js +5 -5
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.d.ts +14 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.js +22 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAndActions/MessageAndActions.test.js +25 -0
- package/dist/cjs/Message/MessageAndActions/index.d.ts +1 -0
- package/dist/cjs/Message/MessageAndActions/index.js +17 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.d.ts +13 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.js +22 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentItem.test.js +25 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.d.ts +13 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.js +22 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.test.d.ts +1 -0
- package/dist/cjs/Message/MessageAttachments/MessageAttachmentsContainer.test.js +25 -0
- package/dist/cjs/Message/MessageAttachments/index.d.ts +2 -0
- package/dist/cjs/Message/MessageAttachments/index.js +18 -0
- package/dist/cjs/Message/MessageInput.d.ts +1 -1
- package/dist/cjs/Message/MessageInput.js +3 -1
- package/dist/cjs/Message/MessageLoading.d.ts +13 -4
- package/dist/cjs/Message/MessageLoading.js +19 -5
- package/dist/cjs/Message/MessageLoading.test.d.ts +1 -0
- package/dist/cjs/Message/MessageLoading.test.js +25 -0
- package/dist/cjs/Message/QuickResponse/QuickResponse.js +3 -2
- package/dist/cjs/Message/QuickResponse/QuickResponse.test.d.ts +1 -0
- package/dist/cjs/Message/QuickResponse/QuickResponse.test.js +109 -0
- package/dist/cjs/Message/QuickResponse/index.d.ts +1 -0
- package/dist/cjs/Message/QuickResponse/index.js +17 -0
- package/dist/cjs/Message/QuickStarts/QuickStartTile.d.ts +1 -1
- package/dist/cjs/Message/QuickStarts/QuickStartTile.js +3 -2
- package/dist/cjs/Message/QuickStarts/index.d.ts +2 -0
- package/dist/cjs/Message/QuickStarts/index.js +18 -0
- package/dist/cjs/Message/UserFeedback/UserFeedback.d.ts +1 -1
- package/dist/cjs/Message/UserFeedback/UserFeedback.js +3 -1
- package/dist/cjs/Message/UserFeedback/UserFeedbackComplete.d.ts +1 -1
- package/dist/cjs/Message/UserFeedback/UserFeedbackComplete.js +3 -2
- package/dist/cjs/Message/UserFeedback/index.d.ts +2 -0
- package/dist/cjs/Message/UserFeedback/index.js +18 -0
- package/dist/cjs/Message/index.d.ts +8 -0
- package/dist/cjs/Message/index.js +8 -0
- package/dist/cjs/ResponseActions/ResponseActions.d.ts +4 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.d.ts +13 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.js +22 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.test.d.ts +1 -0
- package/dist/cjs/ResponseActions/ResponseActionsGroups.test.js +25 -0
- package/dist/cjs/ResponseActions/index.d.ts +1 -0
- package/dist/cjs/ResponseActions/index.js +1 -0
- package/dist/css/main.css +2 -0
- package/dist/css/main.css.map +1 -1
- package/dist/esm/MarkdownContent/MarkdownContent.d.ts +7 -2
- package/dist/esm/Message/ErrorMessage/ErrorMessage.d.ts +15 -1
- package/dist/esm/Message/ErrorMessage/ErrorMessage.js +3 -3
- package/dist/esm/Message/ErrorMessage/ErrorMessage.test.d.ts +1 -0
- package/dist/esm/Message/ErrorMessage/ErrorMessage.test.js +25 -0
- package/dist/esm/Message/Message.d.ts +2 -0
- package/dist/esm/Message/Message.js +5 -5
- package/dist/esm/Message/MessageAndActions/MessageAndActions.d.ts +14 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.js +18 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.test.d.ts +1 -0
- package/dist/esm/Message/MessageAndActions/MessageAndActions.test.js +20 -0
- package/dist/esm/Message/MessageAndActions/index.d.ts +1 -0
- package/dist/esm/Message/MessageAndActions/index.js +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.d.ts +13 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.js +18 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.test.d.ts +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentItem.test.js +20 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.d.ts +13 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.js +18 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.test.d.ts +1 -0
- package/dist/esm/Message/MessageAttachments/MessageAttachmentsContainer.test.js +20 -0
- package/dist/esm/Message/MessageAttachments/index.d.ts +2 -0
- package/dist/esm/Message/MessageAttachments/index.js +2 -0
- package/dist/esm/Message/MessageInput.d.ts +1 -1
- package/dist/esm/Message/MessageInput.js +1 -1
- package/dist/esm/Message/MessageLoading.d.ts +13 -4
- package/dist/esm/Message/MessageLoading.js +16 -4
- package/dist/esm/Message/MessageLoading.test.d.ts +1 -0
- package/dist/esm/Message/MessageLoading.test.js +20 -0
- package/dist/esm/Message/QuickResponse/QuickResponse.js +3 -2
- package/dist/esm/Message/QuickResponse/QuickResponse.test.d.ts +1 -0
- package/dist/esm/Message/QuickResponse/QuickResponse.test.js +104 -0
- package/dist/esm/Message/QuickResponse/index.d.ts +1 -0
- package/dist/esm/Message/QuickResponse/index.js +1 -0
- package/dist/esm/Message/QuickStarts/QuickStartTile.d.ts +1 -1
- package/dist/esm/Message/QuickStarts/QuickStartTile.js +1 -1
- package/dist/esm/Message/QuickStarts/index.d.ts +2 -0
- package/dist/esm/Message/QuickStarts/index.js +2 -0
- package/dist/esm/Message/UserFeedback/UserFeedback.d.ts +1 -1
- package/dist/esm/Message/UserFeedback/UserFeedback.js +1 -1
- package/dist/esm/Message/UserFeedback/UserFeedbackComplete.d.ts +1 -1
- package/dist/esm/Message/UserFeedback/UserFeedbackComplete.js +1 -2
- package/dist/esm/Message/UserFeedback/index.d.ts +2 -0
- package/dist/esm/Message/UserFeedback/index.js +2 -0
- package/dist/esm/Message/index.d.ts +8 -0
- package/dist/esm/Message/index.js +8 -0
- package/dist/esm/ResponseActions/ResponseActions.d.ts +4 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.d.ts +13 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.js +18 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.test.d.ts +1 -0
- package/dist/esm/ResponseActions/ResponseActionsGroups.test.js +20 -0
- package/dist/esm/ResponseActions/index.d.ts +1 -0
- package/dist/esm/ResponseActions/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithCustomStructure.tsx +102 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +55 -10
- package/src/MarkdownContent/MarkdownContent.tsx +7 -2
- package/src/Message/CodeBlockMessage/CodeBlockMessage.scss +1 -0
- package/src/Message/ErrorMessage/ErrorMessage.test.tsx +38 -0
- package/src/Message/ErrorMessage/ErrorMessage.tsx +17 -2
- package/src/Message/Message.tsx +75 -64
- package/src/Message/MessageAndActions/MessageAndActions.test.tsx +23 -0
- package/src/Message/MessageAndActions/MessageAndActions.tsx +22 -0
- package/src/Message/MessageAndActions/index.ts +1 -0
- package/src/Message/MessageAttachments/MessageAttachmentItem.test.tsx +23 -0
- package/src/Message/MessageAttachments/MessageAttachmentItem.tsx +25 -0
- package/src/Message/MessageAttachments/MessageAttachmentsContainer.test.tsx +23 -0
- package/src/Message/MessageAttachments/MessageAttachmentsContainer.tsx +25 -0
- package/src/Message/MessageAttachments/index.ts +2 -0
- package/src/Message/MessageInput.tsx +1 -1
- package/src/Message/MessageLoading.test.tsx +23 -0
- package/src/Message/MessageLoading.tsx +17 -2
- package/src/Message/QuickResponse/QuickResponse.test.tsx +131 -0
- package/src/Message/QuickResponse/QuickResponse.tsx +3 -2
- package/src/Message/QuickResponse/index.ts +1 -0
- package/src/Message/QuickStarts/QuickStartTile.tsx +1 -1
- package/src/Message/QuickStarts/index.ts +2 -0
- package/src/Message/UserFeedback/UserFeedback.tsx +1 -1
- package/src/Message/UserFeedback/UserFeedbackComplete.tsx +1 -4
- package/src/Message/UserFeedback/index.ts +2 -0
- package/src/Message/index.ts +8 -0
- package/src/ResponseActions/ResponseActions.tsx +6 -0
- package/src/ResponseActions/ResponseActionsGroups.test.tsx +23 -0
- package/src/ResponseActions/ResponseActionsGroups.tsx +28 -0
- package/src/ResponseActions/index.ts +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import MessageAttachmentsContainer from './MessageAttachmentsContainer';
|
|
4
|
+
|
|
5
|
+
test('Renders with children', () => {
|
|
6
|
+
render(<MessageAttachmentsContainer>Test content</MessageAttachmentsContainer>);
|
|
7
|
+
expect(screen.getByText('Test content')).toBeInTheDocument();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Renders with pf-chatbot__message-attachments-container class by default', () => {
|
|
11
|
+
render(<MessageAttachmentsContainer>Test content</MessageAttachmentsContainer>);
|
|
12
|
+
expect(screen.getByText('Test content')).toHaveClass('pf-chatbot__message-attachments-container', { exact: true });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('Renders with custom className', () => {
|
|
16
|
+
render(<MessageAttachmentsContainer className="custom-class">Test content</MessageAttachmentsContainer>);
|
|
17
|
+
expect(screen.getByText('Test content')).toHaveClass('custom-class');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('Spreads additional props', () => {
|
|
21
|
+
render(<MessageAttachmentsContainer id="test-id">Test content</MessageAttachmentsContainer>);
|
|
22
|
+
expect(screen.getByText('Test content')).toHaveAttribute('id', 'test-id');
|
|
23
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
|
|
2
|
+
import { css } from '@patternfly/react-styles';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The container to wrap MessageAttachment components. You must wrap any MessageAttachment components in this container.
|
|
6
|
+
* Use this component when passing children to Message to customize its structure.
|
|
7
|
+
*/
|
|
8
|
+
export interface MessageAttachmentsContainerProps extends HTMLProps<HTMLDivElement> {
|
|
9
|
+
/** Content to render inside the attachments container */
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Additional classes applied to the attachments container. */
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MessageAttachmentsContainer: FunctionComponent<MessageAttachmentsContainerProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}) => (
|
|
20
|
+
<div className={css('pf-chatbot__message-attachments-container', className)} {...props}>
|
|
21
|
+
{children}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export default MessageAttachmentsContainer;
|
|
@@ -22,7 +22,7 @@ export interface MessageInputProps extends FormProps {
|
|
|
22
22
|
content?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const MessageInput: FunctionComponent<MessageInputProps> = ({
|
|
25
|
+
export const MessageInput: FunctionComponent<MessageInputProps> = ({
|
|
26
26
|
editPlaceholder = 'Edit prompt message...',
|
|
27
27
|
updateWord = 'Update',
|
|
28
28
|
cancelWord = 'Cancel',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import MessageLoading from './MessageLoading';
|
|
4
|
+
|
|
5
|
+
test('Renders with pf-chatbot__message-loading class by default', () => {
|
|
6
|
+
render(<MessageLoading data-testid="test-id" />);
|
|
7
|
+
expect(screen.getByTestId('test-id')).toHaveClass('pf-chatbot__message-loading', { exact: true });
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Renders with pf-m-primary class when isPrimary is true', () => {
|
|
11
|
+
render(<MessageLoading data-testid="test-id" isPrimary />);
|
|
12
|
+
expect(screen.getByTestId('test-id')).toHaveClass('pf-chatbot__message-loading pf-m-primary');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('Renders loading word when loadingWord is passed', () => {
|
|
16
|
+
render(<MessageLoading loadingWord="Loading message" />);
|
|
17
|
+
expect(screen.getByText('Loading message')).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('Spreads additional props', () => {
|
|
21
|
+
render(<MessageLoading data-testid="test-id" id="custom-id" />);
|
|
22
|
+
expect(screen.getByTestId('test-id')).toHaveAttribute('id', 'custom-id');
|
|
23
|
+
});
|
|
@@ -2,8 +2,23 @@
|
|
|
2
2
|
// Chatbot Main - Message - Processing
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { FunctionComponent } from 'react';
|
|
6
|
+
import type { HTMLProps } from 'react';
|
|
7
|
+
import { css } from '@patternfly/react-styles';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MessageLoading displays a loading animation for messages.
|
|
11
|
+
* Use this component when passing children to Message to show a loading state.
|
|
12
|
+
*/
|
|
13
|
+
export interface MessageLoadingProps extends HTMLProps<HTMLDivElement> {
|
|
14
|
+
/** Text announced to screen readers during loading. */
|
|
15
|
+
loadingWord?: string;
|
|
16
|
+
/** Flag indicating whether primary styling is applied */
|
|
17
|
+
isPrimary?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const MessageLoading: FunctionComponent<MessageLoadingProps> = ({ loadingWord, isPrimary, ...props }) => (
|
|
21
|
+
<div className={css('pf-chatbot__message-loading', isPrimary && 'pf-m-primary')} {...props}>
|
|
7
22
|
<span className="pf-chatbot__message-loading-dots">
|
|
8
23
|
<span className="pf-v6-screen-reader">{loadingWord}</span>
|
|
9
24
|
</span>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import QuickResponse from './QuickResponse';
|
|
5
|
+
|
|
6
|
+
test('Renders with quick responses', () => {
|
|
7
|
+
const quickResponses = [
|
|
8
|
+
{ id: '1', content: 'Response 1' },
|
|
9
|
+
{ id: '2', content: 'Response 2' },
|
|
10
|
+
{ id: '3', content: 'Response 3' }
|
|
11
|
+
];
|
|
12
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
13
|
+
|
|
14
|
+
expect(screen.getByText('Response 1')).toBeVisible();
|
|
15
|
+
expect(screen.getByText('Response 2')).toBeVisible();
|
|
16
|
+
expect(screen.getByText('Response 3')).toBeVisible();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('Renders with compact styling', () => {
|
|
20
|
+
const quickResponses = [{ id: '1', content: 'Compact response' }];
|
|
21
|
+
render(<QuickResponse quickResponses={quickResponses} isCompact />);
|
|
22
|
+
|
|
23
|
+
expect(screen.getByText('Compact response').closest('.pf-v6-c-label')).toHaveClass('pf-m-compact');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Renders with custom className on response', () => {
|
|
27
|
+
const quickResponses = [{ id: '1', content: 'Custom class response', className: 'custom-response-class' }];
|
|
28
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
29
|
+
|
|
30
|
+
expect(screen.getByText('Custom class response').closest('.pf-v6-c-label')).toHaveClass('custom-response-class');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('Renders with custom container className', () => {
|
|
34
|
+
const quickResponses = [
|
|
35
|
+
{ id: '1', content: 'Response 1' },
|
|
36
|
+
{ id: '2', content: 'Response 2' }
|
|
37
|
+
];
|
|
38
|
+
render(
|
|
39
|
+
<QuickResponse
|
|
40
|
+
quickResponses={quickResponses}
|
|
41
|
+
quickResponseContainerProps={{ className: 'custom-container-class' }}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(screen.getByText('Response 1').closest('.pf-v6-c-label-group')).toHaveClass('custom-container-class');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('Spreads additional custom container props', () => {
|
|
49
|
+
const quickResponses = [
|
|
50
|
+
{ id: '1', content: 'Response 1' },
|
|
51
|
+
{ id: '2', content: 'Response 2' }
|
|
52
|
+
];
|
|
53
|
+
render(<QuickResponse quickResponses={quickResponses} quickResponseContainerProps={{ id: 'custom-container-id' }} />);
|
|
54
|
+
|
|
55
|
+
expect(screen.getByText('Response 1').closest('.pf-v6-c-label-group__list')).toHaveAttribute(
|
|
56
|
+
'id',
|
|
57
|
+
'custom-container-id'
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('Renders with pf-chatbot__message-quick-response--selected class after click', async () => {
|
|
62
|
+
const user = userEvent.setup();
|
|
63
|
+
const quickResponses = [
|
|
64
|
+
{ id: '1', content: 'Response 1' },
|
|
65
|
+
{ id: '2', content: 'Response 2' }
|
|
66
|
+
];
|
|
67
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
68
|
+
|
|
69
|
+
await user.click(screen.getByText('Response 1'));
|
|
70
|
+
|
|
71
|
+
expect(screen.getByText('Response 1').closest('.pf-v6-c-label')).toHaveClass(
|
|
72
|
+
'pf-chatbot__message-quick-response--selected'
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('Does not calls onClick handler when not passed', async () => {
|
|
77
|
+
const user = userEvent.setup();
|
|
78
|
+
const handleClick = jest.fn();
|
|
79
|
+
const quickResponses = [{ id: '1', content: 'Clickable response' }];
|
|
80
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
81
|
+
|
|
82
|
+
await user.click(screen.getByText('Clickable response'));
|
|
83
|
+
|
|
84
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('Calls onClick handler when passed', async () => {
|
|
88
|
+
const user = userEvent.setup();
|
|
89
|
+
const handleClick = jest.fn();
|
|
90
|
+
const quickResponses = [{ id: '1', content: 'Clickable response', onClick: handleClick }];
|
|
91
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
92
|
+
|
|
93
|
+
await user.click(screen.getByText('Clickable response'));
|
|
94
|
+
|
|
95
|
+
expect(handleClick).toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('Does not call onSelect when not passed', async () => {
|
|
99
|
+
const user = userEvent.setup();
|
|
100
|
+
const handleSelect = jest.fn();
|
|
101
|
+
const quickResponses = [
|
|
102
|
+
{ id: '1', content: 'Response 1' },
|
|
103
|
+
{ id: '2', content: 'Response 2' }
|
|
104
|
+
];
|
|
105
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
106
|
+
|
|
107
|
+
await user.click(screen.getByText('Response 2'));
|
|
108
|
+
|
|
109
|
+
expect(handleSelect).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('Calls onSelect when passed', async () => {
|
|
113
|
+
const user = userEvent.setup();
|
|
114
|
+
const handleSelect = jest.fn();
|
|
115
|
+
const quickResponses = [
|
|
116
|
+
{ id: '1', content: 'Response 1' },
|
|
117
|
+
{ id: '2', content: 'Response 2' }
|
|
118
|
+
];
|
|
119
|
+
render(<QuickResponse quickResponses={quickResponses} onSelect={handleSelect} />);
|
|
120
|
+
|
|
121
|
+
await user.click(screen.getByText('Response 2'));
|
|
122
|
+
|
|
123
|
+
expect(handleSelect).toHaveBeenCalledWith('2');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('Spreads additional response props', () => {
|
|
127
|
+
const quickResponses = [{ id: '1', content: 'Response with props', isCompact: true, 'aria-label': 'Test label' }];
|
|
128
|
+
render(<QuickResponse quickResponses={quickResponses} />);
|
|
129
|
+
|
|
130
|
+
expect(screen.getByText('Response with props').closest('.pf-v6-c-label')).toHaveAttribute('aria-label', 'Test label');
|
|
131
|
+
});
|
|
@@ -2,6 +2,7 @@ import type { FunctionComponent } from 'react';
|
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { Label, LabelGroup, LabelGroupProps, LabelProps } from '@patternfly/react-core';
|
|
4
4
|
import { CheckIcon } from '@patternfly/react-icons';
|
|
5
|
+
import { css } from '@patternfly/react-styles';
|
|
5
6
|
|
|
6
7
|
export interface QuickResponse extends Omit<LabelProps, 'children'> {
|
|
7
8
|
content: string;
|
|
@@ -35,7 +36,7 @@ export const QuickResponse: FunctionComponent<QuickResponseProps> = ({
|
|
|
35
36
|
};
|
|
36
37
|
return (
|
|
37
38
|
<LabelGroup
|
|
38
|
-
className={
|
|
39
|
+
className={css('pf-chatbot__message-quick-response', quickResponseContainerProps?.className)}
|
|
39
40
|
{...quickResponseContainerProps}
|
|
40
41
|
>
|
|
41
42
|
{quickResponses.map(({ id, onClick, content, className, ...props }: QuickResponse) => (
|
|
@@ -45,7 +46,7 @@ export const QuickResponse: FunctionComponent<QuickResponseProps> = ({
|
|
|
45
46
|
color="blue"
|
|
46
47
|
key={id}
|
|
47
48
|
onClick={() => handleQuickResponseClick(id, onClick)}
|
|
48
|
-
className={
|
|
49
|
+
className={css(id === selectedQuickResponse && 'pf-chatbot__message-quick-response--selected', className)}
|
|
49
50
|
isCompact={isCompact}
|
|
50
51
|
{...props}
|
|
51
52
|
>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './QuickResponse';
|
|
@@ -78,7 +78,7 @@ export interface UserFeedbackProps extends Omit<CardProps, 'onSubmit'>, OUIAProp
|
|
|
78
78
|
privacyStatement?: string;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const UserFeedback: FunctionComponent<UserFeedbackProps> = ({
|
|
81
|
+
export const UserFeedback: FunctionComponent<UserFeedbackProps> = ({
|
|
82
82
|
className,
|
|
83
83
|
timestamp,
|
|
84
84
|
title = 'Why did you choose this rating?',
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
// Chatbot Main - Messages - Feedback Complete Card
|
|
3
3
|
// ============================================================================
|
|
4
4
|
import type { MouseEvent as ReactMouseEvent, FunctionComponent } from 'react';
|
|
5
|
-
|
|
6
5
|
import { useState, useRef, useEffect } from 'react';
|
|
7
|
-
|
|
8
|
-
// Import PatternFly components
|
|
9
6
|
import { Card, CardBody, CardHeader, CardProps, CardTitle, OUIAProps, useOUIAProps } from '@patternfly/react-core';
|
|
10
7
|
import CloseButton from './CloseButton';
|
|
11
8
|
|
|
@@ -48,7 +45,7 @@ export interface UserFeedbackCompleteProps extends Omit<CardProps, 'ref'>, OUIAP
|
|
|
48
45
|
timestamp?: string;
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
const UserFeedbackComplete: FunctionComponent<UserFeedbackCompleteProps> = ({
|
|
48
|
+
export const UserFeedbackComplete: FunctionComponent<UserFeedbackCompleteProps> = ({
|
|
52
49
|
className,
|
|
53
50
|
title = 'Feedback submitted',
|
|
54
51
|
body = "We've received your response. Thank you for sharing your feedback!",
|
package/src/Message/index.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export { default } from './Message';
|
|
2
2
|
export { rehypeCodeBlockToggle } from './Plugins/rehypeCodeBlockToggle';
|
|
3
3
|
|
|
4
|
+
export * from './ErrorMessage/ErrorMessage';
|
|
5
|
+
export * from './MessageAndActions';
|
|
6
|
+
export * from './MessageAttachments';
|
|
4
7
|
export * from './Message';
|
|
8
|
+
export * from './MessageLoading';
|
|
9
|
+
export * from './MessageInput';
|
|
10
|
+
export * from './QuickResponse';
|
|
11
|
+
export * from './QuickStarts';
|
|
12
|
+
export * from './UserFeedback';
|
|
@@ -42,6 +42,12 @@ export interface ActionProps extends Omit<ButtonProps, 'ref'> {
|
|
|
42
42
|
type ExtendedActionProps = ActionProps & {
|
|
43
43
|
[key: string]: any;
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The various actions that can be attached to a bot message for users to interact with.
|
|
48
|
+
* Use this component when passing children to Message to customize its structure.
|
|
49
|
+
*/
|
|
50
|
+
|
|
45
51
|
export interface ResponseActionProps {
|
|
46
52
|
/** Props for message actions, such as feedback (positive or negative), copy button, share, and listen */
|
|
47
53
|
actions: Record<string, ExtendedActionProps | undefined> & {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import ResponseActionsGroups from './ResponseActionsGroups';
|
|
4
|
+
|
|
5
|
+
test('Renders with children', () => {
|
|
6
|
+
render(<ResponseActionsGroups>Test content</ResponseActionsGroups>);
|
|
7
|
+
expect(screen.getByText('Test content')).toBeInTheDocument();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Renders with pf-chatbot__response-actions-groups class by default', () => {
|
|
11
|
+
render(<ResponseActionsGroups>Test content</ResponseActionsGroups>);
|
|
12
|
+
expect(screen.getByText('Test content')).toHaveClass('pf-chatbot__response-actions-groups', { exact: true });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('Renders with custom className', () => {
|
|
16
|
+
render(<ResponseActionsGroups className="custom-class">Test content</ResponseActionsGroups>);
|
|
17
|
+
expect(screen.getByText('Test content')).toHaveClass('custom-class');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('Spreads additional props', () => {
|
|
21
|
+
render(<ResponseActionsGroups id="test-id">Test content</ResponseActionsGroups>);
|
|
22
|
+
expect(screen.getByText('Test content')).toHaveAttribute('id', 'test-id');
|
|
23
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Response Actions Groups - Container for multiple action groups
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
|
|
5
|
+
import { css } from '@patternfly/react-styles';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The container for grouping multiple related ResponseActions components, typically used for having different persistence states amongst groups.
|
|
9
|
+
* Use this component when passing children to Message to customize its structure.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResponseActionsGroupsProps extends HTMLProps<HTMLDivElement> {
|
|
12
|
+
/** Content to render inside the response actions groups container */
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
/** Additional classes applied to the response actions groups container. */
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ResponseActionsGroups: FunctionComponent<ResponseActionsGroupsProps> = ({
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
...props
|
|
22
|
+
}) => (
|
|
23
|
+
<div className={css('pf-chatbot__response-actions-groups', className)} {...props}>
|
|
24
|
+
{children}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export default ResponseActionsGroups;
|