-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlit-react-wrapper.js
61 lines (50 loc) · 1.3 KB
/
lit-react-wrapper.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
52
53
54
55
56
57
58
59
60
61
import { html, LitElement } from 'lit';
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import * as retargetEvents from 'react-shadow-dom-retarget-events';
import { StylesProvider, jssPreset } from '@material-ui/styles';
import { create } from 'jss';
class LitReactWrapper extends LitElement {
static get properties(){
return {
mountPoint: Object,
props: Object,
element: Object
}
}
constructor(){
super();
this.props={};
}
render() {
return html`
<div id="mountPoint"></div>
`;
}
createElement() {
this.reactElement = React.createElement(this.element, this.props, React.createElement('slot'));
return this.reactElement;
}
renderElement(){
const jss = create({
...jssPreset(),
insertionPoint: this.mountPoint
});
ReactDOM.render(
<StylesProvider jss={jss} sheetsManager={new Map()}>
{this.createElement()}
</StylesProvider>,
this.mountPoint
);
}
firstUpdated() {
this.mountPoint = this.shadowRoot.getElementById('mountPoint');
this.renderElement();
retargetEvents(this.shadowRoot);
}
updated(changedProperties){
if(changedProperties)
this.renderElement();
}
}
window.customElements.define('lit-react-wrapper', LitReactWrapper);