mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-16 23:21:00 +08:00
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
import { UploadOutlined } from '@ant-design/icons';
|
|
import type { UploadProps } from 'antd';
|
|
import { Button, Upload } from 'antd';
|
|
|
|
import SemanticPreview from '../../../.dumi/theme/common/SemanticPreview';
|
|
import useLocale from '../../../.dumi/hooks/useLocale';
|
|
|
|
const locales = {
|
|
cn: {
|
|
root: '根元素',
|
|
list: '列表元素',
|
|
item: '列表 Item 元素',
|
|
},
|
|
en: {
|
|
root: 'Root Element',
|
|
list: 'List Element',
|
|
item: 'List Item Element',
|
|
},
|
|
};
|
|
|
|
const uploadProps: UploadProps = {
|
|
action: 'https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload',
|
|
onChange({ file, fileList }) {
|
|
if (file.status !== 'uploading') {
|
|
console.log(file, fileList);
|
|
}
|
|
},
|
|
defaultFileList: [
|
|
{
|
|
uid: '1',
|
|
name: 'xxx.png',
|
|
status: 'uploading',
|
|
url: 'http://www.baidu.com/xxx.png',
|
|
percent: 33,
|
|
},
|
|
{
|
|
uid: '2',
|
|
name: 'yyy.png',
|
|
status: 'done',
|
|
url: 'http://www.baidu.com/yyy.png',
|
|
},
|
|
{
|
|
uid: '3',
|
|
name: 'zzz.png',
|
|
status: 'error',
|
|
response: 'Server Error 500', // custom error message to show
|
|
url: 'http://www.baidu.com/zzz.png',
|
|
},
|
|
],
|
|
};
|
|
|
|
const Block: React.FC<Readonly<UploadProps<any>>> = (props) => (
|
|
<Upload {...uploadProps} {...props}>
|
|
<Button icon={<UploadOutlined />}>Upload</Button>
|
|
</Upload>
|
|
);
|
|
|
|
const App: React.FC = () => {
|
|
const [locale] = useLocale(locales);
|
|
return (
|
|
<SemanticPreview
|
|
componentName="Upload"
|
|
semantics={[
|
|
{ name: 'root', desc: locale.root, version: '6.0.0' },
|
|
{ name: 'list', desc: locale.list, version: '6.0.0' },
|
|
{ name: 'item', desc: locale.item, version: '6.0.0' },
|
|
]}
|
|
>
|
|
<Block />
|
|
</SemanticPreview>
|
|
);
|
|
};
|
|
|
|
export default App;
|