ant-design/components/upload/demo/picture-card.md

84 lines
2.0 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
2016-11-25 15:00:28 +08:00
order: 3
2016-09-18 11:08:54 +08:00
title:
2016-11-25 15:00:28 +08:00
zh-CN: 照片墙
en-US: Pictures Wall
2016-03-31 09:40:55 +08:00
---
2016-01-15 16:44:07 +08:00
2016-08-25 09:46:19 +08:00
## zh-CN
2016-11-25 15:00:28 +08:00
用户可以上传图片并在列表中显示缩略图。当上传照片数到达限制后,上传按钮消失。
2016-01-15 16:44:07 +08:00
2016-08-25 09:46:19 +08:00
## en-US
2016-11-25 15:00:28 +08:00
After users upload picture, the thumbnail will be shown in list. The upload button will disappear when count meets limitation.
2016-08-25 09:46:19 +08:00
2017-02-13 10:55:53 +08:00
````jsx
2016-04-05 12:30:14 +08:00
import { Upload, Icon, Modal } from 'antd';
2016-01-15 16:44:07 +08:00
2016-11-25 15:00:28 +08:00
class PicturesWall extends React.Component {
state = {
previewVisible: false,
previewImage: '',
fileList: [{
uid: '-1',
2016-11-25 15:00:28 +08:00
name: 'xxx.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}],
};
handleCancel = () => this.setState({ previewVisible: false })
handlePreview = (file) => {
2016-04-05 12:30:14 +08:00
this.setState({
2016-11-25 15:00:28 +08:00
previewImage: file.url || file.thumbUrl,
previewVisible: true,
2016-04-05 12:30:14 +08:00
});
2016-11-25 15:00:28 +08:00
}
handleChange = ({ fileList }) => this.setState({ fileList })
2016-04-05 12:30:14 +08:00
render() {
2016-11-25 15:00:28 +08:00
const { previewVisible, previewImage, fileList } = this.state;
const uploadButton = (
<div>
<Icon type="plus" />
<div className="ant-upload-text">Upload</div>
</div>
);
2016-04-05 12:30:14 +08:00
return (
<div className="clearfix">
2016-11-25 15:00:28 +08:00
<Upload
2017-03-08 12:17:46 +08:00
action="//jsonplaceholder.typicode.com/posts/"
2016-11-25 15:00:28 +08:00
listType="picture-card"
fileList={fileList}
onPreview={this.handlePreview}
onChange={this.handleChange}
2016-11-22 14:21:42 +08:00
>
2016-11-25 15:00:28 +08:00
{fileList.length >= 3 ? null : uploadButton}
</Upload>
<Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
2016-04-05 12:30:14 +08:00
</Modal>
</div>
);
2016-11-25 15:00:28 +08:00
}
}
2016-01-15 16:44:07 +08:00
2016-11-25 15:00:28 +08:00
ReactDOM.render(<PicturesWall />, mountNode);
2016-01-15 16:44:07 +08:00
````
````css
2016-08-25 09:46:19 +08:00
/* you can make up upload button and sample style by using stylesheets */
.ant-upload-select-picture-card i {
2017-10-26 11:47:05 +08:00
font-size: 32px;
2016-01-15 16:44:07 +08:00
color: #999;
}
.ant-upload-select-picture-card .ant-upload-text {
2016-01-15 16:44:07 +08:00
margin-top: 8px;
color: #666;
}
````