Pass background theme color from index

main
Mike Fix 8 years ago
parent ce6b20fc4e
commit bb17e1ddbd

@ -25,18 +25,6 @@ class CodeImage extends React.Component {
constructor () { constructor () {
super() super()
this.state = {} this.state = {}
this.save = this.save.bind(this)
}
save () {
// save
domtoimage.toJpeg(this.container)
.then((dataUrl) => {
const link = document.createElement('a')
link.download = 'my-image-name.jpeg'
link.href = dataUrl
link.click()
})
} }
render () { render () {
@ -46,11 +34,9 @@ class CodeImage extends React.Component {
return this.props.connectDropTarget( return this.props.connectDropTarget(
<div id='section'> <div id='section'>
<div id='container' ref={(container) => { this.container = container }}> <div id='container' style={Object.assign({ background: this.props.bg }, this.props.style)}>
<pre className='hyper'> <pre className='hyper'>
<code onClick={this.save}> <code>{code}</code>
{code}
</code>
</pre> </pre>
</div> </div>
<style jsx>{` <style jsx>{`

@ -5,7 +5,7 @@ import { BlockPicker } from 'react-color'
class ColorPicker extends React.Component { class ColorPicker extends React.Component {
constructor() { constructor() {
super() super()
this.state = { isVisible: false, bgcolor: '#565656' } this.state = { isVisible: false }
this.toggle = this.toggle.bind(this) this.toggle = this.toggle.bind(this)
this.handlePickColor = this.handlePickColor.bind(this) this.handlePickColor = this.handlePickColor.bind(this)
} }
@ -19,7 +19,7 @@ class ColorPicker extends React.Component {
} }
handlePickColor(color) { handlePickColor(color) {
this.setState({ bgcolor: color.hex }) this.props.onChange(color.hex)
} }
render() { render() {
@ -29,10 +29,10 @@ class ColorPicker extends React.Component {
<div className="colorpicker-label"> <div className="colorpicker-label">
<span>BG</span> <span>BG</span>
</div> </div>
<div className="bg-color" style={{background: this.state.bgcolor}} onClick={this.toggle}></div> <div className="bg-color" style={{background: this.props.bg}} onClick={this.toggle}></div>
</div> </div>
<div className="colorpicker-picker" hidden={!this.state.isVisible}> <div className="colorpicker-picker" hidden={!this.state.isVisible}>
<BlockPicker color={this.state.bgcolor} onChangeComplete={this.handlePickColor} /> <BlockPicker color={this.props.bg} onChangeComplete={this.handlePickColor} />
</div> </div>
<style jsx>{` <style jsx>{`
.colorpicker-container { .colorpicker-container {

@ -81,7 +81,10 @@ const Toolbar = (props) => (
<div id="toolbar"> <div id="toolbar">
<Dropdown list={themes} /> <Dropdown list={themes} />
<Dropdown list={langauges} /> <Dropdown list={langauges} />
<ColorPicker /> <ColorPicker
onChange={props.onBGChange}
bg={props.bg}
/>
<Settings /> <Settings />
<Button <Button
onClick={props.copyLink} onClick={props.copyLink}

@ -22,6 +22,13 @@ class Index extends React.Component {
} }
} }
constructor() {
super()
this.state = {
bgColor: '#111111'
}
}
save () { save () {
// save // save
domtoimage.toJpeg(document.getElementById('container')) domtoimage.toJpeg(document.getElementById('container'))
@ -39,8 +46,12 @@ class Index extends React.Component {
<Meta /> <Meta />
<h1>Welcome to Code Image</h1> <h1>Welcome to Code Image</h1>
<div id="editor"> <div id="editor">
<Toolbar save={this.save} /> <Toolbar
<CodeImage> save={this.save}
onBGChange={color => this.setState({ bgColor: color })}
bg={this.state.bgColor}
/>
<CodeImage bg={this.state.bgColor}>
{this.props.content} {this.props.content}
</CodeImage> </CodeImage>
</div> </div>

Loading…
Cancel
Save