refactor: affix use genComponentStyleHook (#34896)

This commit is contained in:
MadCcc 2022-04-07 14:53:13 +08:00 committed by GitHub
parent 821ac5bc97
commit 811c48795a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 24 deletions

View File

@ -39,6 +39,7 @@ export interface OverrideToken {
derivative?: Partial<DerivativeToken & AliasToken>;
// Customize component
Affix?: {};
Button?: ButtonComponentToken;
Cascader?: CascaderComponentToken;
Divider?: DividerComponentToken;

View File

@ -1,24 +1,17 @@
// deps-lint-skip-all
import { CSSObject } from '@ant-design/cssinjs';
import {
DerivativeToken,
useStyleRegister,
useToken,
UseComponentStyleResult,
GenerateStyle,
} from '../../_util/theme';
import { GenerateStyle, genComponentStyleHook, FullToken } from '../../_util/theme';
interface AffixToken extends DerivativeToken {
affixCls: string;
interface AffixToken extends FullToken<'Affix'> {
zIndexAffix: number;
}
// ============================== Shared ==============================
const genSharedAffixStyle: GenerateStyle<AffixToken> = (token): CSSObject => {
const { affixCls } = token;
const { componentCls } = token;
return {
[affixCls]: {
[componentCls]: {
position: 'fixed',
zIndex: token.zIndexAffix,
},
@ -26,20 +19,10 @@ const genSharedAffixStyle: GenerateStyle<AffixToken> = (token): CSSObject => {
};
// ============================== Export ==============================
export default function useStyle(prefixCls: string): UseComponentStyleResult {
const [theme, token, hashId] = useToken();
export default genComponentStyleHook('Affix', token => {
const affixToken: AffixToken = {
...token,
affixCls: `.${prefixCls}`,
zIndexAffix: token.zIndexBase + 10,
};
return [
useStyleRegister({ theme, token, hashId, path: [prefixCls] }, () => [
genSharedAffixStyle(affixToken),
]),
hashId,
];
}
return [genSharedAffixStyle(affixToken)];
});