mirror of https://github.com/kern/filepizza
Extract a Centered component.
parent
1e1648410e
commit
5344bbda28
@ -0,0 +1,63 @@
|
||||
import React from 'react'
|
||||
|
||||
export default class Centered extends React.Component {
|
||||
|
||||
render() {
|
||||
const h = this.props.hor
|
||||
const v = this.props.ver
|
||||
|
||||
if (h && v) {
|
||||
|
||||
return <div style={{
|
||||
display: 'table',
|
||||
width: '100%',
|
||||
height: '100%'}}>
|
||||
<div style={{
|
||||
display: 'table-cell',
|
||||
verticalAlign: 'middle',
|
||||
textAlign: 'center'}}>
|
||||
<div style={{display: 'inline-block'}}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} else if (h && !v) {
|
||||
|
||||
return <div style={{textAlign: 'center'}}>
|
||||
<div style={{display: 'inline-block'}}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} else if (!h && v) {
|
||||
|
||||
return <div style={{
|
||||
display: 'table',
|
||||
width: '100%',
|
||||
height: '100%'}}>
|
||||
<div style={{
|
||||
display: 'table-cell',
|
||||
verticalAlign: 'middle'}}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} else {
|
||||
|
||||
return this.props.children
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Centered.propTypes = {
|
||||
hor: React.PropTypes.bool,
|
||||
ver: React.PropTypes.bool
|
||||
}
|
||||
|
||||
Centered.defaultProps = {
|
||||
hor: false,
|
||||
ver: false
|
||||
}
|
||||
@ -1,43 +1,52 @@
|
||||
import React from 'react';
|
||||
import classnames from 'classnames';
|
||||
import React from 'react'
|
||||
import Centered from './Centered'
|
||||
|
||||
export default class DropZone extends React.Component {
|
||||
|
||||
constructor() {
|
||||
this.state = { focus: false };
|
||||
this.state = { focus: false }
|
||||
}
|
||||
|
||||
onDragEnter() {
|
||||
this.setState({ focus: true });
|
||||
this.setState({ focus: true })
|
||||
}
|
||||
|
||||
onDragLeave() {
|
||||
this.setState({ focus: false });
|
||||
onDragLeave(e) {
|
||||
if (e.target !== this.refs.overlay.getDOMNode()) return
|
||||
this.setState({ focus: false })
|
||||
}
|
||||
|
||||
onDragOver(e) {
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'copy';
|
||||
e.preventDefault()
|
||||
e.dataTransfer.dropEffect = 'copy'
|
||||
}
|
||||
|
||||
onDrop(e) {
|
||||
e.preventDefault();
|
||||
this.setState({ focus: false });
|
||||
e.preventDefault()
|
||||
this.setState({ focus: false })
|
||||
|
||||
let file = e.dataTransfer.files[0];
|
||||
if (this.props.onDrop && file) this.props.onDrop(file);
|
||||
let file = e.dataTransfer.files[0]
|
||||
if (this.props.onDrop && file) this.props.onDrop(file)
|
||||
}
|
||||
|
||||
render() {
|
||||
let classes = classnames('drop-zone', {
|
||||
'drop-zone-focus': this.state.focus
|
||||
});
|
||||
|
||||
return <div className={classes}
|
||||
return <div className="drop-zone" ref="root"
|
||||
onDragEnter={this.onDragEnter.bind(this)}
|
||||
onDragLeave={this.onDragLeave.bind(this)}
|
||||
onDragOver={this.onDragOver.bind(this)}
|
||||
onDrop={this.onDrop.bind(this)} />;
|
||||
onDrop={this.onDrop.bind(this)}>
|
||||
|
||||
<div className="drop-zone-overlay"
|
||||
hidden={!this.state.focus}
|
||||
ref="overlay" />
|
||||
|
||||
{this.props.children}
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DropZone.propTypes = {
|
||||
onDrop: React.PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue