ant-design/components/upload/uploadList.jsx

51 lines
1.4 KiB
React
Raw Normal View History

import React from 'react';
2015-08-21 16:19:28 +08:00
import getFileItem from './getFileItem';
const prefixCls = 'ant-upload';
export default React.createClass({
getDefaultProps() {
return {
items: []
};
},
getInitialState() {
return {
items: this.props.items
};
},
componentWillReceiveProps(nextProps) {
if ('items' in nextProps) {
this.setState({
items: nextProps.items
});
}
},
2015-08-09 18:23:18 +08:00
handleClose(file) {
2015-08-21 16:19:28 +08:00
console.log(file.uid, file.id);
let matchWay = (!file.uid) ? 'byName' : 'byUid';
let items = this.state.items;
2015-08-21 16:19:28 +08:00
let removeItem = getFileItem(file, items);
2015-08-09 18:23:18 +08:00
if (removeItem) {
2015-08-21 16:19:28 +08:00
items.splice(items.indexOf(removeItem), 1);
2015-08-09 18:23:18 +08:00
}
this.setState({
items: items
});
},
render() {
2015-08-21 16:19:28 +08:00
let items = this.state.items;
let downloadItem = (file) => {
let statusIcon = file.status === 'done' ? <i className={'anticon anticon-check ' + prefixCls + '-success-icon'}></i> : <i className="anticon anticon-loading"></i>;
return (
2015-08-21 16:19:28 +08:00
<div className={prefixCls + '-list-item'} key={file.index}>
{statusIcon}
2015-08-21 16:19:28 +08:00
<b className={prefixCls + '-item-name'}>{file.filename} {file.uid}</b>
<i className="anticon anticon-cross" ref="theCloseBtn"
onClick={this.handleClose.bind(this, file)}></i>
</div>
);
};
return <div className={prefixCls + '-list'}>{items.map(downloadItem)}</div>;
}
});