-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPinturaEditorOverlay.js
43 lines (36 loc) · 1.07 KB
/
PinturaEditorOverlay.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';
import { overlayEditor } from '@pqina/pintura';
import { sub, unsub } from './events';
class PinturaEditorOverlay extends React.Component {
constructor(props) {
super(props);
this.elementRef = React.createRef();
this.editor = undefined;
}
componentDidMount() {
if (!this.elementRef.current) return;
const props = { ...this.props };
this.editor = overlayEditor(this.elementRef.current, props);
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;
}
render() {
return React.createElement('div', {
className: `PinturaRootWrapper ${
this.props.className ? this.props.className : ''
}`.trim(),
ref: this.elementRef,
});
}
}
export default PinturaEditorOverlay;