2017-01-23 21:07:22 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage (C) 2016, 2018 MinIO, Inc.
|
2017-01-23 21:07:22 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-02-28 15:22:18 -05:00
|
|
|
import React from "react"
|
|
|
|
import { connect } from "react-redux"
|
|
|
|
import ReactDropzone from "react-dropzone"
|
|
|
|
import * as actions from "./actions"
|
2017-01-23 21:07:22 -05:00
|
|
|
|
|
|
|
// Dropzone is a drag-and-drop element for uploading files. It will create a
|
|
|
|
// landing zone of sorts that automatically receives the files.
|
2018-02-28 15:22:18 -05:00
|
|
|
export class Dropzone extends React.Component {
|
2017-01-23 21:07:22 -05:00
|
|
|
onDrop(files) {
|
2018-02-28 15:22:18 -05:00
|
|
|
const { uploadFile } = this.props
|
2017-01-23 21:07:22 -05:00
|
|
|
// 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 => {
|
2018-02-28 15:22:18 -05:00
|
|
|
uploadFile(file)
|
2017-01-23 21:07:22 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-26 15:49:12 -04:00
|
|
|
// Overwrite the default styling from react-dropzone; otherwise it
|
|
|
|
// won't handle child elements correctly.
|
|
|
|
const style = {
|
2020-09-30 01:27:41 -04:00
|
|
|
flex: "1",
|
2018-03-26 15:49:12 -04:00
|
|
|
borderWidth: "0",
|
|
|
|
borderStyle: "dashed",
|
|
|
|
borderColor: "#fff"
|
|
|
|
}
|
|
|
|
const activeStyle = {
|
|
|
|
borderWidth: "2px",
|
|
|
|
borderColor: "#777"
|
|
|
|
}
|
|
|
|
const rejectStyle = {
|
|
|
|
backgroundColor: "#ffdddd"
|
|
|
|
}
|
2020-06-04 20:24:18 -04:00
|
|
|
const getStyle = (isDragActive, isDragAccept, isDragReject) => ({
|
|
|
|
...style,
|
|
|
|
...(isDragActive ? activeStyle : {}),
|
|
|
|
...(isDragReject ? rejectStyle : {})
|
|
|
|
})
|
2018-03-26 15:49:12 -04:00
|
|
|
|
2017-01-23 21:07:22 -05:00
|
|
|
// disableClick means that it won't trigger a file upload box when
|
|
|
|
// the user clicks on a file.
|
|
|
|
return (
|
2018-02-28 15:22:18 -05:00
|
|
|
<ReactDropzone
|
|
|
|
onDrop={this.onDrop.bind(this)}
|
|
|
|
>
|
2020-06-04 20:24:18 -04:00
|
|
|
{({getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject}) => (
|
|
|
|
<div
|
|
|
|
{...getRootProps({
|
|
|
|
onClick: event => event.stopPropagation()
|
|
|
|
})}
|
|
|
|
style={getStyle(isDragActive, isDragAccept, isDragReject)}
|
|
|
|
>
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
)}
|
2017-01-23 21:07:22 -05:00
|
|
|
</ReactDropzone>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 15:22:18 -05:00
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
2018-03-22 15:25:56 -04:00
|
|
|
uploadFile: file => dispatch(actions.uploadFile(file))
|
2018-02-28 15:22:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(undefined, mapDispatchToProps)(Dropzone)
|