mirror of https://github.com/sgoudham/carbon.git
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.
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
8 years ago
|
import { EOL } from 'os'
|
||
8 years ago
|
import React from 'react'
|
||
|
import domtoimage from 'dom-to-image'
|
||
8 years ago
|
import CodeMirror from 'react-codemirror'
|
||
8 years ago
|
import WindowControls from '../components/svg/Controls'
|
||
8 years ago
|
|
||
8 years ago
|
// hack to only call modes on browser
|
||
|
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
|
||
8 years ago
|
require('../lib/constants')
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
const DEFAULT_SETTINGS = {
|
||
|
paddingVertical: '50px',
|
||
|
paddingHorizontal: '50px',
|
||
|
marginVertical: '45px',
|
||
|
marginHorizontal: '45px',
|
||
|
background: '#fed0ec',
|
||
|
theme: 'dracula',
|
||
|
language: 'javascript'
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
const CodeImage = (props) => {
|
||
|
const config = Object.assign(DEFAULT_SETTINGS, props.config)
|
||
|
|
||
|
const options = {
|
||
|
lineNumbers: false,
|
||
|
mode: config.language,
|
||
|
theme: config.theme,
|
||
|
scrollBarStyle: null,
|
||
|
viewportMargin: Infinity,
|
||
|
lineWrapping: true
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// create styles
|
||
|
const containerStyle = {
|
||
|
background: config.background,
|
||
|
padding: `${config.paddingVertical} ${config.paddingHorizontal}`
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
return (
|
||
|
<div id="section">
|
||
|
<div id="container" style={containerStyle}>
|
||
|
{ true ? <WindowControls /> : null }
|
||
|
<CodeMirror className="CodeMirrorContainer" value={props.children} options={options} />
|
||
8 years ago
|
</div>
|
||
8 years ago
|
<style jsx>{`
|
||
|
#section {
|
||
|
height: 100%;
|
||
|
display: flex;
|
||
|
justify-content: center;
|
||
|
align-items: center;
|
||
|
}
|
||
|
`}</style>
|
||
|
</div>
|
||
|
)
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
export default CodeImage
|