joyent-portal/packages/ui-toolkit/src/editor/index.js

49 lines
999 B
JavaScript
Raw Normal View History

2017-09-27 17:22:01 +03:00
import React, { Component } from 'react';
import Bundle from 'react-bundle';
import Loader from '../status-loader';
class ManifestEditorBundle extends Component {
constructor() {
super();
this.state = {};
this.handleRender = this.handleRender.bind(this);
}
2017-09-27 17:22:01 +03:00
handleRender(ManifestEditor) {
if (ManifestEditor) {
setTimeout(() => {
this.setState({ ManifestEditor });
}, 80);
}
return <Loader />;
}
2017-09-27 17:22:01 +03:00
render() {
if (!this.state.ManifestEditor) {
return (
<Bundle load={() => import('joyent-manifest-editor')}>
{this.handleRender}
</Bundle>
);
}
const { ManifestEditor } = this.state;
const { children, ...rest } = this.props;
return <ManifestEditor {...rest}>{children}</ManifestEditor>;
}
}
export default ({ input, mode, defaultValue, readOnly }) => (
<ManifestEditorBundle
mode={mode}
{...input}
value={input.value || defaultValue}
readOnly={readOnly}
/>
);