Merge pull request #11 from dawnlabs/dnd-overlay

File drop overlay
main
Michael Fix 7 years ago committed by GitHub
commit 8783aa55a0

@ -17,7 +17,7 @@ Visit [dawnlabs.io/carbon](http://dawnlabs.io/carbon) or read [our post](TODO) t
#### Import #### Import
There are a few different ways to import code into Carbon: There are a few different ways to import code into Carbon:
- Drag a file onto the editor - Drop a file onto the editor
- Append a GitHub gist id to the url (e.g. `www.dawnlabs.io/carbon/GIST_ID_HERE`) - Append a GitHub gist id to the url (e.g. `www.dawnlabs.io/carbon/GIST_ID_HERE`)
- Paste your code directly - Paste your code directly

@ -2,23 +2,26 @@ import React from 'react'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
export default (props) => ( export default (props) => (
<div onClick={props.onClick} className="toolbar-btn" style={Object.assign({ <button onClick={props.onClick} style={Object.assign({
background: COLORS.BLACK, background: COLORS.BLACK,
color: props.color, color: props.color,
border: `0.5px solid ${props.color}` border: `0.5px solid ${props.color}`
}, props.style)}> }, props.style)}>
<span>{props.title}</span> <span>{props.title}</span>
<style jsx>{` <style jsx>{`
div { button {
cursor: pointer; cursor: pointer;
outline: none;
height: 100%; height: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 0 16px; padding: 0 16px;
border-radius: 3px; border-radius: 3px;
user-select: none; user-select: none;
} }
button > span {
font-size: 14px;
line-height: 1;
}
`}</style> `}</style>
</div> </button>
) )

@ -5,7 +5,7 @@ const Header = ({ enableHeroText }) => (
<div className="header mb4"> <div className="header mb4">
<div className="header-content"> <div className="header-content">
<a href="/"><Logo /></a> <a href="/"><Logo /></a>
{ enableHeroText ? (<h2 className="mt3">Create and share beautiful images of your source code.<br/> Start typing, or drag a file into the text area to get started.</h2>) : null } { enableHeroText ? (<h2 className="mt3">Create and share beautiful images of your source code.<br/> Start typing, or drop a file into the text area to get started.</h2>) : null }
</div> </div>
<style jsx>{` <style jsx>{`
.header { .header {

@ -0,0 +1,27 @@
const Overlay = props => (
<div className="dnd-container">
{ props.isOver ? <div className="dnd-overlay">{props.title}</div> : null }
{ props.children }
<style jsx>{`
.dnd-container {
position: relative;
}
.dnd-overlay {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
width: 100%;
height: 100%;
z-index: 999;
position: absolute;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.85);
}
`}</style>
</div>
)
export default Overlay

@ -12,8 +12,17 @@ const spec = {
} }
} }
const collect = connect => ({ connectDropTarget: connect.dropTarget() }) const collect = (connect, monitor) => ({ connectDropTarget: connect.dropTarget(), isOver: monitor.isOver() })
const ReadFileDropContainer = props => props.connectDropTarget(props.children) const ReadFileDropContainer = props => props.connectDropTarget(
<div>
{
React.Children.only(React.Children.map(
props.children,
child => React.cloneElement(child, { isOver: props.isOver }),
)[0])
}
</div>
)
export default DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer) export default DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer)

@ -92,7 +92,7 @@ export default () =>
.link { .link {
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
padding-bottom: 2px; padding-bottom: 3px;
background: linear-gradient(to right, rgba(255,255,255, 0.7) 0%, rgba(255,255,255, 0.7) 100%); background: linear-gradient(to right, rgba(255,255,255, 0.7) 0%, rgba(255,255,255, 0.7) 100%);
background-size: 1px 1px; background-size: 1px 1px;
background-position: 0 100%; background-position: 0 100%;

@ -6,7 +6,8 @@
"scripts": { "scripts": {
"dev": "node server.js", "dev": "node server.js",
"build": "next build", "build": "next build",
"start": "NODE_ENV=production node server.js" "start": "NODE_ENV=production node server.js",
"deploy": "now --public"
}, },
"dependencies": { "dependencies": {
"axios": "^0.16.2", "axios": "^0.16.2",

@ -16,7 +16,7 @@ export default () => (
<h4 className="mb0">Import</h4> <h4 className="mb0">Import</h4>
<p className="mb1 mt2">There are a few different ways to import code into Carbon:</p> <p className="mb1 mt2">There are a few different ways to import code into Carbon:</p>
<ul className="mt0 mb3"> <ul className="mt0 mb3">
<li>Drag a file into the editor</li> <li>Drop a file into the editor</li>
<li>Append a GitHub gist id to the url (<a className="link" href="/0db00e81d5416c339181e59481c74b59">example</a>)</li> <li>Append a GitHub gist id to the url (<a className="link" href="/0db00e81d5416c339181e59481c74b59">example</a>)</li>
<li>Paste your code directly</li> <li>Paste your code directly</li>
</ul> </ul>
@ -43,6 +43,7 @@ export default () => (
ul { ul {
list-style-position: inside; list-style-position: inside;
list-style-type: circle;
} }
.about { .about {

@ -6,6 +6,7 @@ import domtoimage from 'dom-to-image'
import Page from '../components/Page' import Page from '../components/Page'
import ReadFileDropContainer from '../components/ReadFileDropContainer' import ReadFileDropContainer from '../components/ReadFileDropContainer'
import Toolbar from '../components/Toolbar' import Toolbar from '../components/Toolbar'
import Overlay from '../components/Overlay'
import Carbon from '../components/Carbon' import Carbon from '../components/Carbon'
import api from '../lib/api' import api from '../lib/api'
import { THEMES, DEFAULT_LANGUAGE, COLORS, DEFAULT_CODE } from '../lib/constants' import { THEMES, DEFAULT_LANGUAGE, COLORS, DEFAULT_CODE } from '../lib/constants'
@ -86,9 +87,6 @@ class Editor extends React.Component {
render () { render () {
return ( return (
<Page enableHeroText> <Page enableHeroText>
<ReadFileDropContainer
onDrop={droppedContent => this.setState({ code: droppedContent })}
>
<div id="editor"> <div id="editor">
<Toolbar <Toolbar
save={this.save} save={this.save}
@ -101,11 +99,16 @@ class Editor extends React.Component {
bg={this.state.background} bg={this.state.background}
enabled={this.state} enabled={this.state}
/> />
<ReadFileDropContainer
onDrop={droppedContent => this.setState({ code: droppedContent })}
>
<Overlay title="Drop your file here to import">
<Carbon config={this.state} updateCode={this.updateCode}> <Carbon config={this.state} updateCode={this.updateCode}>
{this.state.code} {this.state.code}
</Carbon> </Carbon>
</div> </Overlay>
</ReadFileDropContainer> </ReadFileDropContainer>
</div>
<style jsx>{` <style jsx>{`
#editor { #editor {
background: ${COLORS.BLACK}; background: ${COLORS.BLACK};

Loading…
Cancel
Save