You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
carbon/components/codeImage.js

79 lines
2.1 KiB
JavaScript

import { EOL } from 'os'
8 years ago
import React from 'react'
import domtoimage from 'dom-to-image'
import CodeMirror from 'react-codemirror'
import WindowControls from '../components/svg/controls'
8 years ago
// hack to only call modes on browser
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
require('../lib/constants')
}
const margin = '45px 54px'
const padding = '50px 50px'
8 years ago
class CodeImage extends React.Component {
constructor (props) {
super(props)
this.state = {
code: this.props.children,
config: this.props.config || {}
}
8 years ago
}
updateCode (newCode) {
this.setState({ code: newCode })
}
8 years ago
render () {
const options = { lineNumbers: false, mode: 'javascript', theme: 'dracula'}
return (
8 years ago
<div id='section'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/codemirror.min.css'/>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.26.0/theme/dracula.min.css'/>
<div id='container' style={Object.assign({ background: this.state.config.bg }, this.props.style)}>
{ true ? <WindowControls /> : null }
<div id='anotherContainer'>
<CodeMirror value={this.state.code} onChange={this.updateCode} options={options} />
</div>
8 years ago
</div>
<style jsx>{`
#section {
height: 100%;
8 years ago
display: flex;
justify-content: center;
align-items: center;
}
#anotherContainer {
8 years ago
background: white;
min-width: 700px;
min-height: 400px;
margin: 0px;
padding: 15px;
height: 100%;
background: #000;
8 years ago
display: flex;
justify-content: center;
align-items: center;
}
.hyper {
border: 1px solid #393939;
border-radius: 5px;
background: black;
padding: 26px 18px;
margin: ${margin}
color: white;
8 years ago
}
.bw {}
8 years ago
`}</style>
</div>
)
}
}
export default CodeImage