@botonic/react 0.22.2 → 0.22.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.
- package/lib/cjs/components/message.js +8 -8
- package/lib/cjs/components/message.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.js +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js +3 -1
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
- package/lib/cjs/components/multichannel/whatsapp/markdown.d.ts +1 -0
- package/lib/cjs/components/multichannel/whatsapp/markdown.js +57 -0
- package/lib/cjs/components/multichannel/whatsapp/markdown.js.map +1 -0
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +1 -0
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/contexts.d.ts +4 -2
- package/lib/cjs/contexts.js +3 -2
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/index-types.d.ts +1 -1
- package/lib/cjs/webchat/hooks.d.ts +1 -0
- package/lib/cjs/webchat/hooks.js +7 -4
- package/lib/cjs/webchat/hooks.js.map +1 -1
- package/lib/cjs/webchat/messages-reducer.js +10 -4
- package/lib/cjs/webchat/messages-reducer.js.map +1 -1
- package/lib/cjs/webchat/trigger-button/index.d.ts +1 -0
- package/lib/cjs/webchat/trigger-button/index.js +32 -0
- package/lib/cjs/webchat/trigger-button/index.js.map +1 -0
- package/lib/cjs/webchat/trigger-button/styles.d.ts +3 -0
- package/lib/cjs/webchat/trigger-button/styles.js +40 -0
- package/lib/cjs/webchat/trigger-button/styles.js.map +1 -0
- package/lib/cjs/webchat/webchat-reducer.js +4 -2
- package/lib/cjs/webchat/webchat-reducer.js.map +1 -1
- package/lib/cjs/webchat/webchat.js +2 -39
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/esm/components/message.js +8 -8
- package/lib/esm/components/message.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.js +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js +3 -1
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel.js.map +1 -1
- package/lib/esm/components/multichannel/whatsapp/markdown.d.ts +1 -0
- package/lib/esm/components/multichannel/whatsapp/markdown.js +53 -0
- package/lib/esm/components/multichannel/whatsapp/markdown.js.map +1 -0
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/contexts.d.ts +4 -2
- package/lib/esm/contexts.js +3 -2
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/index-types.d.ts +1 -1
- package/lib/esm/webchat/hooks.d.ts +1 -0
- package/lib/esm/webchat/hooks.js +7 -4
- package/lib/esm/webchat/hooks.js.map +1 -1
- package/lib/esm/webchat/messages-reducer.js +10 -4
- package/lib/esm/webchat/messages-reducer.js.map +1 -1
- package/lib/esm/webchat/trigger-button/index.d.ts +1 -0
- package/lib/esm/webchat/trigger-button/index.js +28 -0
- package/lib/esm/webchat/trigger-button/index.js.map +1 -0
- package/lib/esm/webchat/trigger-button/styles.d.ts +3 -0
- package/lib/esm/webchat/trigger-button/styles.js +36 -0
- package/lib/esm/webchat/trigger-button/styles.js.map +1 -0
- package/lib/esm/webchat/webchat-reducer.js +4 -2
- package/lib/esm/webchat/webchat-reducer.js.map +1 -1
- package/lib/esm/webchat/webchat.js +3 -40
- package/lib/esm/webchat/webchat.js.map +1 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/components/message.jsx +8 -8
- package/src/components/multichannel/multichannel-carousel.jsx +1 -1
- package/src/components/multichannel/multichannel-text.jsx +3 -1
- package/src/components/multichannel/multichannel.jsx +0 -1
- package/src/components/multichannel/whatsapp/markdown.ts +88 -0
- package/src/constants.js +1 -0
- package/src/contexts.jsx +3 -2
- package/src/index-types.ts +1 -1
- package/src/webchat/hooks.js +5 -2
- package/src/webchat/messages-reducer.js +16 -7
- package/src/webchat/trigger-button/index.tsx +67 -0
- package/src/webchat/trigger-button/styles.ts +39 -0
- package/src/webchat/webchat-reducer.js +8 -2
- package/src/webchat/webchat.jsx +4 -69
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
import { ROLES, WEBCHAT } from '../../constants'
|
|
4
|
+
import { WebchatContext } from '../../contexts'
|
|
5
|
+
import { resolveImage } from '../../util/environment'
|
|
6
|
+
import {
|
|
7
|
+
StyledTriggerButton,
|
|
8
|
+
TriggerImage,
|
|
9
|
+
UnreadMessagesCounter,
|
|
10
|
+
} from './styles'
|
|
11
|
+
|
|
12
|
+
export const TriggerButton = (): JSX.Element => {
|
|
13
|
+
const { webchatState, getThemeProperty, toggleWebchat } =
|
|
14
|
+
useContext(WebchatContext)
|
|
15
|
+
|
|
16
|
+
const getTriggerImage = () => {
|
|
17
|
+
const image = getThemeProperty(
|
|
18
|
+
WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage,
|
|
19
|
+
undefined
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if (!image) {
|
|
23
|
+
webchatState.theme.triggerButtonImage = WEBCHAT.DEFAULTS.LOGO
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
return image
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const triggerButtonImage = getTriggerImage()
|
|
30
|
+
|
|
31
|
+
const triggerButtonStyle = getThemeProperty(
|
|
32
|
+
WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const CustomTriggerButton = getThemeProperty(
|
|
36
|
+
WEBCHAT.CUSTOM_PROPERTIES.customTrigger,
|
|
37
|
+
undefined
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const handleClick = (event: any) => {
|
|
41
|
+
toggleWebchat(true)
|
|
42
|
+
event.preventDefault()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div onClick={handleClick}>
|
|
47
|
+
{webchatState.unreadMessages !== 0 && (
|
|
48
|
+
<UnreadMessagesCounter className='trigger-notifications'>
|
|
49
|
+
{webchatState.unreadMessages}
|
|
50
|
+
</UnreadMessagesCounter>
|
|
51
|
+
)}
|
|
52
|
+
{CustomTriggerButton ? (
|
|
53
|
+
//@ts-ignore
|
|
54
|
+
<CustomTriggerButton />
|
|
55
|
+
) : (
|
|
56
|
+
<StyledTriggerButton
|
|
57
|
+
role={ROLES.TRIGGER_BUTTON}
|
|
58
|
+
style={triggerButtonStyle}
|
|
59
|
+
>
|
|
60
|
+
{triggerButtonImage && (
|
|
61
|
+
<TriggerImage src={resolveImage(triggerButtonImage)} />
|
|
62
|
+
)}
|
|
63
|
+
</StyledTriggerButton>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
import { COLORS } from '../../constants'
|
|
4
|
+
|
|
5
|
+
export const StyledTriggerButton = styled.div`
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
position: fixed;
|
|
8
|
+
background: ${COLORS.SOLID_WHITE};
|
|
9
|
+
border-radius: 50%;
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
width: 65px;
|
|
15
|
+
height: 65px;
|
|
16
|
+
bottom: 20px;
|
|
17
|
+
right: 10px;
|
|
18
|
+
padding: 8px;
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
export const UnreadMessagesCounter = styled.div`
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
border-radius: 50%;
|
|
26
|
+
position: absolute;
|
|
27
|
+
right: 20px;
|
|
28
|
+
bottom: 80px;
|
|
29
|
+
width: 24px;
|
|
30
|
+
height: 24px;
|
|
31
|
+
background-color: ${COLORS.RED_NOTIFICATIONS};
|
|
32
|
+
color: white;
|
|
33
|
+
z-index: 10;
|
|
34
|
+
`
|
|
35
|
+
|
|
36
|
+
export const TriggerImage = styled.img`
|
|
37
|
+
max-width: 100%;
|
|
38
|
+
max-height: 100%;
|
|
39
|
+
`
|
|
@@ -35,8 +35,14 @@ export function webchatReducer(state, action) {
|
|
|
35
35
|
}
|
|
36
36
|
case UPDATE_HANDOFF:
|
|
37
37
|
return { ...state, handoff: action.payload }
|
|
38
|
-
case TOGGLE_WEBCHAT:
|
|
39
|
-
|
|
38
|
+
case TOGGLE_WEBCHAT: {
|
|
39
|
+
const isWebchatOpen = action.payload
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
isWebchatOpen,
|
|
43
|
+
unreadMessages: isWebchatOpen ? 0 : state.unreadMessages,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
40
46
|
case TOGGLE_EMOJI_PICKER:
|
|
41
47
|
return { ...state, isEmojiPickerOpen: action.payload }
|
|
42
48
|
case TOGGLE_PERSISTENT_MENU:
|
package/src/webchat/webchat.jsx
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from '../message-utils'
|
|
38
38
|
import { msgToBotonic } from '../msg-to-botonic'
|
|
39
39
|
import { scrollToBottom } from '../util/dom'
|
|
40
|
-
import { isDev
|
|
40
|
+
import { isDev } from '../util/environment'
|
|
41
41
|
import { deserializeRegex, stringifyWithRegexs } from '../util/regexs'
|
|
42
42
|
import {
|
|
43
43
|
_getThemeProperty,
|
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
} from './hooks'
|
|
64
64
|
import { WebchatMessageList } from './message-list'
|
|
65
65
|
import { WebchatReplies } from './replies'
|
|
66
|
+
import { TriggerButton } from './trigger-button'
|
|
66
67
|
import { useStorageState } from './use-storage-state-hook'
|
|
67
68
|
import { WebviewContainer } from './webview'
|
|
68
69
|
|
|
@@ -86,22 +87,6 @@ const StyledWebchat = styled.div`
|
|
|
86
87
|
flex-direction: column;
|
|
87
88
|
`
|
|
88
89
|
|
|
89
|
-
const StyledTriggerButton = styled.div`
|
|
90
|
-
cursor: pointer;
|
|
91
|
-
position: fixed;
|
|
92
|
-
background: ${COLORS.SOLID_WHITE};
|
|
93
|
-
border-radius: 50%;
|
|
94
|
-
display: flex;
|
|
95
|
-
align-items: center;
|
|
96
|
-
justify-content: center;
|
|
97
|
-
overflow: hidden;
|
|
98
|
-
width: 65px;
|
|
99
|
-
height: 65px;
|
|
100
|
-
bottom: 20px;
|
|
101
|
-
right: 10px;
|
|
102
|
-
padding: 8px;
|
|
103
|
-
`
|
|
104
|
-
|
|
105
90
|
const UserInputContainer = styled.div`
|
|
106
91
|
min-height: 52px;
|
|
107
92
|
position: relative;
|
|
@@ -120,11 +105,6 @@ const TextAreaContainer = styled.div`
|
|
|
120
105
|
align-items: center;
|
|
121
106
|
`
|
|
122
107
|
|
|
123
|
-
const TriggerImage = styled.img`
|
|
124
|
-
max-width: 100%;
|
|
125
|
-
max-height: 100%;
|
|
126
|
-
`
|
|
127
|
-
|
|
128
108
|
const ErrorMessageContainer = styled.div`
|
|
129
109
|
position: relative;
|
|
130
110
|
display: flex;
|
|
@@ -448,6 +428,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
448
428
|
}
|
|
449
429
|
return false
|
|
450
430
|
}
|
|
431
|
+
|
|
451
432
|
const closeMenu = () => {
|
|
452
433
|
togglePersistentMenu(false)
|
|
453
434
|
}
|
|
@@ -711,43 +692,6 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
711
692
|
}
|
|
712
693
|
}, [webchatState.isWebchatOpen])
|
|
713
694
|
|
|
714
|
-
const getTriggerImage = () => {
|
|
715
|
-
const triggerImage = getThemeProperty(
|
|
716
|
-
WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage,
|
|
717
|
-
null
|
|
718
|
-
)
|
|
719
|
-
if (triggerImage === null) {
|
|
720
|
-
webchatState.theme.triggerButtonImage = WEBCHAT.DEFAULTS.LOGO
|
|
721
|
-
return null
|
|
722
|
-
}
|
|
723
|
-
return triggerImage
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
const triggerButtonStyle = getThemeProperty(
|
|
727
|
-
WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle
|
|
728
|
-
)
|
|
729
|
-
|
|
730
|
-
const CustomTriggerButton = getThemeProperty(
|
|
731
|
-
WEBCHAT.CUSTOM_PROPERTIES.customTrigger,
|
|
732
|
-
undefined
|
|
733
|
-
)
|
|
734
|
-
|
|
735
|
-
const triggerButton = () => {
|
|
736
|
-
if (CustomTriggerButton) {
|
|
737
|
-
return <CustomTriggerButton />
|
|
738
|
-
}
|
|
739
|
-
return (
|
|
740
|
-
<StyledTriggerButton
|
|
741
|
-
role={ROLES.TRIGGER_BUTTON}
|
|
742
|
-
style={{ ...triggerButtonStyle }}
|
|
743
|
-
>
|
|
744
|
-
{getTriggerImage() && (
|
|
745
|
-
<TriggerImage src={resolveImage(getTriggerImage())} />
|
|
746
|
-
)}
|
|
747
|
-
</StyledTriggerButton>
|
|
748
|
-
)
|
|
749
|
-
}
|
|
750
|
-
|
|
751
695
|
const webchatMessageList = () => (
|
|
752
696
|
<WebchatMessageList style={{ flex: 1 }}>
|
|
753
697
|
{webchatState.typing && <TypingIndicator />}
|
|
@@ -917,16 +861,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
917
861
|
updateWebchatDevSettings: updateWebchatDevSettings,
|
|
918
862
|
}}
|
|
919
863
|
>
|
|
920
|
-
{!webchatState.isWebchatOpen &&
|
|
921
|
-
<div
|
|
922
|
-
onClick={event => {
|
|
923
|
-
toggleWebchat(true)
|
|
924
|
-
event.preventDefault()
|
|
925
|
-
}}
|
|
926
|
-
>
|
|
927
|
-
{triggerButton()}
|
|
928
|
-
</div>
|
|
929
|
-
)}
|
|
864
|
+
{!webchatState.isWebchatOpen && <TriggerButton />}
|
|
930
865
|
|
|
931
866
|
{webchatState.isWebchatOpen && (
|
|
932
867
|
<StyledWebchat
|