Browse Source

improve upload list layout style

pull/17805/head
afc163 5 years ago
parent
commit
5742ae221c
  1. 3
      components/upload/Upload.tsx
  2. 6
      components/upload/UploadList.tsx
  3. 32
      components/upload/demo/avatar.md
  4. 28
      components/upload/demo/picture-card.md
  5. 8
      components/upload/style/index.less

3
components/upload/Upload.tsx

@ -332,12 +332,13 @@ class Upload extends React.Component<UploadProps, UploadState> {
if (listType === 'picture-card') {
return (
<span className={className}>
<span className={classNames(className, `${prefixCls}-picture-card-wrapper`)}>
{uploadList}
{uploadButton}
</span>
);
}
return (
<span className={className}>
{uploadButton}

6
components/upload/UploadList.tsx

@ -89,7 +89,11 @@ export default class UploadList extends React.Component<UploadListProps, any> {
);
} else {
const thumbnail = isImageUrl(file) ? (
<img src={file.thumbUrl || file.url} alt={file.name} />
<img
src={file.thumbUrl || file.url}
alt={file.name}
className={`${prefixCls}-list-item-image`}
/>
) : (
<Icon type="file" className={`${prefixCls}-list-item-icon`} theme="twoTone" />
);

32
components/upload/demo/avatar.md

@ -27,15 +27,15 @@ function getBase64(img, callback) {
}
function beforeUpload(file) {
const isJPG = file.type === 'image/jpeg';
if (!isJPG) {
message.error('You can only upload JPG file!');
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isJpgOrPng) {
message.error('You can only upload JPG/PNG file!');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('Image must smaller than 2MB!');
}
return isJPG && isLt2M;
return isJpgOrPng && isLt2M;
}
class Avatar extends React.Component {
@ -68,19 +68,17 @@ class Avatar extends React.Component {
);
const { imageUrl } = this.state;
return (
<div className="clearfix">
<Upload
name="avatar"
listType="picture-card"
className="avatar-uploader"
showUploadList={false}
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
beforeUpload={beforeUpload}
onChange={this.handleChange}
>
{imageUrl ? <img src={imageUrl} alt="avatar" /> : uploadButton}
</Upload>
</div>
<Upload
name="avatar"
listType="picture-card"
className="avatar-uploader"
showUploadList={false}
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
beforeUpload={beforeUpload}
onChange={this.handleChange}
>
{imageUrl ? <img src={imageUrl} alt="avatar" style={{ width: '100%' }} /> : uploadButton}
</Upload>
);
}
}

28
components/upload/demo/picture-card.md

@ -32,7 +32,31 @@ class PicturesWall extends React.Component {
fileList: [
{
uid: '-1',
name: 'xxx.png',
name: 'image.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
},
{
uid: '-2',
name: 'image.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
},
{
uid: '-3',
name: 'image.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
},
{
uid: '-4',
name: 'image.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
},
{
uid: '-5',
name: 'image.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
},
@ -71,7 +95,7 @@ class PicturesWall extends React.Component {
onPreview={this.handlePreview}
onChange={this.handleChange}
>
{fileList.length >= 3 ? null : uploadButton}
{fileList.length >= 8 ? null : uploadButton}
</Upload>
<Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />

8
components/upload/style/index.less

@ -128,6 +128,10 @@
color: @text-color-secondary;
}
}
&-picture-card-wrapper {
.clearfix;
}
}
.@{upload-prefix-cls}-list {
@ -258,6 +262,10 @@
transform: translate(-50%, -50%);
}
.@{upload-item}-image {
max-width: 100%;
}
.@{upload-item}-thumbnail img {
display: block;
width: 48px;

Loading…
Cancel
Save