@botonic/react 0.24.0-alpha.4 → 0.24.0-alpha.6

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 (71) hide show
  1. package/lib/cjs/components/index-types.d.ts +2 -2
  2. package/lib/cjs/components/index-types.js.map +1 -1
  3. package/lib/cjs/components/message/index.js +2 -3
  4. package/lib/cjs/components/message/index.js.map +1 -1
  5. package/lib/cjs/components/message/message-image.d.ts +3 -3
  6. package/lib/cjs/components/message/message-image.js +7 -2
  7. package/lib/cjs/components/message/message-image.js.map +1 -1
  8. package/lib/cjs/components/message/styles.js +14 -6
  9. package/lib/cjs/components/message/styles.js.map +1 -1
  10. package/lib/cjs/components/message/timestamps.d.ts +9 -7
  11. package/lib/cjs/components/message/timestamps.js +20 -11
  12. package/lib/cjs/components/message/timestamps.js.map +1 -1
  13. package/lib/cjs/constants.d.ts +1 -0
  14. package/lib/cjs/constants.js +1 -0
  15. package/lib/cjs/constants.js.map +1 -1
  16. package/lib/cjs/index-types.d.ts +1 -1
  17. package/lib/cjs/webchat/components/styled-scrollbar.js +1 -1
  18. package/lib/cjs/webchat/components/styled-scrollbar.js.map +1 -1
  19. package/lib/cjs/webchat/devices/device-adapter.js +0 -4
  20. package/lib/cjs/webchat/devices/device-adapter.js.map +1 -1
  21. package/lib/cjs/webchat/message-list/index.js +1 -1
  22. package/lib/cjs/webchat/message-list/index.js.map +1 -1
  23. package/lib/cjs/webchat/message-list/unread-messages-banner.js +8 -0
  24. package/lib/cjs/webchat/message-list/unread-messages-banner.js.map +1 -1
  25. package/lib/cjs/webchat/replies.js +1 -1
  26. package/lib/cjs/webchat/replies.js.map +1 -1
  27. package/lib/cjs/webchat/webchat.js +1 -3
  28. package/lib/cjs/webchat/webchat.js.map +1 -1
  29. package/lib/esm/components/index-types.d.ts +2 -2
  30. package/lib/esm/components/index-types.js.map +1 -1
  31. package/lib/esm/components/message/index.js +2 -3
  32. package/lib/esm/components/message/index.js.map +1 -1
  33. package/lib/esm/components/message/message-image.d.ts +3 -3
  34. package/lib/esm/components/message/message-image.js +7 -2
  35. package/lib/esm/components/message/message-image.js.map +1 -1
  36. package/lib/esm/components/message/styles.js +14 -6
  37. package/lib/esm/components/message/styles.js.map +1 -1
  38. package/lib/esm/components/message/timestamps.d.ts +9 -7
  39. package/lib/esm/components/message/timestamps.js +21 -11
  40. package/lib/esm/components/message/timestamps.js.map +1 -1
  41. package/lib/esm/constants.d.ts +1 -0
  42. package/lib/esm/constants.js +1 -0
  43. package/lib/esm/constants.js.map +1 -1
  44. package/lib/esm/index-types.d.ts +1 -1
  45. package/lib/esm/webchat/components/styled-scrollbar.js +1 -1
  46. package/lib/esm/webchat/components/styled-scrollbar.js.map +1 -1
  47. package/lib/esm/webchat/devices/device-adapter.js +0 -4
  48. package/lib/esm/webchat/devices/device-adapter.js.map +1 -1
  49. package/lib/esm/webchat/message-list/index.js +1 -1
  50. package/lib/esm/webchat/message-list/index.js.map +1 -1
  51. package/lib/esm/webchat/message-list/unread-messages-banner.js +9 -1
  52. package/lib/esm/webchat/message-list/unread-messages-banner.js.map +1 -1
  53. package/lib/esm/webchat/replies.js +1 -1
  54. package/lib/esm/webchat/replies.js.map +1 -1
  55. package/lib/esm/webchat/webchat.js +1 -3
  56. package/lib/esm/webchat/webchat.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/components/index-types.ts +3 -2
  59. package/src/components/message/index.jsx +1 -7
  60. package/src/components/message/message-image.tsx +11 -7
  61. package/src/components/message/styles.ts +14 -6
  62. package/src/components/message/timestamps.tsx +100 -0
  63. package/src/constants.js +1 -0
  64. package/src/index-types.ts +1 -1
  65. package/src/webchat/components/styled-scrollbar.jsx +1 -1
  66. package/src/webchat/devices/device-adapter.js +0 -4
  67. package/src/webchat/message-list/index.tsx +1 -1
  68. package/src/webchat/message-list/unread-messages-banner.tsx +10 -1
  69. package/src/webchat/replies.jsx +1 -3
  70. package/src/webchat/webchat.jsx +4 -4
  71. package/src/components/message/timestamps.jsx +0 -62
