mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
refactor: affix use genComponentStyleHook (#34896)
This commit is contained in:
parent
821ac5bc97
commit
811c48795a
@ -39,6 +39,7 @@ export interface OverrideToken {
|
||||
derivative?: Partial<DerivativeToken & AliasToken>;
|
||||
|
||||
// Customize component
|
||||
Affix?: {};
|
||||
Button?: ButtonComponentToken;
|
||||
Cascader?: CascaderComponentToken;
|
||||
Divider?: DividerComponentToken;
|
||||
|
@ -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)];
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user