forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreview.tsx
More file actions
40 lines (31 loc) · 1007 Bytes
/
Preview.tsx
File metadata and controls
40 lines (31 loc) · 1007 Bytes
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
import * as React from 'react';
import { ISandpackContext } from '../../types';
import withSandpack from '../../utils/with-sandpack';
export interface PreviewProps {
sandpack: ISandpackContext;
}
class Preview extends React.Component<PreviewProps> {
container?: HTMLDivElement;
setContainerElement = (el: HTMLDivElement) => {
this.container = el;
};
initializeFrame = () => {
const { browserFrame } = this.props.sandpack;
if (browserFrame && this.container) {
browserFrame.style.width = '100%';
browserFrame.style.height = '500px';
browserFrame.style.visibility = 'visible';
browserFrame.style.position = 'relative';
this.container.appendChild(browserFrame);
}
};
componentDidUpdate(prevProps: PreviewProps) {
if (prevProps.sandpack.browserFrame !== this.props.sandpack.browserFrame) {
this.initializeFrame();
}
}
render() {
return <div ref={this.setContainerElement} />;
}
}
export default withSandpack(Preview);