@botonic/react 0.34.1 → 0.35.0-alpha.1

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 (305) hide show
  1. package/lib/cjs/components/{button.d.ts → button/index.d.ts} +4 -5
  2. package/lib/cjs/components/{button.js → button/index.js} +26 -56
  3. package/lib/cjs/components/button/index.js.map +1 -0
  4. package/lib/cjs/components/button/styles.d.ts +2 -0
  5. package/lib/cjs/components/button/styles.js +40 -0
  6. package/lib/cjs/components/button/styles.js.map +1 -0
  7. package/lib/cjs/components/buttons-disabler.d.ts +20 -23
  8. package/lib/cjs/components/buttons-disabler.js +11 -26
  9. package/lib/cjs/components/buttons-disabler.js.map +1 -1
  10. package/lib/cjs/components/carousel.js +1 -1
  11. package/lib/cjs/components/carousel.js.map +1 -1
  12. package/lib/cjs/components/element.js +3 -3
  13. package/lib/cjs/components/element.js.map +1 -1
  14. package/lib/cjs/components/image.js +1 -1
  15. package/lib/cjs/components/image.js.map +1 -1
  16. package/lib/cjs/components/index-types.d.ts +1 -1
  17. package/lib/cjs/components/index.d.ts +1 -1
  18. package/lib/cjs/components/index.js +2 -2
  19. package/lib/cjs/components/index.js.map +1 -1
  20. package/lib/cjs/components/message/index.js +7 -7
  21. package/lib/cjs/components/message/index.js.map +1 -1
  22. package/lib/cjs/components/message/message-image.js +1 -1
  23. package/lib/cjs/components/message/message-image.js.map +1 -1
  24. package/lib/cjs/components/message/styles.d.ts +11 -11
  25. package/lib/cjs/components/message/timestamps.js +1 -1
  26. package/lib/cjs/components/message/timestamps.js.map +1 -1
  27. package/lib/cjs/components/multichannel/multichannel-button.js +4 -4
  28. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
  29. package/lib/cjs/components/multichannel/multichannel-carousel.js +2 -2
  30. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
  31. package/lib/cjs/components/multichannel/multichannel-utils.js +2 -2
  32. package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -1
  33. package/lib/cjs/components/reply.js +3 -1
  34. package/lib/cjs/components/reply.js.map +1 -1
  35. package/lib/cjs/components/webchat-settings.d.ts +6 -3
  36. package/lib/cjs/components/webchat-settings.js.map +1 -1
  37. package/lib/cjs/constants.d.ts +0 -12
  38. package/lib/cjs/constants.js +0 -12
  39. package/lib/cjs/constants.js.map +1 -1
  40. package/lib/cjs/contexts.d.ts +1 -5
  41. package/lib/cjs/contexts.js +10 -5
  42. package/lib/cjs/contexts.js.map +1 -1
  43. package/lib/cjs/dev-app.js +3 -11
  44. package/lib/cjs/dev-app.js.map +1 -1
  45. package/lib/cjs/index-types.d.ts +6 -28
  46. package/lib/cjs/index-types.js.map +1 -1
  47. package/lib/cjs/msg-to-botonic.js +2 -2
  48. package/lib/cjs/msg-to-botonic.js.map +1 -1
  49. package/lib/cjs/react-bot.d.ts +16 -6
  50. package/lib/cjs/react-bot.js +5 -6
  51. package/lib/cjs/react-bot.js.map +1 -1
  52. package/lib/cjs/shared/styles.d.ts +2 -2
  53. package/lib/cjs/time-zone-to-country-code.d.ts +1 -0
  54. package/lib/cjs/time-zone-to-country-code.js +108 -0
  55. package/lib/cjs/time-zone-to-country-code.js.map +1 -0
  56. package/lib/cjs/util/webchat.d.ts +4 -2
  57. package/lib/cjs/util/webchat.js +35 -1
  58. package/lib/cjs/util/webchat.js.map +1 -1
  59. package/lib/cjs/webchat/chat-area/styles.d.ts +1 -1
  60. package/lib/cjs/webchat/components/conditional-animation.js +1 -1
  61. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
  62. package/lib/cjs/webchat/components/opened-persistent-menu.js +4 -4
  63. package/lib/cjs/webchat/components/opened-persistent-menu.js.map +1 -1
  64. package/lib/cjs/webchat/context/index.d.ts +1 -1
  65. package/lib/cjs/webchat/context/index.js +4 -7
  66. package/lib/cjs/webchat/context/index.js.map +1 -1
  67. package/lib/cjs/webchat/context/types.d.ts +16 -9
  68. package/lib/cjs/webchat/context/use-webchat.d.ts +3 -4
  69. package/lib/cjs/webchat/context/use-webchat.js +35 -43
  70. package/lib/cjs/webchat/context/use-webchat.js.map +1 -1
  71. package/lib/cjs/webchat/header/default-header.js +5 -5
  72. package/lib/cjs/webchat/header/default-header.js.map +1 -1
  73. package/lib/cjs/webchat/header/styles.d.ts +7 -7
  74. package/lib/cjs/webchat/header/styles.js +5 -1
  75. package/lib/cjs/webchat/header/styles.js.map +1 -1
  76. package/lib/cjs/webchat/index-types.d.ts +0 -11
  77. package/lib/cjs/webchat/input-panel/attachment.d.ts +1 -2
  78. package/lib/cjs/webchat/input-panel/attachment.js +6 -5
  79. package/lib/cjs/webchat/input-panel/attachment.js.map +1 -1
  80. package/lib/cjs/webchat/input-panel/emoji-picker.d.ts +1 -2
  81. package/lib/cjs/webchat/input-panel/emoji-picker.js +6 -5
  82. package/lib/cjs/webchat/input-panel/emoji-picker.js.map +1 -1
  83. package/lib/cjs/webchat/input-panel/index.d.ts +1 -4
  84. package/lib/cjs/webchat/input-panel/index.js +2 -2
  85. package/lib/cjs/webchat/input-panel/index.js.map +1 -1
  86. package/lib/cjs/webchat/input-panel/persistent-menu.d.ts +1 -2
  87. package/lib/cjs/webchat/input-panel/persistent-menu.js +5 -4
  88. package/lib/cjs/webchat/input-panel/persistent-menu.js.map +1 -1
  89. package/lib/cjs/webchat/input-panel/send-button.js +4 -3
  90. package/lib/cjs/webchat/input-panel/send-button.js.map +1 -1
  91. package/lib/cjs/webchat/input-panel/styles.d.ts +3 -3
  92. package/lib/cjs/webchat/input-panel/textarea.d.ts +1 -3
  93. package/lib/cjs/webchat/input-panel/textarea.js +7 -5
  94. package/lib/cjs/webchat/input-panel/textarea.js.map +1 -1
  95. package/lib/cjs/webchat/message-list/intro-message.js +1 -1
  96. package/lib/cjs/webchat/message-list/intro-message.js.map +1 -1
  97. package/lib/cjs/webchat/message-list/styles.d.ts +5 -5
  98. package/lib/cjs/webchat/message-list/use-notifications.js +4 -4
  99. package/lib/cjs/webchat/message-list/use-notifications.js.map +1 -1
  100. package/lib/cjs/webchat/replies/styles.d.ts +3 -3
  101. package/lib/cjs/webchat/styles.d.ts +4 -9
  102. package/lib/cjs/webchat/styles.js +18 -7
  103. package/lib/cjs/webchat/styles.js.map +1 -1
  104. package/lib/cjs/webchat/theme/default-theme.d.ts +2 -0
  105. package/lib/cjs/webchat/theme/default-theme.js +104 -0
  106. package/lib/cjs/webchat/theme/default-theme.js.map +1 -0
  107. package/lib/cjs/webchat/theme/types.d.ts +59 -12
  108. package/lib/cjs/webchat/trigger-button/index.js +3 -3
  109. package/lib/cjs/webchat/trigger-button/index.js.map +1 -1
  110. package/lib/cjs/webchat/trigger-button/styles.d.ts +3 -3
  111. package/lib/cjs/webchat/typing-indicator/styles.d.ts +3 -3
  112. package/lib/cjs/webchat/webchat-dev.d.ts +1 -1
  113. package/lib/cjs/webchat/webchat.js +26 -34
  114. package/lib/cjs/webchat/webchat.js.map +1 -1
  115. package/lib/cjs/webchat/webview/index.js +1 -14
  116. package/lib/cjs/webchat/webview/index.js.map +1 -1
  117. package/lib/cjs/webchat/webview/styles.d.ts +6 -6
  118. package/lib/cjs/webchat/webview/styles.js +16 -2
  119. package/lib/cjs/webchat/webview/styles.js.map +1 -1
  120. package/lib/cjs/webchat-app.d.ts +35 -2
  121. package/lib/cjs/webchat-app.js +45 -17
  122. package/lib/cjs/webchat-app.js.map +1 -1
  123. package/lib/cjs/webchat.template.html +43 -2
  124. package/lib/cjs/webview-app.js +0 -1
  125. package/lib/cjs/webview-app.js.map +1 -1
  126. package/lib/esm/components/{button.d.ts → button/index.d.ts} +4 -5
  127. package/lib/esm/components/{button.js → button/index.js} +26 -55
  128. package/lib/esm/components/button/index.js.map +1 -0
  129. package/lib/esm/components/button/styles.d.ts +2 -0
  130. package/lib/esm/components/button/styles.js +36 -0
  131. package/lib/esm/components/button/styles.js.map +1 -0
  132. package/lib/esm/components/buttons-disabler.d.ts +20 -23
  133. package/lib/esm/components/buttons-disabler.js +11 -26
  134. package/lib/esm/components/buttons-disabler.js.map +1 -1
  135. package/lib/esm/components/carousel.js +1 -1
  136. package/lib/esm/components/carousel.js.map +1 -1
  137. package/lib/esm/components/element.js +1 -1
  138. package/lib/esm/components/element.js.map +1 -1
  139. package/lib/esm/components/image.js +1 -1
  140. package/lib/esm/components/image.js.map +1 -1
  141. package/lib/esm/components/index-types.d.ts +1 -1
  142. package/lib/esm/components/index.d.ts +1 -1
  143. package/lib/esm/components/index.js +1 -1
  144. package/lib/esm/components/index.js.map +1 -1
  145. package/lib/esm/components/message/index.js +5 -5
  146. package/lib/esm/components/message/index.js.map +1 -1
  147. package/lib/esm/components/message/message-image.js +1 -1
  148. package/lib/esm/components/message/message-image.js.map +1 -1
  149. package/lib/esm/components/message/styles.d.ts +11 -11
  150. package/lib/esm/components/message/timestamps.js +1 -1
  151. package/lib/esm/components/message/timestamps.js.map +1 -1
  152. package/lib/esm/components/multichannel/multichannel-button.js +1 -1
  153. package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
  154. package/lib/esm/components/multichannel/multichannel-carousel.js +1 -1
  155. package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
  156. package/lib/esm/components/multichannel/multichannel-utils.js +1 -1
  157. package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -1
  158. package/lib/esm/components/reply.js +4 -2
  159. package/lib/esm/components/reply.js.map +1 -1
  160. package/lib/esm/components/webchat-settings.d.ts +6 -3
  161. package/lib/esm/components/webchat-settings.js.map +1 -1
  162. package/lib/esm/constants.d.ts +0 -12
  163. package/lib/esm/constants.js +0 -12
  164. package/lib/esm/constants.js.map +1 -1
  165. package/lib/esm/contexts.d.ts +1 -5
  166. package/lib/esm/contexts.js +10 -5
  167. package/lib/esm/contexts.js.map +1 -1
  168. package/lib/esm/dev-app.js +3 -11
  169. package/lib/esm/dev-app.js.map +1 -1
  170. package/lib/esm/index-types.d.ts +6 -28
  171. package/lib/esm/index-types.js.map +1 -1
  172. package/lib/esm/msg-to-botonic.js +1 -1
  173. package/lib/esm/msg-to-botonic.js.map +1 -1
  174. package/lib/esm/react-bot.d.ts +16 -6
  175. package/lib/esm/react-bot.js +5 -6
  176. package/lib/esm/react-bot.js.map +1 -1
  177. package/lib/esm/shared/styles.d.ts +2 -2
  178. package/lib/esm/time-zone-to-country-code.d.ts +1 -0
  179. package/lib/esm/time-zone-to-country-code.js +105 -0
  180. package/lib/esm/time-zone-to-country-code.js.map +1 -0
  181. package/lib/esm/util/webchat.d.ts +4 -2
  182. package/lib/esm/util/webchat.js +33 -0
  183. package/lib/esm/util/webchat.js.map +1 -1
  184. package/lib/esm/webchat/chat-area/styles.d.ts +1 -1
  185. package/lib/esm/webchat/components/conditional-animation.js +1 -1
  186. package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
  187. package/lib/esm/webchat/components/opened-persistent-menu.js +2 -2
  188. package/lib/esm/webchat/components/opened-persistent-menu.js.map +1 -1
  189. package/lib/esm/webchat/context/index.d.ts +1 -1
  190. package/lib/esm/webchat/context/index.js +2 -4
  191. package/lib/esm/webchat/context/index.js.map +1 -1
  192. package/lib/esm/webchat/context/types.d.ts +16 -9
  193. package/lib/esm/webchat/context/use-webchat.d.ts +3 -4
  194. package/lib/esm/webchat/context/use-webchat.js +33 -41
  195. package/lib/esm/webchat/context/use-webchat.js.map +1 -1
  196. package/lib/esm/webchat/header/default-header.js +6 -6
  197. package/lib/esm/webchat/header/default-header.js.map +1 -1
  198. package/lib/esm/webchat/header/styles.d.ts +7 -7
  199. package/lib/esm/webchat/header/styles.js +6 -2
  200. package/lib/esm/webchat/header/styles.js.map +1 -1
  201. package/lib/esm/webchat/index-types.d.ts +0 -11
  202. package/lib/esm/webchat/input-panel/attachment.d.ts +1 -2
  203. package/lib/esm/webchat/input-panel/attachment.js +7 -6
  204. package/lib/esm/webchat/input-panel/attachment.js.map +1 -1
  205. package/lib/esm/webchat/input-panel/emoji-picker.d.ts +1 -2
  206. package/lib/esm/webchat/input-panel/emoji-picker.js +7 -6
  207. package/lib/esm/webchat/input-panel/emoji-picker.js.map +1 -1
  208. package/lib/esm/webchat/input-panel/index.d.ts +1 -4
  209. package/lib/esm/webchat/input-panel/index.js +2 -2
  210. package/lib/esm/webchat/input-panel/index.js.map +1 -1
  211. package/lib/esm/webchat/input-panel/persistent-menu.d.ts +1 -2
  212. package/lib/esm/webchat/input-panel/persistent-menu.js +6 -5
  213. package/lib/esm/webchat/input-panel/persistent-menu.js.map +1 -1
  214. package/lib/esm/webchat/input-panel/send-button.js +5 -4
  215. package/lib/esm/webchat/input-panel/send-button.js.map +1 -1
  216. package/lib/esm/webchat/input-panel/styles.d.ts +3 -3
  217. package/lib/esm/webchat/input-panel/textarea.d.ts +1 -3
  218. package/lib/esm/webchat/input-panel/textarea.js +7 -5
  219. package/lib/esm/webchat/input-panel/textarea.js.map +1 -1
  220. package/lib/esm/webchat/message-list/intro-message.js +1 -1
  221. package/lib/esm/webchat/message-list/intro-message.js.map +1 -1
  222. package/lib/esm/webchat/message-list/styles.d.ts +5 -5
  223. package/lib/esm/webchat/message-list/use-notifications.js +4 -4
  224. package/lib/esm/webchat/message-list/use-notifications.js.map +1 -1
  225. package/lib/esm/webchat/replies/styles.d.ts +3 -3
  226. package/lib/esm/webchat/styles.d.ts +4 -9
  227. package/lib/esm/webchat/styles.js +19 -8
  228. package/lib/esm/webchat/styles.js.map +1 -1
  229. package/lib/esm/webchat/theme/default-theme.d.ts +2 -0
  230. package/lib/esm/webchat/theme/default-theme.js +101 -0
  231. package/lib/esm/webchat/theme/default-theme.js.map +1 -0
  232. package/lib/esm/webchat/theme/types.d.ts +59 -12
  233. package/lib/esm/webchat/trigger-button/index.js +3 -3
  234. package/lib/esm/webchat/trigger-button/index.js.map +1 -1
  235. package/lib/esm/webchat/trigger-button/styles.d.ts +3 -3
  236. package/lib/esm/webchat/typing-indicator/styles.d.ts +3 -3
  237. package/lib/esm/webchat/webchat-dev.d.ts +1 -1
  238. package/lib/esm/webchat/webchat.js +29 -37
  239. package/lib/esm/webchat/webchat.js.map +1 -1
  240. package/lib/esm/webchat/webview/index.js +1 -14
  241. package/lib/esm/webchat/webview/index.js.map +1 -1
  242. package/lib/esm/webchat/webview/styles.d.ts +6 -6
  243. package/lib/esm/webchat/webview/styles.js +17 -3
  244. package/lib/esm/webchat/webview/styles.js.map +1 -1
  245. package/lib/esm/webchat-app.d.ts +35 -2
  246. package/lib/esm/webchat-app.js +45 -17
  247. package/lib/esm/webchat-app.js.map +1 -1
  248. package/lib/esm/webchat.template.html +43 -2
  249. package/lib/esm/webview-app.js +1 -2
  250. package/lib/esm/webview-app.js.map +1 -1
  251. package/package.json +4 -2
  252. package/src/components/{button.tsx → button/index.tsx} +26 -102
  253. package/src/components/button/styles.ts +38 -0
  254. package/src/components/{buttons-disabler.js → buttons-disabler.ts} +35 -39
  255. package/src/components/carousel.tsx +1 -2
  256. package/src/components/element.tsx +1 -1
  257. package/src/components/image.tsx +3 -2
  258. package/src/components/index-types.ts +1 -1
  259. package/src/components/index.ts +1 -1
  260. package/src/components/message/index.jsx +5 -9
  261. package/src/components/message/message-image.tsx +1 -4
  262. package/src/components/message/timestamps.tsx +1 -2
  263. package/src/components/multichannel/multichannel-button.jsx +1 -1
  264. package/src/components/multichannel/multichannel-carousel.jsx +1 -1
  265. package/src/components/multichannel/multichannel-utils.js +1 -1
  266. package/src/components/reply.tsx +2 -8
  267. package/src/components/webchat-settings.tsx +11 -3
  268. package/src/constants.js +0 -12
  269. package/src/contexts.tsx +11 -12
  270. package/src/dev-app.jsx +1 -25
  271. package/src/index-types.ts +8 -26
  272. package/src/msg-to-botonic.jsx +1 -1
  273. package/src/react-bot.tsx +51 -0
  274. package/src/time-zone-to-country-code.ts +104 -0
  275. package/src/util/webchat.ts +41 -2
  276. package/src/webchat/components/conditional-animation.jsx +2 -2
  277. package/src/webchat/components/opened-persistent-menu.jsx +2 -3
  278. package/src/webchat/context/index.tsx +3 -5
  279. package/src/webchat/context/types.ts +18 -13
  280. package/src/webchat/context/use-webchat.ts +36 -43
  281. package/src/webchat/header/default-header.tsx +6 -17
  282. package/src/webchat/header/styles.ts +6 -2
  283. package/src/webchat/index-types.ts +0 -12
  284. package/src/webchat/input-panel/attachment.tsx +5 -16
  285. package/src/webchat/input-panel/emoji-picker.tsx +5 -15
  286. package/src/webchat/input-panel/index.tsx +2 -13
  287. package/src/webchat/input-panel/persistent-menu.tsx +5 -15
  288. package/src/webchat/input-panel/send-button.tsx +3 -9
  289. package/src/webchat/input-panel/textarea.tsx +8 -14
  290. package/src/webchat/message-list/intro-message.tsx +1 -2
  291. package/src/webchat/message-list/use-notifications.ts +4 -8
  292. package/src/webchat/styles.ts +20 -14
  293. package/src/webchat/theme/default-theme.ts +102 -0
  294. package/src/webchat/theme/theme.d.ts +8 -0
  295. package/src/webchat/theme/types.ts +111 -24
  296. package/src/webchat/trigger-button/index.tsx +3 -5
  297. package/src/webchat/webchat.tsx +79 -102
  298. package/src/webchat/webview/index.tsx +0 -14
  299. package/src/webchat/webview/styles.ts +16 -2
  300. package/src/webchat-app.tsx +88 -35
  301. package/src/webchat.template.html +43 -2
  302. package/src/webview-app.tsx +1 -3
  303. package/lib/cjs/components/button.js.map +0 -1
  304. package/lib/esm/components/button.js.map +0 -1
  305. package/src/react-bot.jsx +0 -38
