refactor: Checkbox & Tree migrate to genComponentStyleHook (#34904)

* refactor: Checkbox migrate to genComponentStyleHook

* refactor: tree migrate to genComponentStyleHook
This commit is contained in:
MadCcc 2022-04-07 18:24:45 +08:00 committed by GitHub
parent 8dd16a1f57
commit 064edfe22a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 39 deletions

View File

@ -43,6 +43,7 @@ export interface OverrideToken {
Button?: ButtonComponentToken;
Carousel?: {};
Cascader?: CascaderComponentToken;
Checkbox?: {};
Divider?: DividerComponentToken;
Empty?: EmptyComponentToken;
Form?: {};
@ -52,6 +53,7 @@ export interface OverrideToken {
Pagination?: {};
Select?: SelectComponentToken;
Slider?: SliderComponentToken;
Tree?: {};
TreeSelect?: {};
Typography?: TypographyComponentToken;
}

View File

@ -1,15 +1,8 @@
// deps-lint-skip-all
import { Keyframes } from '@ant-design/cssinjs';
import {
DerivativeToken,
useStyleRegister,
useToken,
resetComponent,
UseComponentStyleResult,
GenerateStyle,
} from '../../_util/theme';
import { resetComponent, GenerateStyle, genComponentStyleHook, FullToken } from '../../_util/theme';
interface CheckboxToken extends DerivativeToken {
interface CheckboxToken extends FullToken<'Checkbox'> {
checkboxCls: string;
}
@ -242,7 +235,7 @@ export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token, hashId) =>
};
// ============================== Export ==============================
export function getStyle(prefixCls: string, token: DerivativeToken, hashId: string) {
export function getStyle(prefixCls: string, token: FullToken<'Checkbox'>, hashId: string) {
const checkboxToken: CheckboxToken = {
...token,
checkboxCls: `.${prefixCls}`,
@ -251,13 +244,6 @@ export function getStyle(prefixCls: string, token: DerivativeToken, hashId: stri
return [genCheckboxStyle(checkboxToken, hashId), antCheckboxEffect];
}
export default function useStyle(prefixCls: string): UseComponentStyleResult {
const [theme, token, hashId] = useToken();
return [
useStyleRegister({ theme, token, hashId, path: [prefixCls] }, () =>
getStyle(prefixCls, token, hashId),
),
hashId,
];
}
export default genComponentStyleHook('Checkbox', (token, { prefixCls, hashId }) => [
getStyle(prefixCls, token, hashId),
]);

View File

@ -3,13 +3,7 @@
// deps-lint-skip-all
import { CSSObject, CSSInterpolation, Keyframes } from '@ant-design/cssinjs';
import {
DerivativeToken,
useStyleRegister,
useToken,
resetComponent,
UseComponentStyleResult,
} from '../../_util/theme';
import { DerivativeToken, resetComponent, genComponentStyleHook } from '../../_util/theme';
import { getStyle as getCheckboxStyle } from '../../checkbox/style';
// ============================ Keyframes =============================
@ -471,15 +465,8 @@ export const genTreeStyle = (
};
// ============================== Export ==============================
export default function useStyle(prefixCls: string): UseComponentStyleResult {
const [theme, token, hashId] = useToken();
return [
useStyleRegister({ theme, token, hashId, path: [prefixCls] }, () => [
getCheckboxStyle(`${prefixCls}-checkbox`, token, hashId),
genTreeStyle(prefixCls, token, hashId),
treeNodeFX,
]),
hashId,
];
}
export default genComponentStyleHook('Tree', (token, { prefixCls, hashId }) => [
getCheckboxStyle(`${prefixCls}-checkbox`, token, hashId),
genTreeStyle(prefixCls, token, hashId),
treeNodeFX,
]);