Add save image to toolbar callback

main
Mike Fix 8 years ago
parent 93ec8dc952
commit ce6b20fc4e

@ -1,12 +1,13 @@
import React from 'react' import React from 'react'
export default (props) => ( export default (props) => (
<div className="toolbar-btn" style={Object.assign({ <div onClick={props.onClick} className="toolbar-btn" style={Object.assign({
background: props.bg background: props.bg
}, props.style)}> }, props.style)}>
<span>{props.title}</span> <span>{props.title}</span>
<style jsx>{` <style jsx>{`
div { div {
cursor: pointer;
height: 37px; height: 37px;
display: flex; display: flex;
align-items: center; align-items: center;

@ -77,20 +77,19 @@ const langauges = [
'YAML' 'YAML'
].map(name => ({ name })) ].map(name => ({ name }))
export default class extends React.Component { const Toolbar = (props) => (
constructor() {
super()
}
render() {
return (
<div id="toolbar"> <div id="toolbar">
<Dropdown list={themes} /> <Dropdown list={themes} />
<Dropdown list={langauges} /> <Dropdown list={langauges} />
<ColorPicker /> <ColorPicker />
<Settings /> <Settings />
<Button title="Copy Imgur Link" bg="#84ACFC" style={{ borderRadius: '3px 0px 0px 3px' }}/> <Button
<Button title="Save Image" bg="#C3E98D" /> onClick={props.copyLink}
title="Copy Imgur Link"
bg="#84ACFC"
style={{ borderRadius: '3px 0px 0px 3px' }}
/>
<Button onClick={props.save} title="Save Image" bg="#C3E98D" />
<style jsx>{` <style jsx>{`
#toolbar { #toolbar {
width: 100%; width: 100%;
@ -103,5 +102,5 @@ export default class extends React.Component {
`}</style> `}</style>
</div> </div>
) )
}
} export default Toolbar

@ -2,6 +2,8 @@ import React from 'react'
import HTML5Backend from 'react-dnd-html5-backend' import HTML5Backend from 'react-dnd-html5-backend'
import { DragDropContext } from 'react-dnd' import { DragDropContext } from 'react-dnd'
import Axios from 'axios' import Axios from 'axios'
import domtoimage from 'dom-to-image'
import Meta from '../components/meta' import Meta from '../components/meta'
import Toolbar from '../components/toolbar' import Toolbar from '../components/toolbar'
@ -19,13 +21,25 @@ class Index extends React.Component {
return {} return {}
} }
} }
save () {
// save
domtoimage.toJpeg(document.getElementById('container'))
.then((dataUrl) => {
const link = document.createElement('a')
link.download = 'my-image-name.jpeg'
link.href = dataUrl
link.click()
})
}
render () { render () {
return ( return (
<div className="main"> <div className="main">
<Meta /> <Meta />
<h1>Welcome to Code Image</h1> <h1>Welcome to Code Image</h1>
<div id="editor"> <div id="editor">
<Toolbar /> <Toolbar save={this.save} />
<CodeImage> <CodeImage>
{this.props.content} {this.props.content}
</CodeImage> </CodeImage>

Loading…
Cancel
Save