@patternfly/chatbot 2.2.0-prerelease.42 → 2.2.0-prerelease.43

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.
@@ -64,7 +64,7 @@ const MicrophoneButton = (_a) => {
64
64
  };
65
65
  setSpeechRecognition(recognition);
66
66
  }
67
- }, [onSpeechRecognition]);
67
+ }, [onSpeechRecognition, language, onIsListeningChange]);
68
68
  if (!speechRecognition) {
69
69
  return null;
70
70
  }
@@ -29,26 +29,26 @@ const MessageBoxBase = ({ announcement, ariaLabel = 'Scrollable message log', ch
29
29
  setAtTop(scrollTop === 0);
30
30
  setAtBottom(Math.round(scrollTop) + Math.round(clientHeight) >= Math.round(scrollHeight) - 1); // rounding means it could be within a pixel of the bottom
31
31
  }
32
- }, []);
32
+ }, [messageBoxRef]);
33
33
  const checkOverflow = react_1.default.useCallback(() => {
34
34
  const element = messageBoxRef.current;
35
35
  if (element) {
36
36
  const { scrollHeight, clientHeight } = element;
37
37
  setIsOverflowing(scrollHeight >= clientHeight);
38
38
  }
39
- }, []);
39
+ }, [messageBoxRef]);
40
40
  const scrollToTop = react_1.default.useCallback(() => {
41
41
  const element = messageBoxRef.current;
42
42
  if (element) {
43
43
  element.scrollTo({ top: 0, behavior: 'smooth' });
44
44
  }
45
- }, []);
45
+ }, [messageBoxRef]);
46
46
  const scrollToBottom = react_1.default.useCallback(() => {
47
47
  const element = messageBoxRef.current;
48
48
  if (element) {
49
49
  element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
50
50
  }
51
- }, []);
51
+ }, [messageBoxRef]);
52
52
  // Detect scroll position
53
53
  react_1.default.useEffect(() => {
54
54
  const element = messageBoxRef.current;
@@ -62,7 +62,7 @@ const MessageBoxBase = ({ announcement, ariaLabel = 'Scrollable message log', ch
62
62
  element.removeEventListener('scroll', handleScroll);
63
63
  };
64
64
  }
65
- }, [checkOverflow, handleScroll]);
65
+ }, [checkOverflow, handleScroll, messageBoxRef]);
66
66
  return (react_1.default.createElement(react_1.default.Fragment, null,
67
67
  react_1.default.createElement(JumpButton_1.default, { position: "top", isHidden: isOverflowing && atTop, onClick: scrollToTop }),
68
68
  react_1.default.createElement("div", { role: "region", tabIndex: 0, "aria-label": ariaLabel, className: `pf-chatbot__messagebox ${position === 'bottom' && 'pf-chatbot__messagebox--bottom'} ${className !== null && className !== void 0 ? className : ''}`, ref: innerRef !== null && innerRef !== void 0 ? innerRef : messageBoxRef },
@@ -58,7 +58,7 @@ export const MicrophoneButton = (_a) => {
58
58
  };
59
59
  setSpeechRecognition(recognition);
60
60
  }
61
- }, [onSpeechRecognition]);
61
+ }, [onSpeechRecognition, language, onIsListeningChange]);
62
62
  if (!speechRecognition) {
63
63
  return null;
64
64
  }
@@ -23,26 +23,26 @@ const MessageBoxBase = ({ announcement, ariaLabel = 'Scrollable message log', ch
23
23
  setAtTop(scrollTop === 0);
24
24
  setAtBottom(Math.round(scrollTop) + Math.round(clientHeight) >= Math.round(scrollHeight) - 1); // rounding means it could be within a pixel of the bottom
25
25
  }
26
- }, []);
26
+ }, [messageBoxRef]);
27
27
  const checkOverflow = React.useCallback(() => {
28
28
  const element = messageBoxRef.current;
29
29
  if (element) {
30
30
  const { scrollHeight, clientHeight } = element;
31
31
  setIsOverflowing(scrollHeight >= clientHeight);
32
32
  }
33
- }, []);
33
+ }, [messageBoxRef]);
34
34
  const scrollToTop = React.useCallback(() => {
35
35
  const element = messageBoxRef.current;
36
36
  if (element) {
37
37
  element.scrollTo({ top: 0, behavior: 'smooth' });
38
38
  }
39
- }, []);
39
+ }, [messageBoxRef]);
40
40
  const scrollToBottom = React.useCallback(() => {
41
41
  const element = messageBoxRef.current;
42
42
  if (element) {
43
43
  element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
44
44
  }
45
- }, []);
45
+ }, [messageBoxRef]);
46
46
  // Detect scroll position
