@patternfly/chatbot 6.3.0-prerelease.1 → 6.3.0-prerelease.2

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.
@@ -28,10 +28,14 @@ export interface MessageBarProps extends TextAreaProps {
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 */
30
30
  alwayShowSendButton?: boolean;
31
+ /** Placeholder for message input */
32
+ placeholder?: string;
31
33
  /** Flag to disable/enable the Attach button */
32
34
  hasAttachButton?: boolean;
33
35
  /** Flag to enable the Microphone button */
34
36
  hasMicrophoneButton?: boolean;
37
+ /** Placeholder text when listening */
38
+ listeningText?: string;
35
39
  /** Flag to enable the Stop button, used for streaming content */
36
40
  hasStopButton?: boolean;
37
41
  /** Callback function for when stop button is clicked */
@@ -24,7 +24,7 @@ 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, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
27
+ var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
28
28
  // Text Input
29
29
  // --------------------------------------------------------------------------
30
30
  const [message, setMessage] = react_1.default.useState(value !== null && value !== void 0 ? value : '');
@@ -186,7 +186,7 @@ const MessageBar = (_a) => {
186
186
  };
187
187
  const messageBarContents = (react_1.default.createElement(react_1.default.Fragment, null,
188
188
  react_1.default.createElement("div", { className: "pf-chatbot__message-bar-input" },
189
- react_1.default.createElement(react_core_1.TextArea, Object.assign({ className: "pf-chatbot__message-textarea", value: message, onChange: handleChange, "aria-label": isListeningMessage ? 'Listening' : 'Send a message...', placeholder: isListeningMessage ? 'Listening' : 'Send a message...', ref: textareaRef, onKeyDown: handleKeyDown }, props))),
189
+ react_1.default.createElement(react_core_1.TextArea, Object.assign({ className: "pf-chatbot__message-textarea", value: message, onChange: handleChange, "aria-label": isListeningMessage ? listeningText : placeholder, placeholder: isListeningMessage ? listeningText : placeholder, ref: textareaRef, onKeyDown: handleKeyDown }, props))),
190
190
  react_1.default.createElement("div", { className: "pf-chatbot__message-bar-actions" }, renderButtons())));
