-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathbutton.js
43 lines (40 loc) · 1.13 KB
/
button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from 'react';
const Button = ({ showResult }) => {
const [result, setResult] = React.useState(null);
React.useEffect(() => {
if (document.getElementById('polotno-button')) {
return;
}
const script = document.createElement('script');
script.id = 'polotno-button';
script.src = 'https://embed.polotno.com/button-v1.js';
script.async = true;
document.body.appendChild(script);
}, []);
return (
<div style={{ textAlign: 'center' }}>
<button
className="button button--primary"
onClick={() => {
window.createPolotnoEditor({
jsonUrl:
'https://api.polotno.com/templates/2021-10-25-instagram-post-sunday-reminder.json',
onPublish: ({ dataURL, json }) => {
setResult(dataURL);
console.log('polotno json', json);
},
});
}}
>
Open Polotno Editor
</button>
{result && showResult && (
<>
<p>Result:</p>
<img id="result" src={result} style={{ height: '200px' }} />
</>
)}
</div>
);
};
export default Button;