47
47
  React.useEffect(() => {
48
48
  const element = messageBoxRef.current;
@@ -56,7 +56,7 @@ const MessageBoxBase = ({ announcement, ariaLabel = 'Scrollable message log', ch
56
56
  element.removeEventListener('scroll', handleScroll);
57
57
  };
58
58
  }
59
- }, [checkOverflow, handleScroll]);
59
+ }, [checkOverflow, handleScroll, messageBoxRef]);
60
60
  return (React.createElement(React.Fragment, null,
61
61
  React.createElement(JumpButton, { position: "top", isHidden: isOverflowing && atTop, onClick: scrollToTop }),
62
62
  React.createElement("div", { role: "region", tabIndex: 0, "aria-label": ariaLabel, className: `pf-chatbot__messagebox ${position === 'bottom' && 'pf-chatbot__messagebox--bottom'} ${className !== null && className !== void 0 ? className : ''}`, ref: innerRef !== null && innerRef !== void 0 ? innerRef : messageBoxRef },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/chatbot",
3
- "version": "2.2.0-prerelease.42",
3
+ "version": "2.2.0-prerelease.43",
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",
@@ -36,71 +36,74 @@ export const CompareChild = ({ name, input, hasNewInput, setIsSendButtonDisabled
36
36
  return id.toString();
37
37
  };
38
38
 
39
- const handleSend = (input: string) => {
40
- const date = new Date();
41
- const newMessages: MessageProps[] = [];
42
- messages.forEach((message) => newMessages.push(message));
43
- newMessages.push({
44
- avatar: userAvatar,
45
- avatarProps: { isBordered: true },
46
- id: generateId(),
47
- name: 'You',
48
- role: 'user',
49
- content: input,
50
- timestamp: `${date?.toLocaleDateString()} ${date?.toLocaleTimeString()}`
51
- });
52
- newMessages.push({
53
- avatar: patternflyAvatar,
54
- id: generateId(),
55
- name,
56
- role: 'bot',
57
- timestamp: `${date?.toLocaleDateString()} ${date?.toLocaleTimeString()}`,
58
- isLoading: true
59
- });
60
- setMessages(newMessages);
61
- // make announcement to assistive devices that new messages have been added
62
- setAnnouncement(`Message from You: ${input}. Message from ${name} is loading.`);
63
-
64
- // this is for demo purposes only; in a real situation, there would be an API response we would wait for
65
- setTimeout(() => {
66
- const loadedMessages: MessageProps[] = [];
67
- // we can't use structuredClone since messages contains functions, but we can't mutate
68
- // items that are going into state or the UI won't update correctly
69
- newMessages.forEach((message) => loadedMessages.push(message));
70
- loadedMessages.pop();
71
- loadedMessages.push({
39
+ const handleSend = React.useCallback(
40
+ (input: string) => {
41
+ const date = new Date();
42
+ const newMessages: MessageProps[] = [];
43
+ messages.forEach((message) => newMessages.push(message));
44
+ newMessages.push({
45
+ avatar: userAvatar,
46
+ avatarProps: { isBordered: true },
72
47
  id: generateId(),
73
- role: 'bot',
74
- content: `API response from ${name} goes here`,
75
- name,
48
+ name: 'You',
49
+ role: 'user',
50
+ content: input,
51
+ timestamp: `${date?.toLocaleDateString()} ${date?.toLocaleTimeString()}`
52
+ });
53
+ newMessages.push({
76
54
  avatar: patternflyAvatar,
77
- isLoading: false,
78
- actions: {
79
- // eslint-disable-next-line no-console
80
- positive: { onClick: () => console.log('Good response') },
81
- // eslint-disable-next-line no-console
82
- negative: { onClick: () => console.log('Bad response') },
83
- // eslint-disable-next-line no-console
84
- copy: { onClick: () => console.log('Copy') },
85
- // eslint-disable-next-line no-console
86
- share: { onClick: () => console.log('Share') },
87
- // eslint-disable-next-line no-console
88
- listen: { onClick: () => console.log('Listen') }
89
- },
90
- timestamp: date.toLocaleString()
55
+ id: generateId(),
56
+ name,
57
+ role: 'bot',
58
+ timestamp: `${date?.toLocaleDateString()} ${date?.toLocaleTimeString()}`,
59
+ isLoading: true
91
60
  });
92
- setMessages(loadedMessages);
93
- // make announcement to assistive devices that new message has loaded
94
- setAnnouncement(`Message from ${name}: API response goes here`);
95
- setIsSendButtonDisabled(false);
96
- }, 5000);
97
- };
61
+ setMessages(newMessages);
62
+ // make announcement to assistive devices that new messages have been added
63
+ setAnnouncement(`Message from You: ${input}. Message from ${name} is loading.`);
64
+
65
+ // this is for demo purposes only; in a real situation, there would be an API response we would wait for
66
+ setTimeout(() => {
67
+ const loadedMessages: MessageProps[] = [];
68
+ // we can't use structuredClone since messages contains functions, but we can't mutate
69
+ // items that are going into state or the UI won't update correctly
70
+ newMessages.forEach((message) => loadedMessages.push(message));
71
+ loadedMessages.pop();
72
+ loadedMessages.push({
73
+ id: generateId(),
74
+ role: 'bot',
75
+ content: `API response from ${name} goes here`,
76
+ name,
77
+ avatar: patternflyAvatar,
78
+ isLoading: false,
79
+ actions: {
80
+ // eslint-disable-next-line no-console
81
+ positive: { onClick: () => console.log('Good response') },
82
+ // eslint-disable-next-line no-console
83
+ negative: { onClick: () => console.log('Bad response') },
84
+ // eslint-disable-next-line no-console
85
+ copy: { onClick: () => console.log('Copy') },
86
+ // eslint-disable-next-line no-console
87
+ share: { onClick: () => console.log('Share') },
88
+ // eslint-disable-next-line no-console
89
+ listen: { onClick: () => console.log('Listen') }
90
+ },
91
+ timestamp: date.toLocaleString()
92
+ });
93
+ setMessages(loadedMessages);
94
+ // make announcement to assistive devices that new message has loaded
95
+ setAnnouncement(`Message from ${name}: API response goes here`);
96
+ setIsSendButtonDisabled(false);
97
+ }, 5000);
98
+ },
99
+ [messages, name, setIsSendButtonDisabled]
100
+ );
98
101
 
99
102
  React.useEffect(() => {
100
103
  if (input) {
101
104
  handleSend(input);
102
105
  }
103
- }, [hasNewInput]);
106
+ }, [hasNewInput, input]);
104
107
 
105
108
  // Auto-scrolls to the latest message
106
109
  React.useEffect(() => {
@@ -81,7 +81,7 @@ export const MicrophoneButton: React.FunctionComponent<MicrophoneButtonProps> =
81
81
 
82
82
  setSpeechRecognition(recognition);
83
83
  }
84
- }, [onSpeechRecognition]);
84
+ }, [onSpeechRecognition, language, onIsListeningChange]);
85
85
 
86
86
  if (!speechRecognition) {
87
87
  return null;
@@ -46,7 +46,7 @@ const MessageBoxBase: React.FunctionComponent<MessageBoxProps> = ({
46
46
  setAtTop(scrollTop === 0);
47
47
  setAtBottom(Math.round(scrollTop) + Math.round(clientHeight) >= Math.round(scrollHeight) - 1); // rounding means it could be within a pixel of the bottom
48
48
  }
49
- }, []);
49
+ }, [messageBoxRef]);
50
50
 
