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

fix(upload): upload组件增加一个可选参数successBorder,控制图片上传成功后边框是否显示 #331

Merged
merged 1 commit into from
Oct 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/components/src/components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const triggerMap: ITriggerMap = {
};

const Upload: React.FC<IUploadProps> = ({
successBorder = false,
style,
prefixCls: customPrefixCls,
className,
Expand All @@ -57,7 +58,11 @@ const Upload: React.FC<IUploadProps> = ({
const { getPrefixCls } = useContext(ConfigContext);
const prefixCls = getPrefixCls('upload', customPrefixCls);

const rootCls = classnames(className, prefixCls, {
const rootCls = classnames(className, prefixCls, successBorder ? {
[`${prefixCls}--disabled`]: disabled,
[`${prefixCls}--success-border`]: file?.status === STATUS_SUCCESS,
[`${prefixCls}--error`]: file?.status === STATUS_ERROR,
} : {
[`${prefixCls}--disabled`]: disabled,
[`${prefixCls}--success`]: file?.status === STATUS_SUCCESS,
[`${prefixCls}--error`]: file?.status === STATUS_ERROR,
Expand Down Expand Up @@ -94,7 +99,7 @@ const Upload: React.FC<IUploadProps> = ({
response,
status: STATUS_SUCCESS,
};

try {
if (fileOnSuccess.type.startsWith('image/')) {
dataUrl = await imageFile2DataUrl(fileOnSuccess);
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/components/upload/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface IInnerTriggerProps {
}

export interface IUploadProps<T = any> {
// 上传的图片是否显示边框
successBorder ?: boolean;
// upload 组件展现类型
type?: TUploadType;
// input 时希望使用 file 还是直接使用 url
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/components/upload/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
}
}
}
&--success-border {
& .@{gio-upload-card},
& .@{gio-upload-avatar},
& .@{gio-upload-drag} {
border: 1px solid #dcdfed;

&:hover .@{gio-upload-actions} {
opacity: 1;
}
}
}

&--disabled {
& .@{gio-upload-card},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { props, action } from './commonSets';

export default () => (
<div>
<Upload type="card" style={{ margin: '0 5px' }} action={action} {...props} />
<Upload type="card" style={{ margin: '0 5px' }} {...props} />
<Upload type="card" style={{ margin: '0 5px' }} action={action} {...props} successBorder />
<Upload type="card" style={{ margin: '0 5px' }} {...props} successBorder />
</div>
);