@@ -0,0 +1,38 @@
1
+ import styled from 'styled-components'
2
+
3
+ export const StyledButton = styled.button`
4
+ display: flex;
5
+ justify-content: center;
6
+ align-content: center;
7
+ gap: 6px;
8
+ cursor: pointer;
9
+ width: ${props => props.theme.button?.style?.width};
10
+ max-height: ${props => props.theme.button?.style?.maxHeight};
11
+ height: ${props => props.theme.button?.style?.height};
12
+ font-family: ${props => props.theme.style?.fontFamily};
13
+ font-size: ${props => props.theme.button?.style?.fontSize};
14
+ font-weight: ${props => props.theme.button?.style?.fontWeight};
15
+ background: ${props => props.theme.button?.style?.background};
16
+ color: ${props => props.theme.button?.style?.color};
17
+ outline: ${props => props.theme.button?.style?.outline};
18
+ border: ${props => props.theme.button?.style?.border};
19
+ border-radius: ${props => props.theme.button?.style?.borderRadius};
20
+ padding: ${props => props.theme.button?.style?.padding};
21
+ overflow: ${props => props.theme.button?.style?.overflow};
22
+
23
+ &:hover {
24
+ background: ${props => props.theme.button?.hoverBackground};
25
+ color: ${props => props.theme.button?.hoverTextColor};
26
+ }
27
+
28
+ &:disabled {
29
+ opacity: ${props => props.theme.button?.disabledstyle?.opacity};
30
+ cursor: ${props => props.theme.button?.disabledstyle?.cursor};
31
+ pointer-events: ${props =>
32
+ props.theme.button?.disabledstyle?.pointerEvents};
33
+ }
34
+ `
35
+
36
+ export const StyledUrlImage = styled.img`
37
+ width: 20px;
38
+ `
@@ -1,21 +1,35 @@
1
- import { Button } from '../components/button'
2
- import { WEBCHAT } from '../constants'
1
+ import React from 'react'
2
+
3
+ import { WebchatMessage } from '../index-types'
3
4
  import { isCarousel } from '../message-utils'
