forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragger.jsx
115 lines (104 loc) · 2.85 KB
/
dragger.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Icon from '../icon';
import { func } from '../util';
import zhCN from '../locale/zh-cn.js';
import Upload from './upload';
/**
* Upload.Dragger
* @description IE10+ 支持。继承 Upload 的 API,除非特别说明
*/
class Dragger extends React.Component {
static propTypes = {
/**
* 样式前缀
*/
prefix: PropTypes.string,
locale: PropTypes.object,
shape: PropTypes.string,
onDragOver: PropTypes.func,
onDragLeave: PropTypes.func,
onDrop: PropTypes.func,
limit: PropTypes.number,
className: PropTypes.string,
style: PropTypes.object,
defaultValue: PropTypes.array,
children: PropTypes.node,
listType: PropTypes.string,
timeout: PropTypes.number,
};
static defaultProps = {
prefix: 'next-',
onDragOver: func.noop,
onDragLeave: func.noop,
onDrop: func.noop,
locale: zhCN.Upload,
};
state = {
dragOver: false,
};
onDragOver = e => {
if (!this.state.dragOver) {
this.setState({
dragOver: true,
});
}
this.props.onDragOver(e);
};
onDragLeave = e => {
this.setState({
dragOver: false,
});
this.props.onDragLeave(e);
};
onDrop = e => {
this.setState({
dragOver: false,
});
this.props.onDrop(e);
};
render() {
const {
className,
style,
shape,
locale,
prefix,
listType,
...others
} = this.props;
const prefixCls = `${prefix}upload-drag`;
const cls = classNames({
[`${prefixCls}`]: true,
[`${prefixCls}-over`]: this.state.dragOver,
[className]: !!className,
});
const children = this.props.children || (
<div className={cls}>
<p className={`${prefixCls}-icon`}>
<Icon size="large" className={`${prefixCls}-upload-icon`} />
</p>
<p className={`${prefixCls}-text`}>{locale.drag.text}</p>
<p className={`${prefixCls}-hint`}>{locale.drag.hint}</p>
</div>
);
return (
<Upload
{...others}
prefix={prefix}
shape={shape}
listType={listType}
dragable
style={style}
onDragOver={this.onDragOver}
onDragLeave={this.onDragLeave}
onDrop={this.onDrop}
ref={this.saveUploaderRef}
>
{children}
</Upload>
);
}
}
export default Dragger;