Skip to content

Commit ed55f44

Browse files
committed
support Chatwoot expanded bubble
1 parent 3068167 commit ed55f44

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ You can customise the Chatwoot Widget by passing the following props to the
336336
`Chatwoot` component:
337337

338338
- `color`: The background color, set to same color value you choose in Chatwoot dashboard.
339+
- `launcherTitle`: The text used for the [Expanded Bubble](https://www.chatwoot.com/docs/product/channels/live-chat/sdk/setup#widget-designs) design. Setting to any non-empty string will enable expanded bubble design automatically. Default to null.
339340

340341
</details>
341342

src/components/Chatwoot/index.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import useChat from '../../hooks/useChat'
55
const styles: {
66
button: CSSProperties
77
img: CSSProperties
8+
expandedButton: CSSProperties
9+
expandedImg: CSSProperties
10+
launcherTitle: CSSProperties
811
close: CSSProperties
912
} = {
1013
button: {
@@ -24,6 +27,27 @@ const styles: {
2427
margin: '20px',
2528
width: '24px'
2629
},
30+
expandedButton: {
31+
display: 'flex',
32+
bottom: '24px',
33+
height: '48px',
34+
width: 'auto'
35+
},
36+
expandedImg: {
37+
height: '20px',
38+
margin: '14px 8px 14px 16px',
39+
width: '20px'
40+
},
41+
launcherTitle: {
42+
display: 'flex',
43+
color: '#fff',
44+
alignItems: 'center',
45+
paddingRight: '20px',
46+
fontFamily:
47+
'system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, Arial, sans-serif',
48+
fontSize: '16px',
49+
fontWeight: 500
50+
},
2751
close: {
2852
backgroundColor: '#fff',
2953
height: '24px',
@@ -36,9 +60,10 @@ const styles: {
3660

3761
interface Props {
3862
color?: string
63+
launcherTitle?: string
3964
}
4065

41-
const Provider = ({ color }: Props): JSX.Element | null => {
66+
const Provider = ({ color, launcherTitle }: Props): JSX.Element | null => {
4267
const [state, loadChat] = useChat({ loadWhenIdle: true })
4368

4469
if (state === 'complete') return null
@@ -54,15 +79,24 @@ const Provider = ({ color }: Props): JSX.Element | null => {
5479
onMouseEnter={() => loadChat({ open: false })}
5580
style={{
5681
...styles.button,
82+
...(launcherTitle && styles.expandedButton),
5783
backgroundColor: color
5884
}}
5985
>
6086
{state === 'initial' ? (
61-
<img
62-
style={styles.img}
63-
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAUVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////8IN+deAAAAGnRSTlMAAwgJEBk0TVheY2R5eo+ut8jb5OXs8fX2+cjRDTIAAADsSURBVHgBldZbkoMgFIThRgQv8SKKgGf/C51UnJqaRI30/9zfe+NQUQ3TvG7bOk9DVeCmshmj/CuOTYnrdBfkUOg0zlOtl9OWVuEk4+QyZ3DIevmSt/ioTvK1VH/s5bY3YdM9SBZ/mUUyWgx+U06ycgp7D8msxSvtc4HXL9BLdj2elSEfhBJAI0QNgJEBI1BEBsQClVBVGDgwYOLAhJkDM1YOrNg4sLFAsLJgZsHEgoEFFQt0JAFGFjQsKAMJ0LFAexKgZYFyJIDxJIBNJEDNAtSJBLCeBDCOBFAPzwFA94ED+zmhwDO9358r8ANtIsMXi7qVAwAAAABJRU5ErkJggg=="
64-
alt="bubble-icon"
65-
/>
87+
<>
88+
<img
89+
style={{
90+
...styles.img,
91+
...(launcherTitle && styles.expandedImg)
92+
}}
93+
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAUVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////8IN+deAAAAGnRSTlMAAwgJEBk0TVheY2R5eo+ut8jb5OXs8fX2+cjRDTIAAADsSURBVHgBldZbkoMgFIThRgQv8SKKgGf/C51UnJqaRI30/9zfe+NQUQ3TvG7bOk9DVeCmshmj/CuOTYnrdBfkUOg0zlOtl9OWVuEk4+QyZ3DIevmSt/ioTvK1VH/s5bY3YdM9SBZ/mUUyWgx+U06ycgp7D8msxSvtc4HXL9BLdj2elSEfhBJAI0QNgJEBI1BEBsQClVBVGDgwYOLAhJkDM1YOrNg4sLFAsLJgZsHEgoEFFQt0JAFGFjQsKAMJ0LFAexKgZYFyJIDxJIBNJEDNAtSJBLCeBDCOBFAPzwFA94ED+zmhwDO9358r8ANtIsMXi7qVAwAAAABJRU5ErkJggg=="
94+
alt="bubble-icon"
95+
/>
96+
{launcherTitle ? (
97+
<div style={styles.launcherTitle}>{launcherTitle}</div>
98+
) : null}
99+
</>
66100
) : (
67101
<>
68102
<div style={{ ...styles.close, transform: 'rotate(45deg)' }} />

0 commit comments

Comments
 (0)