4
5
  import { strToBool } from '../util/objects'
5
6
  import { deepMapWithIndex } from '../util/react'
6
- import { _getThemeProperty } from '../util/webchat'
7
+ import { Button } from './button'
8
+ import { ButtonProps } from './index-types'
9
+
10
+ interface DisabledProps {
11
+ disabled?: boolean
12
+ autodisable?: boolean | string
13
+ disabledstyle?: Record<string, string> | string
14
+ }
7
15
 
16
+ interface AdditionalProps {
17
+ parentId: string
18
+ disabled?: boolean
19
+ setDisabled: (disabled: boolean) => void
20
+ }
8
21
  export class ButtonsDisabler {
9
- static constructBrowserProps(props) {
10
- const disabledProps = { disabled: props.disabled }
22
+ static constructBrowserProps(props: DisabledProps): DisabledProps {
23
+ const disabledProps: DisabledProps = {}
11
24
  if (props.autodisable !== undefined)
12
25
  disabledProps.autodisable = strToBool(props.autodisable)
13
26
  if (props.disabledstyle !== undefined)
14
27
  disabledProps.disabledstyle = props.disabledstyle
15
28
  return disabledProps
16
29
  }
17
- static constructNodeProps(props) {
18
- const disabledProps = {}
30
+
31
+ static constructNodeProps(props: DisabledProps): DisabledProps {
32
+ const disabledProps: DisabledProps = {}
19
33
  if (props.autodisable !== undefined)
20
34
  disabledProps.autodisable = String(props.autodisable)
21
35
  if (props.disabledstyle !== undefined)
@@ -23,7 +37,7 @@ export class ButtonsDisabler {
23
37
  return disabledProps
24
38
  }
25
39
 
26
- static withDisabledProps(props) {
40
+ static withDisabledProps(props: DisabledProps): DisabledProps {
27
41
  return {
28
42
  disabled: props.disabled,
29
43
  autodisable: props.autodisable,
@@ -31,44 +45,25 @@ export class ButtonsDisabler {
31
45
  }
32
46
  }
33
47
 
34
- static resolveDisabling(theme, props) {
35
- const getThemeProperty = _getThemeProperty(theme)
36
- const autoDisable =
37
- props.autodisable !== undefined
38
- ? props.autodisable
39
- : getThemeProperty(
40
- WEBCHAT.CUSTOM_PROPERTIES.buttonAutoDisable,
41
- WEBCHAT.DEFAULTS.BUTTON_AUTO_DISABLE
42
- )
43
- const computedDisabledStyle =
44
- props.disabledstyle !== undefined
45
- ? props.disabledstyle
46
- : getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.buttonDisabledStyle, {})
47
-
48
- const disabledStyle = {
49
- ...WEBCHAT.DEFAULTS.BUTTON_DISABLED_STYLE,
50
- ...computedDisabledStyle,
51
- }
52
- return { autoDisable, disabledStyle }
53
- }
54
-
55
- static updateChildrenButtons(children, additionalProps = undefined) {
56
- return deepMapWithIndex(children, n => {
57
- if (n.type === Button) return this.updateButtons(n, additionalProps)
58
- return n
48
+ static updateChildrenButtons(
49
+ children: React.ReactNode,
50
+ additionalProps?: AdditionalProps
51
+ ): React.ReactNode {
52
+ return deepMapWithIndex(children, (node: any) => {
53
+ if (node.type === Button) return this.updateButtons(node, additionalProps)
54
+ return node
59
55
  })
60
56
  }
61
57
 
62
- static updateButtons(node, additionalProps) {
63
- if (!additionalProps) additionalProps = {}
64
- else {
58
+ static updateButtons(node: any, additionalProps?: AdditionalProps): any {
59
+ if (additionalProps) {
65
60
  additionalProps = {
61
+ parentId: additionalProps.parentId,
66
62
  disabled:
67
63
  node.props.disabled === true
68
64
  ? node.props.disabled
69
65
  : additionalProps.disabled,
70
66
  setDisabled: additionalProps.setDisabled,
71
- parentId: additionalProps.parentId,
72
67
  }
73
68
  }
74
69
  return {
@@ -80,8 +75,8 @@ export class ButtonsDisabler {
80
75
  }
81
76
  }
82
77
 
83
- static getUpdatedMessage(messageToUpdate, { autoDisable, disabledStyle }) {
84
- const updateMsgButton = button => {
78
+ static getUpdatedMessage(messageToUpdate: WebchatMessage): WebchatMessage {
79
+ const updateMsgButton = (button: ButtonProps) => {
85
80
  return {
86
81
  ...button,
87
82
  ...{
@@ -89,6 +84,7 @@ export class ButtonsDisabler {
89
84
  },
90
85
  }
91
86
  }
87
+
92
88
  if (
93
89
  isCarousel(messageToUpdate) &&
94
90
  messageToUpdate.data &&
@@ -88,8 +88,7 @@ export const Carousel = (props: CarouselProps) => {
88
88
  )
89
89
  // TODO: Investigate why when set to false, scroll is enabled via dragging the bar but not hovering the carousel elements
90
90
  const carouselArrowsEnabled = getThemeProperty(
91
- WEBCHAT.CUSTOM_PROPERTIES.enableCarouselArrows,
92
- true
91
+ WEBCHAT.CUSTOM_PROPERTIES.enableCarouselArrows
93
92
  )
94
93
 
95
94
  const scrollCarouselBy = value => {
@@ -3,7 +3,7 @@ import styled from 'styled-components'
3
3
 
4
4
  import { COLORS, WEBCHAT } from '../constants'
5
5
  import { renderComponent } from '../util/react'
6
- import { Button } from './button'
6
+ import { Button } from './button/index'
7
7
 
8
8
  const ElementContainer = styled.div`
9
9
  display: flex;
@@ -37,9 +37,9 @@ export const Image = (props: ImageProps) => {
37
37
 
38
38
  const { getThemeProperty } = useContext(WebchatContext)
39
39
  const ImagePreviewer = getThemeProperty(
40
- WEBCHAT.CUSTOM_PROPERTIES.imagePreviewer,
41
- null
40
+ WEBCHAT.CUSTOM_PROPERTIES.imagePreviewer
42
41
  )
42
+
43
43
  if (isBrowser()) {
44
44
  content = (
45
45
  <>
@@ -59,6 +59,7 @@ export const Image = (props: ImageProps) => {
59
59
  </>
60
60
  )
61
61
  }
62
+
62
63
  return (
63
64
  <Message
64
65
  role={ROLES.IMAGE_MESSAGE}
@@ -51,7 +51,7 @@ export interface ButtonProps {
51
51
  onClick?: () => void
52
52
  autodisable?: boolean
53
53
  disabled?: boolean
54
- disabledstyle?: boolean
54
+ disabledstyle?: Record<string, string> | string
55
55
  children: string
56
56
  setDisabled?: (disabled: boolean) => void
57
57
  parentId?: string
@@ -1,5 +1,5 @@
1
1
  export { Audio } from './audio'
2
- export { Button } from './button'
2
+ export { Button } from './button/index'
3
3
  export { Carousel } from './carousel'
4
4
  export { customMessage } from './custom-message'
5
5
  export { Document } from './document'
@@ -9,7 +9,7 @@ import { Fade } from '../../shared/styles'
9
9
  import { isDev } from '../../util/environment'
10
10
  import { ConditionalWrapper, renderComponent } from '../../util/react'
11
11
  import { WebchatContext } from '../../webchat/context'
12
- import { Button } from '../button'
12
+ import { Button } from '../button/index'
13
13
  import { ButtonsDisabler } from '../buttons-disabler'
14
14
  import { getMarkdownStyle, renderLinks, renderMarkdown } from '../markdown'
15
15
  import { Reply } from '../reply'
@@ -49,7 +49,7 @@ export const Message = props => {
49
49
  const markdown = props.markdown
50
50
  const { webchatState, addMessage, updateReplies, getThemeProperty } =
51
51
  useContext(WebchatContext)
52
- const [state, setState] = useState({
52
+ const [state] = useState({
53
53
  id: props.id || uuidv7(),
54
54
  })
55
55
 
@@ -139,10 +139,7 @@ export const Message = props => {
139
139
  }
140
140
  }, [webchatState.messagesJSON])
141
141
 
142
- const brandColor = getThemeProperty(
143
- WEBCHAT.CUSTOM_PROPERTIES.brandColor,
144
- COLORS.BOTONIC_BLUE
145
- )
142
+ const brandColor = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.brandColor)
146
143
 
147
144
  const getBgColor = () => {
148
145
  if (!blob) return COLORS.TRANSPARENT
@@ -165,7 +162,7 @@ export const Message = props => {
165
162
 
166
163
  const userOrBotMessage = isSentByUser ? SENDERS.user : SENDERS.bot
167
164
  const hasBlobTick = () =>
168
- getThemeProperty(`message.${userOrBotMessage}.blobTick`, true)
165
+ getThemeProperty(`message.${userOrBotMessage}.blobTick`)
169
166
 
170
167
  const renderBrowser = () => {
171
168
  const messageJSON = webchatState.messagesJSON.find(m => m.id === state.id)
@@ -205,8 +202,7 @@ export const Message = props => {
205
202
  }
206
203
 
207
204
  const animationsEnabled = getThemeProperty(
208
- WEBCHAT.CUSTOM_PROPERTIES.enableAnimations,
209
- true
205
+ WEBCHAT.CUSTOM_PROPERTIES.enableAnimations
210
206
  )
211
207
 
212
208
  const resolveCustomTypeName = () =>
@@ -23,10 +23,7 @@ export const MessageImage = ({ imagestyle, sentBy }: MessageImageProps) => {
23
23
 
24
24
  const BotMessageImage = getThemeProperty(
25
25
  WEBCHAT.CUSTOM_PROPERTIES.botMessageImage,
26
- getThemeProperty(
27
- WEBCHAT.CUSTOM_PROPERTIES.brandImage,
28
- WEBCHAT.DEFAULTS.LOGO
29
- )
26
+ getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.brandImage)
30
27
  )
31
28
 
32
29
  const AgentMessageImage = getThemeProperty(
@@ -62,8 +62,7 @@ export const MessageTimestamp = ({
62
62
  const isSentByAgent = sentBy === SENDERS.agent
63
63
 
64
64
  const BotMessageImage = getThemeProperty(
65
- WEBCHAT.CUSTOM_PROPERTIES.botMessageImage,
66
- undefined
65
+ WEBCHAT.CUSTOM_PROPERTIES.botMessageImage
67
66
  )
68
67
 
69
68
  const AgentMessageImage = getThemeProperty(
@@ -3,7 +3,7 @@ import React, { useContext } from 'react'
3
3
 
4
4
  import { RequestContext } from '../../contexts'
5
5
  import { truncateText } from '../../util'
6
- import { Button } from '../button'
6
+ import { Button } from '../button/index'
7
7
  import { MultichannelContext } from './multichannel-context'
8
8
  import { WHATSAPP_MAX_BUTTON_CHARS } from './whatsapp/constants'
9
9
 
@@ -2,7 +2,7 @@ import { isDev, isFacebook, isWebchat, isWhatsapp } from '@botonic/core'
2
2
  import React, { useContext } from 'react'
3
3
 
4
4
  import { RequestContext } from '../../contexts'
5
- import { Button } from '../button'
5
+ import { Button } from '../button/index'
6
6
  import { Carousel } from '../carousel'
7
7
  import { Image } from '../image'
8
8
  import { Text } from '../text'
@@ -1,4 +1,4 @@
1
- import { Button } from '../button'
1
+ import { Button } from '../button/index'
2
2
  import { Carousel } from '../carousel'
3
3
  import { Pic } from '../pic'
4
4
  import { Reply } from '../reply'
@@ -11,6 +11,8 @@ const StyledButton = styled.button`
11
11
  padding: 4px 8px;
12
12
  font-family: inherit;
13
13
  border-radius: 8px;
14
+ border: 1px solid ${props => props.theme.brand?.color};
15
+ color: ${props => props.theme.brand?.color};
14
16
  cursor: pointer;
15
17
  outline: 0;
16
18
  `
@@ -41,14 +43,6 @@ export const Reply = (props: ReplyProps) => {
41
43
  return (
42
44
  <StyledButton
43
45
  style={{
44
- border: `1px solid ${getThemeProperty(
45
- WEBCHAT.CUSTOM_PROPERTIES.brandColor,
46
- COLORS.BOTONIC_BLUE
47
- )}`,
48
- color: getThemeProperty(
49
- WEBCHAT.CUSTOM_PROPERTIES.brandColor,
50
- COLORS.BOTONIC_BLUE
51
- ),
52
46
  ...replyStyle,
53
47
  }}
54
48
  onClick={e => handleClick(e)}
@@ -4,7 +4,10 @@ import React, { useContext } from 'react'
4
4
  import { renderComponent } from '../util/react'
5
5
  import { stringifyWithRegexs } from '../util/regexs'
6
6
  import { WebchatContext } from '../webchat/context'
7
- import { PersistentMenuOptionsTheme, ThemeProps } from '../webchat/theme/types'
7
+ import {
8
+ PersistentMenuOptionsTheme,
9
+ WebchatTheme,
10
+ } from '../webchat/theme/types'
8
11
  import { BlockInputOption } from './index-types'
9
12
 
10
13
  export interface WebchatSettingsProps {
@@ -14,8 +17,13 @@ export interface WebchatSettingsProps {
14
17
  enableEmojiPicker?: boolean
15
18
  enableUserInput?: boolean
16
19
  persistentMenu?: PersistentMenuOptionsTheme
17
- theme?: ThemeProps
18
- user?: { extra_data?: any }
20
+ theme?: Partial<WebchatTheme>
21
+ user?: {
22
+ extra_data?: any
23
+ country?: string
24
+ locale?: string
25
+ system_locale?: string
26
+ }
19
27
  }
20
28
 
21
29
  export const WebchatSettings = ({
package/src/constants.js CHANGED
@@ -33,25 +33,13 @@ export const COLORS = {
33
33
 
34
34
  export const WEBCHAT = {
35
35
  DEFAULTS: {
36
- WIDTH: 300,
37
- HEIGHT: 450,
38
- TITLE: 'Botonic',
39
36
  LOGO: BotonicLogo,
40
37
  URL_ICON: UrlIcon,
41
- PLACEHOLDER: 'Ask me something...',
42
- FONT_FAMILY: "'Noto Sans JP', sans-serif",
43
- BORDER_RADIUS_TOP_CORNERS: '6px 6px 0px 0px',
44
38
  ELEMENT_WIDTH: 222,
45
39
  ELEMENT_MARGIN_RIGHT: 6,
46
40
  STORAGE_KEY: 'botonicState',
47
41
  HOST_ID: 'root',
48
42
  ID: 'botonic-webchat',
49
- BUTTON_AUTO_DISABLE: false,
50
- BUTTON_DISABLED_STYLE: {
51
- opacity: 0.5,
52
- cursor: 'auto',
53
- pointerEvents: 'none',
54
- },
55
43
  },
56
44
  CUSTOM_PROPERTIES: {
57
45
  // General
package/src/contexts.tsx CHANGED
@@ -3,19 +3,20 @@ import { createContext } from 'react'
3
3
 
4
4
  import { ActionRequest } from './index-types'
5
5
 
6
- export const RequestContext = createContext<
7
- Partial<ActionRequest> & {
8
- getString: () => string
9
- setLocale: () => void
10
- }
11
- >({
12
- getString: () => '',
13
- setLocale: () => undefined,
14
- session: {} as CoreSession,
6
+ export const RequestContext = createContext<ActionRequest>({
7
+ getUserCountry: () => '',
8
+ getUserLocale: () => '',
9
+ getSystemLocale: () => '',
10
+ setUserCountry: () => undefined,
11
+ setUserLocale: () => undefined,
12
+ setSystemLocale: () => undefined,
15
13
  params: {},
16
- input: {} as CoreInput,
17
14
  defaultDelay: 0,
18
15
  defaultTyping: 0,
16
+ input: {} as CoreInput,
17
+ session: {} as CoreSession,
18
+ lastRoutePath: '',
19
+ plugins: {},
19
20
  })
20
21
 
21
22
  export interface CloseWebviewOptions {
@@ -26,12 +27,10 @@ export interface CloseWebviewOptions {
26
27
 
27
28
  export const WebviewRequestContext = createContext<{
28
29
  closeWebview: (options?: CloseWebviewOptions) => Promise<void>
29
- getString?: (stringId: string) => string
30
30
  params: Record<string, any>
31
31
  session: Partial<CoreSession>
32
32
  }>({
33
33
  closeWebview: async () => undefined,
34
- getString: undefined,
35
34
  params: {} as Record<string, any>,
36
35
  session: {} as Partial<CoreSession>,
37
36
  })
package/src/dev-app.jsx CHANGED
@@ -1,4 +1,3 @@
1
- import merge from 'lodash.merge'
2
1
  import React from 'react'
3
2
  import { createRoot } from 'react-dom/client'
4
3
 
@@ -56,13 +55,6 @@ export class DevApp extends WebchatApp {
56
55
  getComponent(host, optionsAtRuntime = {}) {
57
56
  let {
58
57
  theme = {},
59
- persistentMenu,
60
- coverComponent,
61
- blockInputs,
62
- enableEmojiPicker,
63
- enableAttachments,
64
- enableUserInput,
65
- enableAnimations,
66
58
  storage,
67
59
  storageKey,
68
60
  onInit,
@@ -73,14 +65,7 @@ export class DevApp extends WebchatApp {
73
65
  hostId,
74
66
  ...webchatOptions
75
67
  } = optionsAtRuntime
76
- theme = merge(this.theme, theme)
77
- persistentMenu = persistentMenu || this.persistentMenu
78
- coverComponent = coverComponent || this.coverComponent
79
- blockInputs = blockInputs || this.blockInputs
80
- enableEmojiPicker = enableEmojiPicker || this.enableEmojiPicker
81
- enableAttachments = enableAttachments || this.enableAttachments
82
- enableUserInput = enableUserInput || this.enableUserInput
83
- enableAnimations = enableAnimations || this.enableAnimations
68
+ theme = super.createInitialTheme(optionsAtRuntime)
84
69
  storage = storage || this.storage
85
70
  storageKey = storageKey || this.storageKey
86
71
  this.onInit = onInit || this.onInit
@@ -97,17 +82,8 @@ export class DevApp extends WebchatApp {
97
82
  host={this.host}
98
83
  shadowDOM={this.shadowDOM}
99
84
  theme={theme}
100
- persistentMenu={persistentMenu}
101
- coverComponent={coverComponent}
102
- blockInputs={blockInputs}
103
- enableEmojiPicker={enableEmojiPicker}
104
- enableAttachments={enableAttachments}
105
- enableUserInput={enableUserInput}
106
- enableAnimations={enableAnimations}
107
85
  storage={storage}
108
86
  storageKey={storageKey}
109
- getString={(stringId, session) => this.bot.getString(stringId, session)}
110
- setLocale={(locale, session) => this.bot.setLocale(locale, session)}
111
87
  onInit={(...args) => this.onInitWebchat(...args)}
112
88
  onOpen={(...args) => this.onOpenWebchat(...args)}
113
89
  onClose={(...args) => this.onCloseWebchat(...args)}
@@ -1,8 +1,8 @@
1
1
  import {
2
+ BotContext,
2
3
  BotRequest as CoreBotRequest,
3
4
  Input as CoreInput,
4
5
  InputType as CoreInputType,
5
- Plugin as CorePlugin,
6
6
  Route as CoreRoute,
7
7
  Routes as CoreRoutes,
8
8
  ServerConfig,
@@ -22,7 +22,7 @@ import { UseWebchat } from './webchat/context/use-webchat'
22
22
  import {
23
23
  CoverComponentOptions,
24
24
  PersistentMenuOptionsTheme,
25
- ThemeProps,
25
+ WebchatTheme,
26
26
  } from './webchat/theme/types'
27
27
  import { WebchatApp } from './webchat-app'
28
28
 
@@ -38,21 +38,9 @@ export interface Route extends CoreRoute {
38
38
  }
39
39
  export type Routes = CoreRoutes<Route>
40
40
 
41
- // Parameters of the actions' botonicInit method
42
- export interface ActionRequest {
43
- defaultDelay: number
44
- defaultTyping: number
45
- input: CoreInput
46
- lastRoutePath: string
47
- params: { [key: string]: string }
48
- plugins: { [id: string]: CorePlugin }
49
- session: CoreSession
50
- }
51
-
52
- export interface RequestContextInterface extends ActionRequest {
53
- getString: (stringId: string) => string
54
- setLocale: (locale: string) => string
55
- }
41
+ // Parameters of the actions in botonicInit method
42
+ // the ActionRequest is provided by the context of the core-bot
43
+ export type ActionRequest = BotContext
56
44
 
57
45
  export interface WebchatRef {
58
46
  addBotResponse: ({
@@ -88,7 +76,7 @@ interface AddBotResponseArgs {
88
76
  }
89
77
 
90
78
  export interface WebchatArgs {
91
- theme?: ThemeProps
79
+ theme?: Partial<WebchatTheme>
92
80
  persistentMenu?: PersistentMenuOptionsTheme
93
81
  coverComponent?: CoverComponentOptions
94
82
  blockInputs?: BlockInputOption[]
@@ -120,14 +108,7 @@ export interface WebchatProps {
120
108
  onStateChange: (args: OnStateChangeArgs) => void
121
109
 
122
110
  shadowDOM?: any
123
- theme?: ThemeProps
124
- persistentMenu?: PersistentMenuOptionsTheme
125
- coverComponent?: CoverComponentOptions
126
- blockInputs?: BlockInputOption[]
127
- enableEmojiPicker?: boolean
128
- enableAttachments?: boolean
129
- enableUserInput?: boolean
130
- enableAnimations?: boolean
111
+ theme?: WebchatTheme
131
112
  storage?: Storage | null
132
113
  storageKey?: string | (() => string)
133
114
  defaultDelay?: number
@@ -215,3 +196,4 @@ interface UpdateMessageInfoEvent {
215
196
  }
216
197
 
217
198
  export { CaseEventQueuePositionChangedInput } from '@botonic/core'
199
+ export { WebchatTheme }
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
 
3
3
  import { Audio } from './components/audio'
4
- import { Button } from './components/button'
4
+ import { Button } from './components/button/index'
5
5
  import { ButtonsDisabler } from './components/buttons-disabler'
6
6
  import { Carousel } from './components/carousel'
7
7
  import { Document } from './components/document'
@@ -0,0 +1,51 @@
1
+ import { CoreBot } from '@botonic/core'
2
+ import React from 'react'
3
+
4
+ import { Text } from './components/text'
5
+ import { RequestContext } from './contexts'
6
+ import { ActionRequest } from './index-types'
7
+
8
+ type ActionComponentType<P = any> = React.ComponentType<P> & {
9
+ botonicInit?: (request: ActionRequest) => Promise<P>
10
+ contextType?: React.Context<typeof RequestContext>
11
+ render: (props: P) => JSX.Element
12
+ }
13
+ interface RenderReactActionsArgs {
14
+ request: ActionRequest
15
+ actions: ActionComponentType[]
16
+ }
17
+
18
+ export class ReactBot extends CoreBot {
19
+ constructor(options: any) {
20
+ super({
21
+ defaultRoutes: [
22
+ {
23
+ path: '404',
24
+ action: () => <Text>I don't understand you</Text>, // eslint-disable-line
25
+ },
26
+ ],
27
+ renderer: (args: RenderReactActionsArgs) => this.renderReactActions(args),
28
+ ...options,
29
+ })
30
+ }
31
+
32
+ async renderReactActions({ request, actions }: RenderReactActionsArgs) {
33
+ const renderedActions: JSX.Element[] = []
34
+
35
+ for (const Action of actions) {
36
+ if (Action) {
37
+ const props = Action.botonicInit
38
+ ? await Action.botonicInit(request)
39
+ : {}
40
+ const renderedAction: JSX.Element = (
41
+ <RequestContext.Provider value={request}>
42
+ <Action {...props} />
43
+ </RequestContext.Provider>
44
+ )
45
+ renderedActions.push(renderedAction)
46
+ }
47
+ }
48
+
49
+ return renderedActions
50
+ }
51
+ }