Feature: Window Title (#257)

* Added title bar

* Added state for title bar
main
Mark Molnar 7 years ago committed by Jake Dexheimer
parent 56f11f404f
commit b1ef2d1263

@ -27,6 +27,7 @@ class Carbon extends React.Component {
} }
this.handleLanguageChange = this.handleLanguageChange.bind(this) this.handleLanguageChange = this.handleLanguageChange.bind(this)
this.handleTitleBarChange = this.handleTitleBarChange.bind(this)
this.codeUpdated = this.codeUpdated.bind(this) this.codeUpdated = this.codeUpdated.bind(this)
} }
@ -53,6 +54,10 @@ class Carbon extends React.Component {
this.props.updateCode(newCode) this.props.updateCode(newCode)
} }
handleTitleBarChange(newTitle) {
this.props.updateTitleBar(newTitle)
}
handleLanguageChange = debounce( handleLanguageChange = debounce(
(newCode, config) => { (newCode, config) => {
const props = (config && config.customProps) || this.props const props = (config && config.customProps) || this.props
@ -104,7 +109,7 @@ class Carbon extends React.Component {
if (this.state.loading === false) { if (this.state.loading === false) {
content = ( content = (
<div id="container"> <div id="container">
{config.windowControls ? <WindowControls theme={config.windowTheme} /> : null} {config.windowControls ? <WindowControls theme={config.windowTheme} handleTitleBarChange={this.handleTitleBarChange} /> : null}
<CodeMirror <CodeMirror
className={`CodeMirror__container window-theme__${config.windowTheme}`} className={`CodeMirror__container window-theme__${config.windowTheme}`}
onBeforeChange={(editor, meta, code) => this.codeUpdated(code)} onBeforeChange={(editor, meta, code) => this.codeUpdated(code)}

@ -1,9 +1,12 @@
import React from 'react' import React from 'react'
import { Controls, ControlsBW } from './svg/Controls' import { Controls, ControlsBW } from './svg/Controls'
export default ({ theme }) => ( export default ({ theme, handleTitleBarChange }) => (
<div className="window-controls"> <div className="window-controls">
{theme === 'bw' ? <ControlsBW /> : <Controls />} {theme === 'bw' ? <ControlsBW /> : <Controls />}
<div className="window-title-container">
<input type="text" spellCheck="false" onChange={e => handleTitleBarChange(e.target.value)} />
</div>
<style jsx> <style jsx>
{` {`
div { div {
@ -13,6 +16,24 @@ export default ({ theme }) => (
margin-left: 18px; margin-left: 18px;
z-index: 2; z-index: 2;
} }
.window-title-container {
position: absolute;
top: 20px;
left: -18px;
width: 100%;
text-align: center;
}
input {
width: 250px;
background: none;
outline: none;
border: none;
color: white;
text-align: center;
font-size: 14px;
}
`} `}
</style> </style>
</div> </div>

@ -72,6 +72,7 @@ class Editor extends React.Component {
this.save = this.save.bind(this) this.save = this.save.bind(this)
this.upload = this.upload.bind(this) this.upload = this.upload.bind(this)
this.updateCode = this.updateCode.bind(this) this.updateCode = this.updateCode.bind(this)
this.updateTitleBar = this.updateTitleBar.bind(this)
this.updateAspectRatio = this.updateAspectRatio.bind(this) this.updateAspectRatio = this.updateAspectRatio.bind(this)
this.resetDefaultSettings = this.resetDefaultSettings.bind(this) this.resetDefaultSettings = this.resetDefaultSettings.bind(this)
} }
@ -120,6 +121,10 @@ class Editor extends React.Component {
this.setState({ aspectRatio }) this.setState({ aspectRatio })
} }
updateTitleBar(titleBar) {
this.setState({ titleBar })
}
save() { save() {
this.getCarbonImage().then(dataUrl => { this.getCarbonImage().then(dataUrl => {
const link = document.createElement('a') const link = document.createElement('a')
@ -216,6 +221,7 @@ class Editor extends React.Component {
config={this.state} config={this.state}
updateCode={code => this.updateCode(code)} updateCode={code => this.updateCode(code)}
onAspectRatioChange={this.updateAspectRatio} onAspectRatioChange={this.updateAspectRatio}
updateTitleBar={this.updateTitleBar}
> >
{this.state.code || DEFAULT_CODE} {this.state.code || DEFAULT_CODE}
</Carbon> </Carbon>

Loading…
Cancel
Save