You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
8 years ago
|
/*
|
||
7 years ago
|
* Minio Cloud Storage (C) 2016, 2018 Minio, Inc.
|
||
8 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
7 years ago
|
import React from "react"
|
||
|
import { connect } from "react-redux"
|
||
|
import ReactDropzone from "react-dropzone"
|
||
|
import * as actions from "./actions"
|
||
8 years ago
|
|
||
|
// Dropzone is a drag-and-drop element for uploading files. It will create a
|
||
|
// landing zone of sorts that automatically receives the files.
|
||
7 years ago
|
export class Dropzone extends React.Component {
|
||
8 years ago
|
onDrop(files) {
|
||
7 years ago
|
const { uploadFile } = this.props
|
||
8 years ago
|
// FIXME: Currently you can upload multiple files, but only one abort
|
||
|
// modal will be shown, and progress updates will only occur for one
|
||
|
// file at a time. See #171.
|
||
|
files.forEach(file => {
|
||
7 years ago
|
uploadFile(file)
|
||
8 years ago
|
})
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
// Overwrite the default styling from react-dropzone; otherwise it
|
||
|
// won't handle child elements correctly.
|
||
|
const style = {
|
||
7 years ago
|
height: "100%",
|
||
|
borderWidth: "0",
|
||
|
borderStyle: "dashed",
|
||
|
borderColor: "#fff"
|
||
8 years ago
|
}
|
||
|
const activeStyle = {
|
||
7 years ago
|
borderWidth: "2px",
|
||
|
borderColor: "#777"
|
||
8 years ago
|
}
|
||
|
const rejectStyle = {
|
||
7 years ago
|
backgroundColor: "#ffdddd"
|
||
8 years ago
|
}
|
||
|
|
||
|
// disableClick means that it won't trigger a file upload box when
|
||
|
// the user clicks on a file.
|
||
|
return (
|
||
7 years ago
|
<ReactDropzone
|
||
|
style={style}
|
||
|
activeStyle={activeStyle}
|
||
|
rejectStyle={rejectStyle}
|
||
|
disableClick={true}
|
||
|
onDrop={this.onDrop.bind(this)}
|
||
|
>
|
||
|
{this.props.children}
|
||
8 years ago
|
</ReactDropzone>
|
||
|
)
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
const mapDispatchToProps = dispatch => {
|
||
|
return {
|
||
|
uploadFile: file => dispatch(actions.uploadFile(file))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default connect(undefined, mapDispatchToProps)(Dropzone)
|