diff --git a/src/components/Editor/index.js b/src/components/Editor/index.js index d5437761..4e425b26 100644 --- a/src/components/Editor/index.js +++ b/src/components/Editor/index.js @@ -55,7 +55,7 @@ class CodeEditor extends Component { ); render() { - const { style, code: _, ...rest } = this.props; + const { style, code: _code, onChange, language, ...rest } = this.props; const { code } = this.state; return ( diff --git a/src/components/Live/LiveProvider.js b/src/components/Live/LiveProvider.js index ac993c05..83082029 100644 --- a/src/components/Live/LiveProvider.js +++ b/src/components/Live/LiveProvider.js @@ -64,12 +64,18 @@ export default class LiveProvider extends Component { this.transpile({ code, scope, transformCode, noInline }); } - componentDidUpdate({ code, scope, noInline, transformCode }) { + componentDidUpdate({ + code: prevCode, + scope: prevScope, + noInline: prevNoInline, + transformCode: prevTransformCode + }) { + const { code, scope, noInline, transformCode } = this.props; if ( - code !== this.props.code || - scope !== this.props.scope || - noInline !== this.props.noInline || - transformCode !== this.props.transformCode + code !== prevCode || + scope !== prevScope || + noInline !== prevNoInline || + transformCode !== prevTransformCode ) { this.transpile({ code, scope, transformCode, noInline }); } diff --git a/stories/Live.js b/stories/Live.js index 7ba76d8a..f2e9ea22 100644 --- a/stories/Live.js +++ b/stories/Live.js @@ -76,13 +76,23 @@ const StyledLivePreview = styled(LivePreview)` `; const StyledEditor = styled(LiveEditor)` - background: #222031; + background: #322e3c; +`; + +const StyledTextarea = styled.textarea` + height: 300px; + width: 600px; + font-family: monospace; + font-size: 16px; + white-space: pre; + background: #322e3c; + color: white; `; const TestComponent = ({ live }) => { const Result = live.element; return ( -
+
{live.error}
@@ -90,6 +100,22 @@ const TestComponent = ({ live }) => { ); }; +const CustomEditor = () => { + const [code, updateCode] = React.useState(functionExample); + + const handleChange = e => { + updateCode(e.target.value); + }; + + return ( + + + + + + ); +}; + const LiveComponent = withLive(TestComponent); storiesOf('Live', module) @@ -143,4 +169,5 @@ storiesOf('Live', module) - )); + )) + .add('with custom editor', () => );