Skip to content

Commit

Permalink
Remove codesplitting
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 18, 2018
1 parent e252aae commit e63b05b
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions examples/src/components/ExampleItem.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import React, { Component } from 'react';
import T from 'prop-types';
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'; // eslint-disable-line
import { LiveProvider, LiveEditor, LivePreview, LiveError } from 'react-live';
import classNames from 'classnames';

let ReactLive;

const scope = { Tabs, Tab, TabList, TabPanel };

export default class ExampleItem extends Component {
state = {
editorOpen: false,
liveLoaded: false,
};

constructor(props) {
super(props);

import('react-live').then(Live => {
ReactLive = Live;
this.setState({ liveLoaded: true });
});
}

toggleCheckbox({ target: { name, checked } }) {
this.setState({
[name]: checked,
Expand All @@ -40,34 +29,11 @@ export default class ExampleItem extends Component {
return <div className="hint">{this.props.hint}</div>;
}

renderLiveEditor() {
if (!this.state.liveLoaded) return null;

render() {
const { editorOpen } = this.state;
const editorClassNames = classNames('live-editor', {
'live-editor--visible': editorOpen,
});

return (
<ReactLive.LiveProvider
mountStylesheet={false}
scope={scope}
code={this.props.code}
noInline
>
<ReactLive.LiveError />
<div className="live-preview">
<div className={editorClassNames}>
<ReactLive.LiveEditor ignoreTabKey />
</div>
<ReactLive.LivePreview />
</div>
</ReactLive.LiveProvider>
);
}

render() {
const { editorOpen } = this.state;
const formId = `editorOpen${this.props.label.replace(' ', '_')}`;

return (
Expand All @@ -86,7 +52,20 @@ export default class ExampleItem extends Component {
</label>
</h3>
{this.renderHint()}
{this.renderLiveEditor()}
<LiveProvider
mountStylesheet={false}
scope={scope}
code={this.props.code}
noInline
>
<LiveError />
<div className="live-preview">
<div className={editorClassNames}>
<LiveEditor ignoreTabKey />
</div>
<LivePreview />
</div>
</LiveProvider>
</div>
);
}
Expand Down

0 comments on commit e63b05b

Please sign in to comment.