From b1ef2d126397ce1939b0a6b8f907f60b4484301e Mon Sep 17 00:00:00 2001 From: Mark Molnar Date: Sun, 25 Feb 2018 17:09:52 +0100 Subject: [PATCH] Feature: Window Title (#257) * Added title bar * Added state for title bar --- components/Carbon.js | 7 ++++++- components/WindowControls.js | 23 ++++++++++++++++++++++- pages/editor.js | 6 ++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/components/Carbon.js b/components/Carbon.js index d903f1b..f3de027 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -27,6 +27,7 @@ class Carbon extends React.Component { } this.handleLanguageChange = this.handleLanguageChange.bind(this) + this.handleTitleBarChange = this.handleTitleBarChange.bind(this) this.codeUpdated = this.codeUpdated.bind(this) } @@ -53,6 +54,10 @@ class Carbon extends React.Component { this.props.updateCode(newCode) } + handleTitleBarChange(newTitle) { + this.props.updateTitleBar(newTitle) + } + handleLanguageChange = debounce( (newCode, config) => { const props = (config && config.customProps) || this.props @@ -104,7 +109,7 @@ class Carbon extends React.Component { if (this.state.loading === false) { content = (
- {config.windowControls ? : null} + {config.windowControls ? : null} this.codeUpdated(code)} diff --git a/components/WindowControls.js b/components/WindowControls.js index c787355..84fb50f 100644 --- a/components/WindowControls.js +++ b/components/WindowControls.js @@ -1,9 +1,12 @@ import React from 'react' import { Controls, ControlsBW } from './svg/Controls' -export default ({ theme }) => ( +export default ({ theme, handleTitleBarChange }) => (
{theme === 'bw' ? : } +
+ handleTitleBarChange(e.target.value)} /> +
diff --git a/pages/editor.js b/pages/editor.js index aaa8cd9..2dffeb1 100644 --- a/pages/editor.js +++ b/pages/editor.js @@ -72,6 +72,7 @@ class Editor extends React.Component { this.save = this.save.bind(this) this.upload = this.upload.bind(this) this.updateCode = this.updateCode.bind(this) + this.updateTitleBar = this.updateTitleBar.bind(this) this.updateAspectRatio = this.updateAspectRatio.bind(this) this.resetDefaultSettings = this.resetDefaultSettings.bind(this) } @@ -120,6 +121,10 @@ class Editor extends React.Component { this.setState({ aspectRatio }) } + updateTitleBar(titleBar) { + this.setState({ titleBar }) + } + save() { this.getCarbonImage().then(dataUrl => { const link = document.createElement('a') @@ -216,6 +221,7 @@ class Editor extends React.Component { config={this.state} updateCode={code => this.updateCode(code)} onAspectRatioChange={this.updateAspectRatio} + updateTitleBar={this.updateTitleBar} > {this.state.code || DEFAULT_CODE}