Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: 💄 fix Upload picture-card button style #26367

Merged
merged 7 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/form/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6055,7 +6055,7 @@ exports[`renders ./components/form/demo/validate-other.md correctly 1`] = `
</svg>
</span>
<span>
Click to upload
Click to upload
</span>
</button>
</span>
Expand Down
4 changes: 1 addition & 3 deletions components/form/demo/validate-other.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ const Demo = () => {
extra="longgggggggggggggggggggggggggggggggggg"
>
<Upload name="logo" action="/upload.do" listType="picture">
<Button>
<UploadOutlined /> Click to upload
</Button>
<Button icon={<UploadOutlined />}>Click to upload</Button>
</Upload>
</Form.Item>

Expand Down
70 changes: 32 additions & 38 deletions components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,35 +217,6 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
forceUpdate,
}));

const renderUploadList = (locale: UploadLocale) => {
const {
showRemoveIcon,
showPreviewIcon,
showDownloadIcon,
removeIcon,
downloadIcon,
} = showUploadList as any;
return (
<UploadList
listType={listType}
items={getFileList()}
previewFile={previewFile}
onPreview={onPreview}
onDownload={onDownload}
onRemove={handleRemove}
showRemoveIcon={!disabled && showRemoveIcon}
showPreviewIcon={showPreviewIcon}
showDownloadIcon={showDownloadIcon}
removeIcon={removeIcon}
downloadIcon={downloadIcon}
iconRender={iconRender}
locale={{ ...locale, ...propLocale }}
isImageUrl={isImageUrl}
progress={progress}
/>
);
};

const { getPrefixCls, direction } = React.useContext(ConfigContext);

const prefixCls = getPrefixCls('upload', customizePrefixCls);
Expand All @@ -271,11 +242,35 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
delete rcUploadProps.id;
}

const uploadList = showUploadList ? (
<LocaleReceiver componentName="Upload" defaultLocale={defaultLocale.Upload}>
{renderUploadList}
</LocaleReceiver>
) : null;
const renderUploadList = (button?: React.ReactNode) =>
showUploadList ? (
<LocaleReceiver componentName="Upload" defaultLocale={defaultLocale.Upload}>
{(locale: UploadLocale) => {
const { showRemoveIcon, showPreviewIcon, showDownloadIcon, removeIcon, downloadIcon } =
typeof showUploadList === 'boolean' ? ({} as any) : showUploadList;
return (
<UploadList
listType={listType}
items={getFileList()}
previewFile={previewFile}
onPreview={onPreview}
onDownload={onDownload}
onRemove={handleRemove}
showRemoveIcon={!disabled && showRemoveIcon}
showPreviewIcon={showPreviewIcon}
showDownloadIcon={showDownloadIcon}
removeIcon={removeIcon}
downloadIcon={downloadIcon}
iconRender={iconRender}
locale={{ ...locale, ...propLocale }}
isImageUrl={isImageUrl}
progress={progress}
appendAction={button}
/>
);
}}
</LocaleReceiver>
) : button;

if (type === 'drag') {
const dragCls = classNames(
Expand All @@ -302,7 +297,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
<div className={`${prefixCls}-drag-container`}>{children}</div>
</RcUpload>
</div>
{uploadList}
{renderUploadList()}
</span>
);
}
Expand All @@ -323,16 +318,15 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
if (listType === 'picture-card') {
return (
<span className={classNames(className, `${prefixCls}-picture-card-wrapper`)}>
{uploadList}
{uploadButton}
{renderUploadList(uploadButton)}
</span>
);
}

return (
<span className={className}>
{uploadButton}
{uploadList}
{renderUploadList()}
</span>
);
};
Expand Down
11 changes: 6 additions & 5 deletions components/upload/UploadList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const InternalUploadList: React.ForwardRefRenderFunction<unknown, UploadListProp
removeIcon: customRemoveIcon,
downloadIcon: customDownloadIcon,
progress: progressProps,
appendAction,
},
ref,
) => {
Expand Down Expand Up @@ -334,13 +335,13 @@ const InternalUploadList: React.ForwardRefRenderFunction<unknown, UploadListProp
[`${prefixCls}-list-rtl`]: direction === 'rtl',
});
const animationDirection = listType === 'picture-card' ? 'animate-inline' : 'animate';
const transitionName = list.length === 0 ? '' : `${prefixCls}-${animationDirection}`;
return (
<Animate
transitionName={`${prefixCls}-${animationDirection}`}
component="div"
className={listClassNames}
>
<Animate transitionName={transitionName} component="div" className={listClassNames}>
{list}
{React.isValidElement(appendAction)
? React.cloneElement(appendAction, { key: 'appendAction' })
: appendAction}
</Animate>
);
};
Expand Down