Skip to content

Commit 0464c84

Browse files
refcator:upload (#6261)
* refcator:upload * docs:update & refactor: upload type * Update style.ts --------- Co-authored-by: tangjinzhou <[email protected]>
1 parent 7e29eb2 commit 0464c84

17 files changed

+727
-864
lines changed

components/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import './timeline/style';
4343
import './input-number/style';
4444
// import './transfer/style';
4545
import './tree/style';
46-
import './upload/style';
46+
// import './upload/style';
4747
// import './layout/style';
4848
// import './anchor/style';
4949
// import './list/style';

components/theme/interface/components.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type { ComponentToken as TagComponentToken } from '../../tag/style';
4444
import type { ComponentToken as TooltipComponentToken } from '../../tooltip/style';
4545
import type { ComponentToken as TransferComponentToken } from '../../transfer/style';
4646
import type { ComponentToken as TypographyComponentToken } from '../../typography/style';
47-
// import type { ComponentToken as UploadComponentToken } from '../../upload/style';
47+
import type { ComponentToken as UploadComponentToken } from '../../upload/style';
4848
// import type { ComponentToken as TourComponentToken } from '../../tour/style';
4949
// import type { ComponentToken as QRCodeComponentToken } from '../../qrcode/style';
5050
// import type { ComponentToken as AppComponentToken } from '../../app/style';
@@ -107,7 +107,7 @@ export interface ComponentTokenMap {
107107
Menu?: MenuComponentToken;
108108
Modal?: ModalComponentToken;
109109
Message?: MessageComponentToken;
110-
// Upload?: UploadComponentToken;
110+
Upload?: UploadComponentToken;
111111
Tooltip?: TooltipComponentToken;
112112
// Table?: TableComponentToken;
113113
Space?: SpaceComponentToken;

components/upload/Upload.tsx

+38-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import type { VueNode } from '../_util/type';
2323
import classNames from '../_util/classNames';
2424
import { useInjectFormItemContext } from '../form';
2525

26+
// CSSINJS
27+
import useStyle from './style';
28+
2629
export const LIST_IGNORE = `__LIST_IGNORE_${Date.now()}__`;
2730

2831
export default defineComponent({
@@ -292,6 +295,10 @@ export default defineComponent({
292295
});
293296

294297
const { prefixCls, direction } = useConfigInject('upload', props);
298+
299+
// style
300+
const [wrapSSR, hashId] = useStyle(prefixCls);
301+
295302
const [locale] = useLocaleReceiver(
296303
'Upload',
297304
defaultLocale.Upload,
@@ -366,6 +373,11 @@ export default defineComponent({
366373
if (!slots.default || disabled) {
367374
delete rcUploadProps.id;
368375
}
376+
377+
const rtlCls = {
378+
[`${prefixCls}-rtl`]: direction.value === 'rtl',
379+
};
380+
369381
if (type === 'drag') {
370382
const dragCls = classNames(
371383
prefixCls.value,
@@ -379,9 +391,14 @@ export default defineComponent({
379391
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
380392
},
381393
attrs.class,
394+
hashId.value,
382395
);
383-
return (
384-
<span>
396+
397+
return wrapSSR(
398+
<span
399+
{...attrs}
400+
class={classNames(`${prefixCls.value}-wrapper`, rtlCls, className, hashId.value)}
401+
>
385402
<div
386403
class={dragCls}
387404
onDrop={onFileDrop}
@@ -399,7 +416,7 @@ export default defineComponent({
399416
</VcUpload>
400417
</div>
401418
{renderUploadList()}
402-
</span>
419+
</span>,
403420
);
404421
}
405422

@@ -417,17 +434,29 @@ export default defineComponent({
417434
);
418435

419436
if (listType === 'picture-card') {
420-
return (
421-
<span class={classNames(`${prefixCls.value}-picture-card-wrapper`, attrs.class)}>
437+
return wrapSSR(
438+
<span
439+
{...attrs}
440+
class={classNames(
441+
`${prefixCls.value}-wrapper`,
442+
`${prefixCls.value}-picture-card-wrapper`,
443+
rtlCls,
444+
attrs.class,
445+
hashId.value,
446+
)}
447+
>
422448
{renderUploadList(renderUploadButton, !!(children && children.length))}
423-
</span>
449+
</span>,
424450
);
425451
}
426-
return (
427-
<span class={attrs.class}>
452+
return wrapSSR(
453+
<span
454+
{...attrs}
455+
class={classNames(`${prefixCls.value}-wrapper`, rtlCls, attrs.class, hashId.value)}
456+
>
428457
{renderUploadButton(children && children.length ? undefined : { display: 'none' })}
429458
{renderUploadList()}
430-
</span>
459+
</span>,
431460
);
432461
};
433462
},

components/upload/UploadList/ListItem.tsx

+38-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, defineComponent, onBeforeUnmount, onMounted, ref } from 'vue';
2-
import type { ExtractPropTypes, PropType, CSSProperties } from 'vue';
2+
import type { ExtractPropTypes, CSSProperties } from 'vue';
33
import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
44
import DeleteOutlined from '@ant-design/icons-vue/DeleteOutlined';
55
import DownloadOutlined from '@ant-design/icons-vue/DownloadOutlined';
@@ -16,36 +16,39 @@ import type {
1616
import type { VueNode } from '../../_util/type';
1717
import useConfigInject from '../../config-provider/hooks/useConfigInject';
1818
import Transition, { getTransitionProps } from '../../_util/transition';
19+
import { booleanType, stringType, functionType, arrayType, objectType } from '../../_util/type';
20+
1921
export const listItemProps = () => {
2022
return {
2123
prefixCls: String,
22-
locale: { type: Object as PropType<UploadLocale>, default: undefined as UploadLocale },
23-
file: Object as PropType<UploadFile>,
24-
items: Array as PropType<UploadFile[]>,
25-
listType: String as PropType<UploadListType>,
26-
isImgUrl: Function as PropType<(file: UploadFile) => boolean>,
24+
locale: objectType<UploadLocale>(undefined as UploadLocale),
25+
file: objectType<UploadFile>(),
26+
items: arrayType<UploadFile[]>(),
27+
listType: stringType<UploadListType>(),
28+
isImgUrl: functionType<(file: UploadFile) => boolean>(),
2729

28-
showRemoveIcon: { type: Boolean, default: undefined },
29-
showDownloadIcon: { type: Boolean, default: undefined },
30-
showPreviewIcon: { type: Boolean, default: undefined },
31-
removeIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>,
32-
downloadIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>,
33-
previewIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>,
30+
showRemoveIcon: booleanType(),
31+
showDownloadIcon: booleanType(),
32+
showPreviewIcon: booleanType(),
33+
removeIcon: functionType<(opt: { file: UploadFile }) => VueNode>(),
34+
downloadIcon: functionType<(opt: { file: UploadFile }) => VueNode>(),
35+
previewIcon: functionType<(opt: { file: UploadFile }) => VueNode>(),
3436

35-
iconRender: Function as PropType<(opt: { file: UploadFile }) => VueNode>,
36-
actionIconRender: Function as PropType<
37-
(opt: {
38-
customIcon: VueNode;
39-
callback: () => void;
40-
prefixCls: string;
41-
title?: string | undefined;
42-
}) => VueNode
43-
>,
44-
itemRender: Function as PropType<ItemRender>,
45-
onPreview: Function as PropType<(file: UploadFile, e: Event) => void>,
46-
onClose: Function as PropType<(file: UploadFile) => void>,
47-
onDownload: Function as PropType<(file: UploadFile) => void>,
48-
progress: Object as PropType<UploadListProgressProps>,
37+
iconRender: functionType<(opt: { file: UploadFile }) => VueNode>(),
38+
actionIconRender:
39+
functionType<
40+
(opt: {
41+
customIcon: VueNode;
42+
callback: () => void;
43+
prefixCls: string;
44+
title?: string | undefined;
45+
}) => VueNode
46+
>(),
47+
itemRender: functionType<ItemRender>(),
48+
onPreview: functionType<(file: UploadFile, e: Event) => void>(),
49+
onClose: functionType<(file: UploadFile) => void>(),
50+
onDownload: functionType<(file: UploadFile) => void>(),
51+
progress: objectType<UploadListProgressProps>(),
4952
};
5053
};
5154

@@ -93,7 +96,6 @@ export default defineComponent({
9396
const { class: className, style } = attrs;
9497
// This is used for legacy span make scrollHeight the wrong value.
9598
// We will force these to be `display: block` with non `picture-card`
96-
const spanClassName = `${prefixCls}-span`;
9799

98100
const iconNode = iconRender({ file });
99101
let icon = <div class={`${prefixCls}-text-icon`}>{iconNode}</div>;
@@ -162,7 +164,7 @@ export default defineComponent({
162164
<span
163165
key="download-delete"
164166
class={[
165-
`${prefixCls}-list-item-card-actions`,
167+
`${prefixCls}-list-item-actions`,
166168
{
167169
picture: listType === 'picture',
168170
},
@@ -231,30 +233,29 @@ export default defineComponent({
231233
} else {
232234
message = file.error?.statusText || file.error?.message || locale.uploadError;
233235
}
234-
const iconAndPreview = (
235-
<span class={spanClassName}>
236-
{icon}
237-
{preview}
238-
</span>
239-
);
240236

241237
const dom = (
242238
<div class={infoUploadingClass}>
243-
<div class={`${prefixCls}-list-item-info`}>{iconAndPreview}</div>
239+
{icon}
240+
{preview}
244241
{actions}
245242
{showProgress.value && (
246243
<Transition {...transitionProps.value}>
247244
<div v-show={file.status === 'uploading'} class={`${prefixCls}-list-item-progress`}>
248245
{'percent' in file ? (
249-
<Progress {...progressProps} type="line" percent={file.percent} />
246+
<Progress
247+
{...(progressProps as UploadListProgressProps)}
248+
type="line"
249+
percent={file.percent}
250+
/>
250251
) : null}
251252
</div>
252253
</Transition>
253254
)}
254255
</div>
255256
);
256257
const listContainerNameClass = {
257-
[`${prefixCls}-list-${listType}-container`]: true,
258+
[`${prefixCls}-list-item-container`]: true,
258259
[`${className}`]: !!className,
259260
};
260261
const item =

components/upload/UploadList/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default defineComponent({
121121
onClick: () => {
122122
callback();
123123
},
124-
class: `${prefixCls}-list-item-card-actions-btn`,
124+
class: `${prefixCls}-list-item-action`,
125125
};
126126
if (isValidElement(customIcon)) {
127127
return <Button {...btnProps} v-slots={{ icon: () => customIcon }} />;

components/upload/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: Components
33
type: Data Entry
44
title: Upload
5-
cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
5+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*93ymR4RD4S0AAAAAAAAAAAAADrJ8AQ/original
66
---
77

88
Upload file by selecting or dragging.

components/upload/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
subtitle: 上传
44
type: 数据录入
55
title: Upload
6-
cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*93ymR4RD4S0AAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
文件选择上传和拖拽上传控件。

0 commit comments

Comments
 (0)