@patternfly/chatbot 2.2.0-prerelease.23 → 2.2.0-prerelease.24
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/MessageBar/MessageBar.d.ts +4 -4
- package/dist/cjs/MessageBar/MessageBar.js +2 -2
- package/dist/cjs/MessageBar/MessageBar.test.js +8 -0
- package/dist/esm/MessageBar/MessageBar.d.ts +4 -4
- package/dist/esm/MessageBar/MessageBar.js +2 -2
- package/dist/esm/MessageBar/MessageBar.test.js +8 -0
- package/package.json +1 -1
- package/src/MessageBar/MessageBar.test.tsx +8 -0
- package/src/MessageBar/MessageBar.tsx +6 -5
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { ButtonProps, DropEvent } from '@patternfly/react-core';
|
2
|
+
import { ButtonProps, DropEvent, TextAreaProps } from '@patternfly/react-core';
|
3
3
|
import { ChatbotDisplayMode } from '../Chatbot';
|
4
4
|
export interface MessageBarWithAttachMenuProps {
|
5
5
|
/** Flag to enable whether attach menu is open */
|
@@ -21,9 +21,9 @@ export interface MessageBarWithAttachMenuProps {
|
|
21
21
|
/** Callback to change the open state of the menu. Triggered by clicking outside of the menu. */
|
22
22
|
onAttachMenuOpenChange?: (isOpen: boolean) => void;
|
23
23
|
}
|
24
|
-
export interface MessageBarProps {
|
24
|
+
export interface MessageBarProps extends TextAreaProps {
|
25
25
|
/** Callback to get the value of input message by user */
|
26
|
-
onSendMessage: (message: string) => void;
|
26
|
+
onSendMessage: (message: string | number) => void;
|
27
27
|
/** Class Name for the MessageBar component */
|
28
28
|
className?: string;
|
29
29
|
/** Flag to always to show the send button. By default send button is shown when there is a message in the input field */
|
@@ -67,7 +67,7 @@ export interface MessageBarProps {
|
|
67
67
|
};
|
68
68
|
};
|
69
69
|
/** A callback for when the text area value changes. */
|
70
|
-
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => void;
|
70
|
+
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
|
71
71
|
/** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
|
72
72
|
displayMode?: ChatbotDisplayMode;
|
73
73
|
}
|
@@ -24,10 +24,10 @@ const AttachButton_1 = require("./AttachButton");
|
|
24
24
|
const AttachMenu_1 = __importDefault(require("../AttachMenu"));
|
25
25
|
const StopButton_1 = __importDefault(require("./StopButton"));
|
26
26
|
const MessageBar = (_a) => {
|
27
|
-
var { onSendMessage, className, alwayShowSendButton, hasAttachButton = true, hasMicrophoneButton, handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode"]);
|
27
|
+
var { onSendMessage, className, alwayShowSendButton, hasAttachButton = true, hasMicrophoneButton, handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
|
28
28
|
// Text Input
|
29
29
|
// --------------------------------------------------------------------------
|
30
|
-
const [message, setMessage] = react_1.default.useState('');
|
30
|
+
const [message, setMessage] = react_1.default.useState(value !== null && value !== void 0 ? value : '');
|
31
31
|
const [isListeningMessage, setIsListeningMessage] = react_1.default.useState(false);
|
32
32
|
const [hasSentMessage, setHasSentMessage] = react_1.default.useState(false);
|
33
33
|
const textareaRef = react_1.default.useRef(null);
|
@@ -234,4 +234,12 @@ describe('Message bar', () => {
|
|
234
234
|
(0, react_2.render)(react_1.default.createElement(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { props: { 'aria-label': 'Test' } } } }));
|
235
235
|
yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Test' }));
|
236
236
|
}));
|
237
|
+
it('can be controlled', () => {
|
238
|
+
(0, react_2.render)(react_1.default.createElement(MessageBar_1.MessageBar, { onSendMessage: jest.fn, value: "test" }));
|
239
|
+
expect(react_2.screen.getByRole('button', { name: 'Attach button' })).toBeTruthy();
|
240
|
+
expect(react_2.screen.getByRole('button', { name: 'Send button' })).toBeTruthy();
|
241
|
+
expect(react_2.screen.queryByRole('button', { name: 'Microphone button' })).toBeFalsy();
|
242
|
+
expect(react_2.screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
|
243
|
+
expect(react_2.screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
|
244
|
+
});
|
237
245
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { ButtonProps, DropEvent } from '@patternfly/react-core';
|
2
|
+
import { ButtonProps, DropEvent, TextAreaProps } from '@patternfly/react-core';
|
3
3
|
import { ChatbotDisplayMode } from '../Chatbot';
|
4
4
|
export interface MessageBarWithAttachMenuProps {
|
5
5
|
/** Flag to enable whether attach menu is open */
|
@@ -21,9 +21,9 @@ export interface MessageBarWithAttachMenuProps {
|
|
21
21
|
/** Callback to change the open state of the menu. Triggered by clicking outside of the menu. */
|
22
22
|
onAttachMenuOpenChange?: (isOpen: boolean) => void;
|
23
23
|
}
|
24
|
-
export interface MessageBarProps {
|
24
|
+
export interface MessageBarProps extends TextAreaProps {
|
25
25
|
/** Callback to get the value of input message by user */
|
26
|
-
onSendMessage: (message: string) => void;
|
26
|
+
onSendMessage: (message: string | number) => void;
|
27
27
|
/** Class Name for the MessageBar component */
|
28
28
|
className?: string;
|
29
29
|
/** Flag to always to show the send button. By default send button is shown when there is a message in the input field */
|
@@ -67,7 +67,7 @@ export interface MessageBarProps {
|
|
67
67
|
};
|
68
68
|
};
|
69
69
|
/** A callback for when the text area value changes. */
|
70
|
-
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => void;
|
70
|
+
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
|
71
71
|
/** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
|
72
72
|
displayMode?: ChatbotDisplayMode;
|
73
73
|
}
|
@@ -18,10 +18,10 @@ import { AttachButton } from './AttachButton';
|
|
18
18
|
import AttachMenu from '../AttachMenu';
|
19
19
|
import StopButton from './StopButton';
|
20
20
|
export const MessageBar = (_a) => {
|
21
|
-
var { onSendMessage, className, alwayShowSendButton, hasAttachButton = true, hasMicrophoneButton, handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode"]);
|
21
|
+
var { onSendMessage, className, alwayShowSendButton, hasAttachButton = true, hasMicrophoneButton, handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
|
22
22
|
// Text Input
|
23
23
|
// --------------------------------------------------------------------------
|
24
|
-
const [message, setMessage] = React.useState('');
|
24
|
+
const [message, setMessage] = React.useState(value !== null && value !== void 0 ? value : '');
|
25
25
|
const [isListeningMessage, setIsListeningMessage] = React.useState(false);
|
26
26
|
const [hasSentMessage, setHasSentMessage] = React.useState(false);
|
27
27
|
const textareaRef = React.useRef(null);
|
@@ -229,4 +229,12 @@ describe('Message bar', () => {
|
|
229
229
|
render(React.createElement(MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { props: { 'aria-label': 'Test' } } } }));
|
230
230
|
yield userEvent.click(screen.getByRole('button', { name: 'Test' }));
|
231
231
|
}));
|
232
|
+
it('can be controlled', () => {
|
233
|
+
render(React.createElement(MessageBar, { onSendMessage: jest.fn, value: "test" }));
|
234
|
+
expect(screen.getByRole('button', { name: 'Attach button' })).toBeTruthy();
|
235
|
+
expect(screen.getByRole('button', { name: 'Send button' })).toBeTruthy();
|
236
|
+
expect(screen.queryByRole('button', { name: 'Microphone button' })).toBeFalsy();
|
237
|
+
expect(screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
|
238
|
+
expect(screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
|
239
|
+
});
|
232
240
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@patternfly/chatbot",
|
3
|
-
"version": "2.2.0-prerelease.
|
3
|
+
"version": "2.2.0-prerelease.24",
|
4
4
|
"description": "This library provides React components based on PatternFly 6 that can be used to build chatbots.",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -315,4 +315,12 @@ describe('Message bar', () => {
|
|
315
315
|
);
|
316
316
|
await userEvent.click(screen.getByRole('button', { name: 'Test' }));
|
317
317
|
});
|
318
|
+
it('can be controlled', () => {
|
319
|
+
render(<MessageBar onSendMessage={jest.fn} value="test" />);
|
320
|
+
expect(screen.getByRole('button', { name: 'Attach button' })).toBeTruthy();
|
321
|
+
expect(screen.getByRole('button', { name: 'Send button' })).toBeTruthy();
|
322
|
+
expect(screen.queryByRole('button', { name: 'Microphone button' })).toBeFalsy();
|
323
|
+
expect(screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
|
324
|
+
expect(screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
|
325
|
+
});
|
318
326
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { ButtonProps, DropEvent, TextArea } from '@patternfly/react-core';
|
2
|
+
import { ButtonProps, DropEvent, TextArea, TextAreaProps } from '@patternfly/react-core';
|
3
3
|
|
4
4
|
// Import Chatbot components
|
5
5
|
import SendButton from './SendButton';
|
@@ -30,9 +30,9 @@ export interface MessageBarWithAttachMenuProps {
|
|
30
30
|
onAttachMenuOpenChange?: (isOpen: boolean) => void;
|
31
31
|
}
|
32
32
|
|
33
|
-
export interface MessageBarProps {
|
33
|
+
export interface MessageBarProps extends TextAreaProps {
|
34
34
|
/** Callback to get the value of input message by user */
|
35
|
-
onSendMessage: (message: string) => void;
|
35
|
+
onSendMessage: (message: string | number) => void;
|
36
36
|
/** Class Name for the MessageBar component */
|
37
37
|
className?: string;
|
38
38
|
/** Flag to always to show the send button. By default send button is shown when there is a message in the input field */
|
@@ -63,7 +63,7 @@ export interface MessageBarProps {
|
|
63
63
|
};
|
64
64
|
};
|
65
65
|
/** A callback for when the text area value changes. */
|
66
|
-
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => void;
|
66
|
+
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
|
67
67
|
/** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
|
68
68
|
displayMode?: ChatbotDisplayMode;
|
69
69
|
}
|
@@ -82,11 +82,12 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
|
|
82
82
|
buttonProps,
|
83
83
|
onChange,
|
84
84
|
displayMode,
|
85
|
+
value,
|
85
86
|
...props
|
86
87
|
}: MessageBarProps) => {
|
87
88
|
// Text Input
|
88
89
|
// --------------------------------------------------------------------------
|
89
|
-
const [message, setMessage] = React.useState<string>('');
|
90
|
+
const [message, setMessage] = React.useState<string | number>(value ?? '');
|
90
91
|
const [isListeningMessage, setIsListeningMessage] = React.useState<boolean>(false);
|
91
92
|
const [hasSentMessage, setHasSentMessage] = React.useState(false);
|
92
93
|
const textareaRef = React.useRef<HTMLTextAreaElement>(null);
|