Skip to content

Commit 52b9582

Browse files
authored
Merge pull request #3 from team-plain/add-chat-widget
add live chat to contact form example
2 parents b46c6af + 9edb1ed commit 52b9582

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

pages/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
import { useEffect } from 'react';
12
import type { NextPage } from 'next';
23
import Head from 'next/head';
34
import { HelpButton } from '../src/components/helpButton';
45

56
const Home: NextPage = () => {
7+
useEffect(() => {
8+
let script = document.createElement('script');
9+
script.async = false;
10+
script.onload = function(){
11+
(window as any).Plain.init({
12+
appId: 'liveChatApp_01J9XJ0Z9WZC9CXQXMR7FT1BC7',
13+
hideLauncher: true,
14+
});
15+
};
16+
script.src = 'https://chat.cdn-plain.com/index.js';
17+
document.getElementsByTagName('head')[0].appendChild(script);
18+
19+
}, []);
20+
621
return (
722
<>
823
<Head>

src/components/helpButton.module.css

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
opacity: 0;
44
transform: translateY(2px);
55
}
6+
67
to {
78
opacity: 1;
89
transform: translateY(0);
@@ -11,23 +12,23 @@
1112

1213

1314
.helpButton {
14-
border-radius: 100%;
15-
background: #e9d5ff;
16-
color: #4c1d95;
17-
width: 42px;
18-
height: 42px;
19-
border: none;
20-
position: fixed;
21-
bottom: 24px;
22-
right: 24px;
23-
display: flex;
24-
align-items: center;
25-
justify-content: center;
26-
cursor: pointer;
15+
border-radius: 100%;
16+
background: #e9d5ff;
17+
color: #4c1d95;
18+
width: 42px;
19+
height: 42px;
20+
border: none;
21+
position: fixed;
22+
bottom: 24px;
23+
right: 24px;
24+
display: flex;
25+
align-items: center;
26+
justify-content: center;
27+
cursor: pointer;
2728
}
2829

2930
.helpButton:focus {
30-
outline: none;
31+
outline: none;
3132
}
3233

3334
.popoverContent {
@@ -36,16 +37,16 @@
3637
padding: 24px;
3738
width: 260px;
3839
background-color: white;
39-
box-shadow: 0px 0.8px 2.7px rgba(0, 0, 0, 0.012),
40-
0px 2px 6.9px rgba(0, 0, 0, 0.018),
41-
0px 4.1px 14.2px rgba(0, 0, 0, 0.022),
42-
0px 8.4px 29.2px rgba(0, 0, 0, 0.028),
43-
0px 23px 80px rgba(0, 0, 0, 0.04);
40+
box-shadow: 0px 0.8px 2.7px rgba(0, 0, 0, 0.012),
41+
0px 2px 6.9px rgba(0, 0, 0, 0.018),
42+
0px 4.1px 14.2px rgba(0, 0, 0, 0.022),
43+
0px 8.4px 29.2px rgba(0, 0, 0, 0.028),
44+
0px 23px 80px rgba(0, 0, 0, 0.04);
4445
animation-duration: 400ms;
4546
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
4647
will-change: transform, opacity;
4748
transition: width 300ms ease, height 300ms ease;
48-
height: 218px;
49+
height: 248px;
4950
}
5051

5152
.popoverContentLarge {
@@ -54,7 +55,7 @@
5455
}
5556

5657
.popoverContent:focus {
57-
outline: none;
58+
outline: none;
5859
}
5960

6061
.popoverContent[data-state='open'] {
@@ -100,4 +101,4 @@
100101
display: flex;
101102
justify-content: center;
102103
align-items: center;
103-
}
104+
}

src/components/helpButton.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ export function HelpButton() {
7474
setIsContactFormOpen(true);
7575
}}
7676
/>
77+
<LinkRow
78+
label="Chat with us"
79+
href="#"
80+
icon={<ChatAltIcon />}
81+
onClick={(e) => {
82+
e.preventDefault();
83+
setIsOpen(false);
84+
(window as any).Plain.open();
85+
}}
86+
/>
7787
</>
7888
)}
7989

0 commit comments

Comments
 (0)