diff --git a/components/Carbon.js b/components/Carbon.js index 5feb023..1508662 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -23,10 +23,11 @@ class Carbon extends React.Component { this.state = { loading: true, - language: props.config.language + language: props.config.language, } this.handleLanguageChange = this.handleLanguageChange.bind(this) + this.codeUpdated = this.codeUpdated.bind(this) } componentDidMount() { @@ -41,6 +42,11 @@ class Carbon extends React.Component { this.handleLanguageChange(newProps.children, { customProps: newProps }) } + codeUpdated (newCode) { + this.handleLanguageChange(newCode) + this.props.updateCode(newCode) + } + handleLanguageChange(newCode, config) { const props = (config && config.customProps) || this.props @@ -93,7 +99,7 @@ class Carbon extends React.Component { { config.windowControls ? : null } diff --git a/pages/editor.js b/pages/editor.js index 8925812..d90b52b 100644 --- a/pages/editor.js +++ b/pages/editor.js @@ -34,11 +34,13 @@ class Editor extends React.Component { windowControls: true, paddingVertical: '48px', paddingHorizontal: '32px', - uploading: false + uploading: false, + code: DEFAULT_CODE } this.save = this.save.bind(this) this.upload = this.upload.bind(this) + this.updateCode = this.updateCode.bind(this) } getCarbonImage () { @@ -56,6 +58,10 @@ class Editor extends React.Component { return domtoimage.toPng(node, config) } + updateCode (code) { + this.setState({ code }) + } + save () { this.getCarbonImage() .then((dataUrl) => { @@ -95,8 +101,8 @@ class Editor extends React.Component { bg={this.state.background} enabled={this.state} /> - - {this.state.droppedContent || this.props.content || DEFAULT_CODE} + + {this.state.droppedContent || this.props.content || this.state.code}