chore: refactor some code (#33034)

* Refactor some code

* Apply suggestions from code review

Co-authored-by: afc163 <afc163@gmail.com>

* [CodeFactor] Apply fixes

[ci skip] [skip ci]

* rename abbr to sizeClassNameMap

* refactor: Button size class name

Co-authored-by: afc163 <afc163@gmail.com>
Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
Frank Fang 2021-12-01 17:53:05 +08:00 committed by GitHub
parent 9b46aa5133
commit de33041bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,12 +177,8 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
};
// =============== Update Loading ===============
let loadingOrDelay: Loading;
if (typeof loading === 'object' && loading.delay) {
loadingOrDelay = loading.delay || true;
} else {
loadingOrDelay = !!loading;
}
const loadingOrDelay: Loading =
typeof loading === 'object' && loading.delay ? loading.delay || true : !!loading;
React.useEffect(() => {
clearTimeout(delayTimeoutRef.current);
@ -222,19 +218,9 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
const prefixCls = getPrefixCls('btn', customizePrefixCls);
const autoInsertSpace = autoInsertSpaceInButton !== false;
// large => lg
// small => sm
let sizeCls = '';
switch (customizeSize || size) {
case 'large':
sizeCls = 'lg';
break;
case 'small':
sizeCls = 'sm';
break;
default:
break;
}
const sizeClassNameMap = { large: 'lg', small: 'sm', middle: undefined };
const sizeFullname = customizeSize || size;
const sizeCls = sizeFullname ? sizeClassNameMap[sizeFullname] || '' : '';
const iconType = innerLoading ? 'loading' : icon;