191
191
  if (attachMenuProps) {
192
192
  return (react_1.default.createElement(AttachMenu_1.default, Object.assign({ toggle: (toggleRef) => (react_1.default.createElement("div", { ref: toggleRef, className: `pf-chatbot__message-bar ${className !== null && className !== void 0 ? className : ''}` }, messageBarContents)), filteredItems: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.attachMenuItems }, (attachMenuProps && { isOpen: attachMenuProps.isAttachMenuOpen }), { onOpenChange: (isAttachMenuOpen) => {
@@ -76,6 +76,12 @@ describe('Message bar', () => {
76
76
  expect(spy).toHaveBeenCalledTimes(1);
77
77
  expect(spy).toHaveBeenCalledWith(expect.any(Object), 'A');
78
78
  }));
79
+ it('can use specified placeholder text', () => __awaiter(void 0, void 0, void 0, function* () {
80
+ (0, react_2.render)(react_1.default.createElement(MessageBar_1.MessageBar, { onSendMessage: jest.fn, placeholder: "test placeholder" }));
81
+ const input = react_2.screen.getByRole('textbox', { name: /test placeholder/i });
82
+ yield user_event_1.default.type(input, 'Hello world');
83
+ expect(input).toHaveTextContent('Hello world');
84
+ }));
79
85
  // Send button
80
86
  // --------------------------------------------------------------------------
81
87
  it('shows send button when text is input', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -229,6 +235,13 @@ describe('Message bar', () => {
229
235
  yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Microphone button' }));
230
236
  expect(react_2.screen.getByRole('tooltip', { name: 'Not currently listening' })).toBeTruthy();
231
237
  }));
238
+ it('can customize the listening placeholder', () => __awaiter(void 0, void 0, void 0, function* () {
239
+ mockSpeechRecognition();
240
+ (0, react_2.render)(react_1.default.createElement(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, listeningText: "I am listening" }));
241
+ yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Microphone button' }));
242
+ const input = react_2.screen.getByRole('textbox', { name: /I am listening/i });
243
+ expect(input).toBeTruthy();
244
+ }));
232
245
  it('can handle buttonProps props appropriately for microphone', () => __awaiter(void 0, void 0, void 0, function* () {
233
246
  mockSpeechRecognition();
234
247
  (0, react_2.render)(react_1.default.createElement(MessageBar_1.MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { props: { 'aria-label': 'Test' } } } }));
@@ -28,10 +28,14 @@ export interface MessageBarProps extends TextAreaProps {
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 */
30
30
  alwayShowSendButton?: boolean;
31
+ /** Placeholder for message input */
32
+ placeholder?: string;
31
33
  /** Flag to disable/enable the Attach button */
32
34
  hasAttachButton?: boolean;
33
35
  /** Flag to enable the Microphone button */
34
36
  hasMicrophoneButton?: boolean;
37
+ /** Placeholder text when listening */
38
+ listeningText?: string;
35
39
  /** Flag to enable the Stop button, used for streaming content */
36
40
  hasStopButton?: boolean;
37
41
  /** Callback function for when stop button is clicked */
@@ -18,7 +18,7 @@ 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, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "hasAttachButton", "hasMicrophoneButton", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
21
+ var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value"]);
22
22
  // Text Input
23
23
  // --------------------------------------------------------------------------
24
24
  const [message, setMessage] = React.useState(value !== null && value !== void 0 ? value : '');
@@ -180,7 +180,7 @@ export const MessageBar = (_a) => {
180
180
  };
181
181
  const messageBarContents = (React.createElement(React.Fragment, null,
182
182
  React.createElement("div", { className: "pf-chatbot__message-bar-input" },
183
- React.createElement(TextArea, Object.assign({ className: "pf-chatbot__message-textarea", value: message, onChange: handleChange, "aria-label": isListeningMessage ? 'Listening' : 'Send a message...', placeholder: isListeningMessage ? 'Listening' : 'Send a message...', ref: textareaRef, onKeyDown: handleKeyDown }, props))),
183
+ React.createElement(TextArea, Object.assign({ className: "pf-chatbot__message-textarea", value: message, onChange: handleChange, "aria-label": isListeningMessage ? listeningText : placeholder, placeholder: isListeningMessage ? listeningText : placeholder, ref: textareaRef, onKeyDown: handleKeyDown }, props))),
184
184
  React.createElement("div", { className: "pf-chatbot__message-bar-actions" }, renderButtons())));
185
185
  if (attachMenuProps) {
186
186
  return (React.createElement(AttachMenu, Object.assign({ toggle: (toggleRef) => (React.createElement("div", { ref: toggleRef, className: `pf-chatbot__message-bar ${className !== null && className !== void 0 ? className : ''}` }, messageBarContents)), filteredItems: attachMenuProps === null || attachMenuProps === void 0 ? void 0 : attachMenuProps.attachMenuItems }, (attachMenuProps && { isOpen: attachMenuProps.isAttachMenuOpen }), { onOpenChange: (isAttachMenuOpen) => {
@@ -71,6 +71,12 @@ describe('Message bar', () => {
71
71
  expect(spy).toHaveBeenCalledTimes(1);
72
72
  expect(spy).toHaveBeenCalledWith(expect.any(Object), 'A');
73
73
  }));
74
+ it('can use specified placeholder text', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ render(React.createElement(MessageBar, { onSendMessage: jest.fn, placeholder: "test placeholder" }));
76
+ const input = screen.getByRole('textbox', { name: /test placeholder/i });
77
+ yield userEvent.type(input, 'Hello world');
78
+ expect(input).toHaveTextContent('Hello world');
79
+ }));
74
80
  // Send button
75
81
  // --------------------------------------------------------------------------
76
82
  it('shows send button when text is input', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -224,6 +230,13 @@ describe('Message bar', () => {
224
230
  yield userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
225
231
  expect(screen.getByRole('tooltip', { name: 'Not currently listening' })).toBeTruthy();
226
232
  }));
233
+ it('can customize the listening placeholder', () => __awaiter(void 0, void 0, void 0, function* () {
234
+ mockSpeechRecognition();
235
+ render(React.createElement(MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, listeningText: "I am listening" }));
236
+ yield userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
237
+ const input = screen.getByRole('textbox', { name: /I am listening/i });
238
+ expect(input).toBeTruthy();
239
+ }));
227
240
  it('can handle buttonProps props appropriately for microphone', () => __awaiter(void 0, void 0, void 0, function* () {
228
241
  mockSpeechRecognition();
229
242
  render(React.createElement(MessageBar, { onSendMessage: jest.fn, hasMicrophoneButton: true, buttonProps: { microphone: { props: { 'aria-label': 'Test' } } } }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/chatbot",
3
- "version": "6.3.0-prerelease.1",
3
+ "version": "6.3.0-prerelease.2",
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",
@@ -96,6 +96,12 @@ describe('Message bar', () => {
96
96
  expect(spy).toHaveBeenCalledTimes(1);
97
97
  expect(spy).toHaveBeenCalledWith(expect.any(Object), 'A');
98
98
  });
99
+ it('can use specified placeholder text', async () => {
100
+ render(<MessageBar onSendMessage={jest.fn} placeholder="test placeholder" />);
101
+ const input = screen.getByRole('textbox', { name: /test placeholder/i });
102
+ await userEvent.type(input, 'Hello world');
103
+ expect(input).toHaveTextContent('Hello world');
104
+ });
99
105
 
100
106
  // Send button
101
107
  // --------------------------------------------------------------------------
@@ -304,6 +310,13 @@ describe('Message bar', () => {
304
310
  await userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
305
311
  expect(screen.getByRole('tooltip', { name: 'Not currently listening' })).toBeTruthy();
306
312
  });
313
+ it('can customize the listening placeholder', async () => {
314
+ mockSpeechRecognition();
315
+ render(<MessageBar onSendMessage={jest.fn} hasMicrophoneButton listeningText="I am listening" />);
316
+ await userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
317
+ const input = screen.getByRole('textbox', { name: /I am listening/i });
318
+ expect(input).toBeTruthy();
319
+ });
307
320
  it('can handle buttonProps props appropriately for microphone', async () => {
308
321
  mockSpeechRecognition();
309
322
  render(
@@ -37,10 +37,14 @@ export interface MessageBarProps extends TextAreaProps {
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 */
39
39
  alwayShowSendButton?: boolean;
40
+ /** Placeholder for message input */
41
+ placeholder?: string;
40
42
  /** Flag to disable/enable the Attach button */
41
43
  hasAttachButton?: boolean;
42
44
  /** Flag to enable the Microphone button */
43
45
  hasMicrophoneButton?: boolean;
46
+ /** Placeholder text when listening */
47
+ listeningText?: string;
44
48
  /** Flag to enable the Stop button, used for streaming content */
45
49
  hasStopButton?: boolean;
46
50
  /** Callback function for when stop button is clicked */
@@ -78,8 +82,10 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
78
82
  onSendMessage,
79
83
  className,
80
84
  alwayShowSendButton,
85
+ placeholder = 'Send a message...',
81
86
  hasAttachButton = true,
82
87
  hasMicrophoneButton,
88
+ listeningText = 'Listening',
83
89
  handleAttach,
84
90
  attachMenuProps,
85
91
  isSendButtonDisabled,
@@ -322,8 +328,8 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
322
328
  className="pf-chatbot__message-textarea"
323
329
  value={message}
324
330
  onChange={handleChange}
325
- aria-label={isListeningMessage ? 'Listening' : 'Send a message...'}
326
- placeholder={isListeningMessage ? 'Listening' : 'Send a message...'}
331
+ aria-label={isListeningMessage ? listeningText : placeholder}
332
+ placeholder={isListeningMessage ? listeningText : placeholder}
327
333
  ref={textareaRef}
328
334
  onKeyDown={handleKeyDown}
329
335
  {...props}