@botonic/react 0.21.1 → 0.21.2-alpha.0

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.
@@ -1,24 +1,52 @@
1
1
  import Picker from 'emoji-picker-react'
2
- import React from 'react'
2
+ import React, { useContext } from 'react'
3
3
  import styled from 'styled-components'
4
4
 
5
5
  import LogoEmoji from '../../assets/emojiButton.svg'
6
- import { ROLES } from '../../constants'
6
+ import { ROLES, WEBCHAT } from '../../constants'
7
+ import { WebchatContext } from '../../contexts'
8
+ import { ConditionalAnimation } from '../components/conditional-animation'
7
9
  import { useComponentVisible } from '../hooks'
8
- import { Icon, IconContainer } from './common'
10
+ import { Icon } from './common'
9
11
 
10
- export const EmojiPicker = props => {
11
- const onClick = event => {
12
- props.onClick()
12
+ export const EmojiPicker = ({ enableEmojiPicker, onClick }) => {
13
+ const { getThemeProperty } = useContext(WebchatContext)
14
+
15
+ const CustomEmojiPicker = getThemeProperty(
16
+ WEBCHAT.CUSTOM_PROPERTIES.customEmojiPicker,
17
+ undefined
18
+ )
19
+
20
+ const isEmojiPickerEnabled = () => {
21
+ const hasCustomEmojiPicker = !!CustomEmojiPicker
22
+ return (
23
+ getThemeProperty(
24
+ WEBCHAT.CUSTOM_PROPERTIES.enableEmojiPicker,
25
+ enableEmojiPicker
26
+ ) ?? hasCustomEmojiPicker
27
+ )
28
+ }
29
+ const emojiPickerEnabled = isEmojiPickerEnabled()
30
+
31
+ const handleClick = event => {
32
+ onClick()
13
33
  event.stopPropagation()
14
34
  }
15
35
 
16
36
  return (
17
- <IconContainer role={ROLES.EMOJI_PICKER_ICON}>
18
- <div onClick={onClick}>
19
- <Icon src={LogoEmoji} />
20
- </div>
21
- </IconContainer>
37
+ <>
38
+ {emojiPickerEnabled ? (
39
+ <ConditionalAnimation>
40
+ <div role={ROLES.EMOJI_PICKER_ICON} onClick={handleClick}>
41
+ {CustomEmojiPicker ? (
42
+ <CustomEmojiPicker />
43
+ ) : (
44
+ <Icon src={LogoEmoji} />
45
+ )}
46
+ </div>
47
+ </ConditionalAnimation>
48
+ ) : null}
49
+ </>
22
50
  )
23
51
  }
24
52
 
@@ -5,6 +5,7 @@ import LogoMenu from '../../assets/menuButton.svg'
5
5
  import { Button } from '../../components/button'
6
6
  import { ROLES, WEBCHAT } from '../../constants'
7
7
  import { WebchatContext } from '../../contexts'
8
+ import { ConditionalAnimation } from '../components/conditional-animation'
8
9
  import { useComponentVisible } from '../hooks'
9
10
  import { Icon } from './common'
10
11
 
@@ -59,17 +60,30 @@ export const OpenedPersistentMenu = ({ onClick, options, borderRadius }) => {
59
60
  )
60
61
  }
61
62
 
62
- const IconContainer = styled.div`
63
- display: flex;
64
- align-items: center;
65
- cursor: pointer;
66
- padding: 18px;
67
- `
63
+ export const PersistentMenu = ({ onClick, persistentMenu }) => {
64
+ const { getThemeProperty } = useContext(WebchatContext)
65
+
66
+ const persistentMenuOptions = getThemeProperty(
67
+ WEBCHAT.CUSTOM_PROPERTIES.persistentMenu,
68
+ persistentMenu
69
+ )
70
+
71
+ const CustomMenuButton = getThemeProperty(
72
+ WEBCHAT.CUSTOM_PROPERTIES.customMenuButton,
73
+ undefined
74
+ )
68
75
 
69
- export const PersistentMenu = props => (
70
- <IconContainer role={ROLES.PERSISTENT_MENU_ICON} onClick={props.onClick}>
71
- <Icon src={LogoMenu} />
72
- </IconContainer>
73
- )
76
+ return (
77
+ <>
78
+ {persistentMenuOptions ? (
79
+ <ConditionalAnimation>
80
+ <div role={ROLES.PERSISTENT_MENU_ICON} onClick={onClick}>
81
+ {CustomMenuButton ? <CustomMenuButton /> : <Icon src={LogoMenu} />}
82
+ </div>
83
+ </ConditionalAnimation>
84
+ ) : null}
85
+ </>
86
+ )
87
+ }
74
88
 
75
89
  export default OpenedPersistentMenu
@@ -1,11 +1,37 @@
1
- import React from 'react'
1
+ import React, { useContext } from 'react'
2
2
 
3
3
  import SendButtonIcon from '../../assets/send-button.svg'
4
- import { ROLES } from '../../constants'
5
- import { Icon, IconContainer } from './common'
6
-
7
- export const SendButton = () => (
8
- <IconContainer role={ROLES.SEND_BUTTON_ICON}>
9
- <Icon src={SendButtonIcon} />
10
- </IconContainer>
11
- )
4
+ import { ROLES, WEBCHAT } from '../../constants'
5
+ import { WebchatContext } from '../../contexts'
6
+ import { ConditionalAnimation } from '../components/conditional-animation'
7
+ import { Icon } from './common'
8
+
9
+ export const SendButton = ({ onClick }) => {
10
+ const { getThemeProperty } = useContext(WebchatContext)
11
+
12
+ const sendButtonEnabled = getThemeProperty(
13
+ WEBCHAT.CUSTOM_PROPERTIES.enableSendButton,
14
+ true
15
+ )
16
+
17
+ const CustomSendButton = getThemeProperty(
18
+ WEBCHAT.CUSTOM_PROPERTIES.customSendButton,
19
+ undefined
20
+ )
21
+
22
+ return (
23
+ <>
24
+ {sendButtonEnabled || CustomSendButton ? (
25
+ <ConditionalAnimation>
26
+ <div onClick={onClick} role={ROLES.SEND_BUTTON_ICON}>
27
+ {CustomSendButton ? (
28
+ <CustomSendButton />
29
+ ) : (
30
+ <Icon src={SendButtonIcon} />
31
+ )}
32
+ </div>
33
+ </ConditionalAnimation>
34
+ ) : null}
35
+ </>
36
+ )
37
+ }
@@ -39,7 +39,6 @@ import {
39
39
  import { msgToBotonic } from '../msg-to-botonic'
40
40
  import { scrollToBottom } from '../util/dom'
41
41
  import { isDev, resolveImage } from '../util/environment'
42
- import { ConditionalWrapper } from '../util/react'
43
42
  import { deserializeRegex, stringifyWithRegexs } from '../util/regexs'
44
43
  import {
45
44
  _getThemeProperty,
@@ -106,8 +105,13 @@ const StyledTriggerButton = styled.div`
106
105
 
107
106
  const UserInputContainer = styled.div`
108
107
  min-height: 52px;
109
- display: flex;
110
108
  position: relative;
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: flex-start;
112
+ gap: 16px;
113
+ padding: 0px 16px;
114
+ z-index: 1;
111
115
  border-top: 1px solid ${COLORS.SOLID_BLACK_ALPHA_0_5};
112
116
  `
113
117
 
@@ -117,13 +121,6 @@ const TextAreaContainer = styled.div`
117
121
  align-items: center;
118
122
  `
119
123
 
120
- const FeaturesWrapper = styled.div`
121
- display: flex;
122
- align-items: center;
123
- justify-content: center;
124
- z-index: 1;
125
- `
126
-
127
124
  const TriggerImage = styled.img`
128
125
  max-width: 100%;
129
126
  max-height: 100%;
@@ -402,10 +399,6 @@ export const Webchat = forwardRef((props, ref) => {
402
399
  toggleEmojiPicker(!webchatState.isEmojiPickerOpen)
403
400
  }
404
401
 
405
- const animationsEnabled = getThemeProperty(
406
- WEBCHAT.CUSTOM_PROPERTIES.enableAnimations,
407
- props.enableAnimations !== undefined ? props.enableAnimations : true
408
- )
409
402
  const persistentMenuOptions = getThemeProperty(
410
403
  WEBCHAT.CUSTOM_PROPERTIES.persistentMenu,
411
404
  props.persistentMenu
@@ -774,37 +767,6 @@ export const Webchat = forwardRef((props, ref) => {
774
767
  }
775
768
 
776
769
  const userInputEnabled = isUserInputEnabled()
777
- const emojiPickerEnabled = getThemeProperty(
778
- WEBCHAT.CUSTOM_PROPERTIES.enableEmojiPicker,
779
- props.enableEmojiPicker
780
- )
781
- const attachmentsEnabled = getThemeProperty(
782
- WEBCHAT.CUSTOM_PROPERTIES.enableAttachments,
783
- props.enableAttachments
784
- )
785
- const sendButtonEnabled = getThemeProperty(
786
- WEBCHAT.CUSTOM_PROPERTIES.enableSendButton,
787
- true
788
- )
789
- const CustomSendButton = getThemeProperty(
790
- WEBCHAT.CUSTOM_PROPERTIES.customSendButton,
791
- undefined
792
- )
793
- const CustomMenuButton = getThemeProperty(
794
- WEBCHAT.CUSTOM_PROPERTIES.customMenuButton,
795
- undefined
796
- )
797
-
798
- const ConditionalAnimation = props => (
799
- <ConditionalWrapper
800
- condition={animationsEnabled}
801
- wrapper={children => (
802
- <motion.div whileHover={{ scale: 1.2 }}>{children}</motion.div>
803
- )}
804
- >
805
- {props.children}
806
- </ConditionalWrapper>
807
- )
808
770
 
809
771
  const userInputArea = () => {
810
772
  return (
@@ -822,15 +784,12 @@ export const Webchat = forwardRef((props, ref) => {
822
784
  onClick={handleEmojiClick}
823
785
  />
824
786
  )}
825
- {persistentMenuOptions && (
826
- <FeaturesWrapper>
827
- <ConditionalAnimation>
828
- <div onClick={handleMenu}>
829
- {CustomMenuButton ? <CustomMenuButton /> : <PersistentMenu />}
830
- </div>
831
- </ConditionalAnimation>
832
- </FeaturesWrapper>
833
- )}
787
+
788
+ <PersistentMenu
789
+ onClick={handleMenu}
790
+ persistentMenu={props.persistentMenu}
791
+ />
792
+
834
793
  <TextAreaContainer>
835
794
  <Textarea
836
795
  name='text'
@@ -865,28 +824,19 @@ export const Webchat = forwardRef((props, ref) => {
865
824
  }}
866
825
  />
867
826
  </TextAreaContainer>
868
- <FeaturesWrapper>
869
- {emojiPickerEnabled && (
870
- <ConditionalAnimation>
871
- <EmojiPicker onClick={handleEmojiClick} />
872
- </ConditionalAnimation>
873
- )}
874
- {attachmentsEnabled && (
875
- <ConditionalAnimation>
876
- <Attachment
877
- onChange={handleAttachment}
878
- accept={getFullMimeWhitelist().join(',')}
879
- />
880
- </ConditionalAnimation>
881
- )}
882
- {(sendButtonEnabled || CustomSendButton) && (
883
- <ConditionalAnimation>
884
- <div onClick={sendTextAreaText}>
885
- {CustomSendButton ? <CustomSendButton /> : <SendButton />}
886
- </div>
887
- </ConditionalAnimation>
888
- )}
889
- </FeaturesWrapper>
827
+
828
+ <EmojiPicker
829
+ enableEmojiPicker={props.enableEmojiPicker}
830
+ onClick={handleEmojiClick}
831
+ />
832
+
833
+ <Attachment
834
+ enableAttachments={props.enableAttachments}
835
+ onChange={handleAttachment}
836
+ accept={getFullMimeWhitelist().join(',')}
837
+ />
838
+
839
+ <SendButton onClick={sendTextAreaText} />
890
840
  </UserInputContainer>
891
841
  )
892
842
  )