51
51
  const checkOverflow = React.useCallback(() => {
52
52
  const element = messageBoxRef.current;
@@ -54,21 +54,21 @@ const MessageBoxBase: React.FunctionComponent<MessageBoxProps> = ({
54
54
  const { scrollHeight, clientHeight } = element;
55
55
  setIsOverflowing(scrollHeight >= clientHeight);
56
56
  }
57
- }, []);
57
+ }, [messageBoxRef]);
58
58
 
59
59
  const scrollToTop = React.useCallback(() => {
60
60
  const element = messageBoxRef.current;
61
61
  if (element) {
62
62
  element.scrollTo({ top: 0, behavior: 'smooth' });
63
63
  }
64
- }, []);
64
+ }, [messageBoxRef]);
65
65
 
66
66
  const scrollToBottom = React.useCallback(() => {
67
67
  const element = messageBoxRef.current;
68
68
  if (element) {
69
69
  element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
70
70
  }
71
- }, []);
71
+ }, [messageBoxRef]);
72
72
 
73
73
  // Detect scroll position
74
74
  React.useEffect(() => {
@@ -85,7 +85,7 @@ const MessageBoxBase: React.FunctionComponent<MessageBoxProps> = ({
85
85
  element.removeEventListener('scroll', handleScroll);
86
86
  };
87
87
  }
88
- }, [checkOverflow, handleScroll]);
88
+ }, [checkOverflow, handleScroll, messageBoxRef]);
89
89
 
90
90
  return (
91
91
  <>