You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

460 lines
13 KiB

import classNames from 'classnames';
import type { UploadProps as RcUploadProps } from 'rc-upload';
import RcUpload from 'rc-upload';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { flushSync } from 'react-dom';
import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/en_US';
import warning from '../_util/warning';
import type { RcFile, ShowUploadListInterface, UploadChangeParam, UploadFile } from './interface';
import { UploadProps } from './interface';
import UploadList from './UploadList';
merge Feature into master (#29758) * feat: add onCancel and onEnd option for editable (#29615) * feature: add onCancel and onEnd option for editable * doc: editable * doc: add EN doc * optimize: code Co-authored-by: chenliang <chenliang9@xiaomi.com> * feat: add parent class for different notification types (#29634) close #29417 * refactor: Upload use origin behavior (#29737) * refactor: Fallback of events * test: Fix test case * fix: Start file update logic * fix: remove status update * test: Remove wrapTest * test: Fix test case * chore: bump rc-upload * docs: About desc * feat: tab support moreIcon (#29744) * feat: Tabs support moreIcon * docs: Tabs support moreIcon * style: lint * docs: add english document * Update components/tabs/index.zh-CN.md Co-authored-by: xrkffgg <xrkffgg@vip.qq.com> * Update components/tabs/index.en-US.md Co-authored-by: xrkffgg <xrkffgg@vip.qq.com> * Update components/tabs/index.zh-CN.md * Update components/tabs/index.en-US.md Co-authored-by: zty <zty.dev@outlook.com> Co-authored-by: zty <zty.dev@icloud.com> Co-authored-by: xrkffgg <xrkffgg@vip.qq.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: jueinin <1014397160@qq.com> Co-authored-by: chenliang <chenliang9@xiaomi.com> Co-authored-by: 不吃猫的鱼 <michael2ib1989@gmail.com> Co-authored-by: 二货机器人 <smith3816@gmail.com> Co-authored-by: Tianyuan Zhang <tianyuan233.zhang@gmail.com> Co-authored-by: zty <zty.dev@outlook.com> Co-authored-by: zty <zty.dev@icloud.com> Co-authored-by: xrkffgg <xrkffgg@vip.qq.com>
4 years ago
import { file2Obj, getFileItem, removeFileItem, updateFileList } from './utils';
import useStyle from './style';
export const LIST_IGNORE = `__LIST_IGNORE_${Date.now()}__`;
export { UploadProps };
const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (props, ref) => {
const {
fileList,
defaultFileList,
onRemove,
showUploadList = true,
listType = 'text',
onPreview,
onDownload,
onChange,
onDrop,
previewFile,
disabled: customDisabled,
locale: propLocale,
iconRender,
isImageUrl,
progress,
prefixCls: customizePrefixCls,
className,
type = 'select',
children,
style,
itemRender,
maxCount,
data = {},
multiple = false,
action = '',
accept = '',
supportServerRender = true,
} = props;
// ===================== Disabled =====================
const disabled = React.useContext(DisabledContext);
const mergedDisabled = customDisabled ?? disabled;
const [mergedFileList, setMergedFileList] = useMergedState(defaultFileList || [], {
value: fileList,
postState: list => list ?? [],
});
const [dragState, setDragState] = React.useState<string>('drop');
const upload = React.useRef<RcUpload>(null);
warning(
'fileList' in props || !('value' in props),
'Upload',
'`value` is not a valid prop, do you mean `fileList`?',
);