-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPinturaEditorModal.js
51 lines (41 loc) · 1.21 KB
/
PinturaEditorModal.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
44
45
46
47
48
49
50
51
import React from 'react';
import { openEditor } from '@pqina/pintura';
import { sub, unsub } from './events';
class PinturaEditorModal extends React.Component {
constructor(props) {
super(props);
this.editor = undefined;
}
componentDidMount() {
// We'll wrap the module in a container so we can use the container as a CSS module target
this.el = document.createElement('div');
if (this.props.className) this.el.className = this.props.className;
document.body.append(this.el);
// Create editor and proxy events
const props = { ...this.props };
this.editor = openEditor({ ...props, enableAutoDestroy: false }, this.el);
sub(this, props);
}
componentDidUpdate() {
const props = { ...this.props };
Object.assign(this.editor, props);
sub(this, props);
}
componentWillUnmount() {
if (!this.editor) return;
unsub(this);
this.editor.destroy();
this.editor = undefined;
this.el.remove();
}
show() {
this.editor.show();
}
hide() {
this.editor.hide();
}
render() {
return null;
}
}
export default PinturaEditorModal;