@@ -41,7 +41,6 @@ export const Message = props => {
41
41
 
42
42
  const isSentByUser = sentBy === SENDERS.user
43
43
  const isSentByBot = sentBy === SENDERS.bot
44
- const isSentByAgent = sentBy === SENDERS.agent
45
44
  const markdown = props.markdown
46
45
  const { webchatState, addMessage, updateReplies, getThemeProperty } =
47
46
  useContext(WebchatContext)
@@ -219,11 +218,7 @@ export const Message = props => {
219
218
  ...getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.messageStyle),
220
219
  }}
221
220
  >
222
- <MessageImage
223
- imagestyle={imagestyle}
224
- isSentByAgent={isSentByAgent}
225
- isSentByUser={isSentByUser}
226
- />
221
+ <MessageImage imagestyle={imagestyle} sentBy={sentBy} />
227
222
  <BlobContainer
228
223
  className={className}
229
224
  bgcolor={getBgColor()}
@@ -262,7 +257,6 @@ export const Message = props => {
262
257
  </MessageContainer>
263
258
  {timestampsEnabled && (
264
259
  <MessageTimestamp
265
- isSentByUser={isSentByUser}
266
260
  sentBy={sentBy}
267
261
  style={timestampStyle}
268
262
  timestamp={messageJSON.timestamp}
@@ -2,22 +2,25 @@ import React, { useContext } from 'react'
2
2
 
3
3
  import { WEBCHAT } from '../../constants'
4
4
  import { WebchatContext } from '../../contexts'
5
+ import { SENDERS } from '../../index-types'
5
6
  import { resolveImage } from '../../util/environment'
6
7
  import { BotMessageImageContainer } from './styles'
7
8
 
8
9
  interface MessageImageProps {
9
10
  imagestyle: Record<string, unknown>
10
- isSentByUser: boolean
11
- isSentByAgent: boolean
11
+ sentBy: SENDERS
12
12
  }
13
13
 
14
- export const MessageImage = ({
15
- imagestyle,
16
- isSentByUser,
17
- isSentByAgent,
18
- }: MessageImageProps) => {
14
+ export const MessageImage = ({ imagestyle, sentBy }: MessageImageProps) => {
19
15
  const { getThemeProperty } = useContext(WebchatContext)
20
16
 
17
+ const isSentByAgent = sentBy === SENDERS.agent
18
+ const isSentByUser = sentBy === SENDERS.user
19
+
20
+ const timestampsWithImage = getThemeProperty(
21
+ WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsWithImage
22
+ )
23
+
21
24
  const BotMessageImage = getThemeProperty(
22
25
  WEBCHAT.CUSTOM_PROPERTIES.botMessageImage,
23
26
  getThemeProperty(
@@ -32,6 +35,7 @@ export const MessageImage = ({
32
35
  )
33
36
 
34
37
  return (
38
+ !timestampsWithImage &&
35
39
  !isSentByUser &&
36
40
  BotMessageImage && (
37
41
  <BotMessageImageContainer
@@ -58,16 +58,24 @@ export const BlobTick = styled.div`
58
58
  export const TimestampContainer = styled.div`
59
59
  display: flex;
60
60
  position: relative;
61
- align-items: flex-start;
61
+ justify-content: ${props => (props.isSentByUser ? 'flex-end' : 'flex-start')};
62
+ align-items: center;
63
+ gap: 10px;
64
+
65
+ box-sizing: border-box;
66
+ width: 100%;
67
+ padding: 0px 15px 4px 15px;
68
+ padding-top: ${props => (props.isSentByUser ? '0px' : '4px')};
69
+
70
+ img {
71
+ max-width: 20px;
72
+ }
62
73
  `
63
74
 
64
75
  export const TimestampText = styled.div`
65
- @import url('https://fonts.googleapis.com/css?family=Lato');
66
- font-family: Lato;
76
+ /* @import url('https://fonts.googleapis.com/css?family=Lato');
77
+ font-family: Lato; */
67
78
  font-size: 10px;
68
79
  color: ${COLORS.SOLID_BLACK};
69
- width: 100%;
70
80
  text-align: ${props => (props.isSentByUser ? 'right' : 'left')};
71
- padding: ${props => (props.isSentByUser ? '0px 15px' : '0px 50px')};
72
- margin-bottom: 5px;
73
81
  `
@@ -0,0 +1,100 @@
1
+ import React, { useContext } from 'react'
2
+
3
+ import { WEBCHAT } from '../../constants'
4
+ import { WebchatContext } from '../../contexts'
5
+ import { SENDERS } from '../../index-types'
6
+ import { resolveImage } from '../../util'
7
+ import { TimestampContainer, TimestampText } from './styles'
8
+
9
+ export const resolveMessageTimestamps = (
10
+ getThemeProperty,
11
+ timestampEnabled
12
+ ) => {
13
+ const timestampsFormat = getThemeProperty(
14
+ WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsFormat
15
+ )
16
+ const timestampStyle = getThemeProperty(
17
+ WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsStyle
18
+ )
19
+ const timestampsEnabled = Boolean(
20
+ timestampEnabled !== undefined
21
+ ? timestampEnabled
22
+ : getThemeProperty(
23
+ WEBCHAT.CUSTOM_PROPERTIES.enableMessageTimestamps,
24
+ Boolean(timestampStyle) || Boolean(timestampsFormat) || false
25
+ )
26
+ )
27
+
28
+ const defaultTimestampFormat = {
29
+ month: 'short',
30
+ day: 'numeric',
31
+ hour: 'numeric',
32
+ minute: 'numeric',
33
+ second: 'numeric',
34
+ }
35
+
36
+ const getFormattedTimestamp = timestampsFormat
37
+ ? timestampsFormat()
38
+ : // @ts-ignore
39
+ new Date().toLocaleString(undefined, defaultTimestampFormat)
40
+
41
+ return {
42
+ timestampsEnabled,
43
+ getFormattedTimestamp,
44
+ timestampStyle,
45
+ }
46
+ }
47
+
48
+ interface MessageTimestampProps {
49
+ timestamp: string
50
+ style: Record<string, unknown>
51
+ sentBy: SENDERS
52
+ }
53
+
54
+ export const MessageTimestamp = ({
55
+ timestamp,
56
+ style,
57
+ sentBy,
58
+ }: MessageTimestampProps) => {
59
+ const { getThemeProperty } = useContext(WebchatContext)
60
+
61
+ const isSentByUser = sentBy === SENDERS.user
62
+ const isSentByAgent = sentBy === SENDERS.agent
63
+
64
+ const BotMessageImage = getThemeProperty(
65
+ WEBCHAT.CUSTOM_PROPERTIES.botMessageImage,
66
+ undefined
67
+ )
68
+
69
+ const AgentMessageImage = getThemeProperty(
70
+ WEBCHAT.CUSTOM_PROPERTIES.agentMessageImage,
71
+ BotMessageImage
72
+ )
73
+
74
+ const timestampsWithImage = getThemeProperty(
75
+ WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsWithImage
76
+ )
77
+
78
+ return (
79
+ <TimestampContainer
80
+ className={`botonic-timestamp-container ${sentBy}`}
81
+ isSentByUser={isSentByUser}
82
+ >
83
+ {timestampsWithImage && BotMessageImage && !isSentByUser && (
84
+ <img
85
+ src={resolveImage(
86
+ isSentByAgent ? AgentMessageImage : BotMessageImage
87
+ )}
88
+ />
89
+ )}
90
+ <TimestampText
91
+ isSentByUser={isSentByUser}
92
+ style={{
93
+ ...style,
94
+ }}
95
+ >
96
+ {timestamp}
97
+ </TimestampText>
98
+ </TimestampContainer>
99
+ )
100
+ }
package/src/constants.js CHANGED
@@ -100,6 +100,7 @@ export const WEBCHAT = {
100
100
  enableMessageTimestamps: 'message.timestamps.enable',
101
101
  messageTimestampsFormat: 'message.timestamps.format',
102
102
  messageTimestampsStyle: 'message.timestamps.style',
103
+ messageTimestampsWithImage: 'message.timestamps.withImage',
103
104
  // Intro
104
105
  customIntro: 'intro.custom',
105
106
  introImage: 'intro.image',
@@ -20,7 +20,7 @@ import {
20
20
  WebchatSettingsProps,
21
21
  Webview,
22
22
  } from './components/index-types'
23
- import { WebchatState } from './webchat'
23
+ import { WebchatState } from './webchat/index-types'
24
24
  import { WebchatApp } from './webchat-app'
25
25
 
26
26
  /**
@@ -8,7 +8,7 @@ import { COLORS } from '../../constants'
8
8
 
9
9
  export const StyledScrollbar = styled(SimpleBar)`
10
10
  ${props =>
11
- props.isMessagesContainer &&
11
+ props.ismessagescontainer === 'true' &&
12
12
  css`
13
13
  display: flex;
14
14
  flex-direction: column;
@@ -21,10 +21,6 @@ export class DeviceAdapter {
21
21
  }
22
22
 
23
23
  onFocus(host) {
24
- if (this.currentDevice !== DEVICES.MOBILE.IPHONE) {
25
- // scrollToBottom({ host, timeout: 800 })
26
- return
27
- }
28
24
  setTimeout(() => {
29
25
  // Place onFocus logic to be run the last on the queue of asynchronous events to give enough time to init method to be called. Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#zero_delays
30
26
  this.webchatResizer.onFocus(() =>
@@ -95,7 +95,7 @@ export const WebchatMessageList = props => {
95
95
  id='botonic-scrollable-content'
96
96
  scrollbar={scrollbarOptions}
97
97
  autoHide={scrollbarOptions.autoHide}
98
- isMessagesContainer={true}
98
+ ismessagescontainer={true.toString()}
99
99
  style={{
100
100
  ...props.style,
101
101
  }}
@@ -1,4 +1,4 @@
1
- import React, { useContext } from 'react'
1
+ import React, { useContext, useEffect } from 'react'
2
2
 
3
3
  import ArrowDown from '../../assets/arrow-down.svg'
4
4
  import { WEBCHAT } from '../../constants'
@@ -35,6 +35,15 @@ export const UnreadMessagesBanner = ({
35
35
  'unread messages'
36
36
  )
37
37
 
38
+ useEffect(() => {
39
+ if (webchatState.isWebchatOpen && unreadMessagesBannerRef.current) {
40
+ unreadMessagesBannerRef.current.scrollIntoView({
41
+ behavior: 'smooth',
42
+ block: 'center',
43
+ })
44
+ }
45
+ }, [webchatState.isWebchatOpen, unreadMessagesBannerRef])
46
+
38
47
  return (
39
48
  notificationsEnabled && (
40
49
  <div ref={unreadMessagesBannerRef}>
@@ -49,11 +49,9 @@ export const WebchatReplies = props => {
49
49
  autoHide={scrollbarOptions.autoHide}
50
50
  >
51
51
  <RepliesContainer
52
+ className='replies-container'
52
53
  justify={justifyContent}
53
54
  wrap={flexWrap}
54
- style={{
55
- ...props.style,
56
- }}
57
55
  >
58
56
  {webchatState.replies.map((r, i) => (
59
57
  <ReplyContainer key={i}>{r}</ReplyContainer>
@@ -714,8 +714,6 @@ export const Webchat = forwardRef((props, ref) => {
714
714
  }
715
715
  }, [webchatState.isWebchatOpen])
716
716
 
717
- const webchatReplies = () => <WebchatReplies replies={webchatState.replies} />
718
-
719
717
  const isUserInputEnabled = () => {
720
718
  const isUserInputEnabled = getThemeProperty(
721
719
  WEBCHAT.CUSTOM_PROPERTIES.enableUserInput,
@@ -911,8 +909,10 @@ export const Webchat = forwardRef((props, ref) => {
911
909
  <WebchatMessageList style={{ flex: 1 }} host={host} />
912
910
 
913
911
  {webchatState.replies &&
914
- Object.keys(webchatState.replies).length > 0 &&
915
- webchatReplies()}
912
+ Object.keys(webchatState.replies).length > 0 && (
913
+ <WebchatReplies replies={webchatState.replies} />
914
+ )}
915
+
916
916
  {webchatState.isPersistentMenuOpen && (
917
917
  <DarkenBackground component={persistentMenu()} />
918
918
  )}
@@ -1,62 +0,0 @@
1
- import React from 'react'
2
-
3
- import { WEBCHAT } from '../../constants'
4
- import { TimestampContainer, TimestampText } from './styles'
5
-
6
- export const resolveMessageTimestamps = (
7
- getThemeFn,
8
- messageTimestampEnabled
9
- ) => {
10
- const timestampsFormat = getThemeFn(
11
- WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsFormat
12
- )
13
- const timestampStyle = getThemeFn(
14
- WEBCHAT.CUSTOM_PROPERTIES.messageTimestampsStyle
15
- )
16
- const timestampsEnabled = Boolean(
17
- messageTimestampEnabled !== undefined
18
- ? messageTimestampEnabled
19
- : getThemeFn(
20
- WEBCHAT.CUSTOM_PROPERTIES.enableMessageTimestamps,
21
- Boolean(timestampStyle) || Boolean(timestampsFormat) || false
22
- )
23
- )
24
-
25
- const defaultTimestampFormat = {
26
- month: 'short',
27
- day: 'numeric',
28
- hour: 'numeric',
29
- minute: 'numeric',
30
- second: 'numeric',
31
- }
32
-
33
- const getFormattedTimestamp = timestampsFormat
34
- ? timestampsFormat()
35
- : new Date().toLocaleString(undefined, defaultTimestampFormat)
36
-
37
- return {
38
- timestampsEnabled,
39
- getFormattedTimestamp,
40
- timestampStyle,
41
- }
42
- }
43
-
44
- export const MessageTimestamp = ({
45
- timestamp,
46
- style,
47
- isSentByUser,
48
- sentBy,
49
- }) => {
50
- return (
51
- <TimestampContainer className={`botonic-timestamp-${sentBy}`}>
52
- <TimestampText
53
- isSentByUser={isSentByUser}
54
- style={{
55
- ...style,
56
- }}
57
- >
58
- {timestamp}
59
- </TimestampText>
60
- </TimestampContainer>
61
- )
62
- }