mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
refactor: next-affix change affix use cssinjs (#34558)
* refactor: next-affix * fix: wrong spell * fix: add fixme * fix: prefixnam * fix: change hash to classname * fix: omit hashclassName * fix: change name to rootclassName * fix: rootClassName add Co-authored-by: zengguhao.zgh <zengguhao.zgh@alibaba-inc.com>
This commit is contained in:
parent
a7a180b913
commit
18c4fe5fd9
@ -192,6 +192,7 @@ export interface AliasToken extends DerivativeToken {
|
|||||||
componentBackgroundDisabled: string;
|
componentBackgroundDisabled: string;
|
||||||
|
|
||||||
zIndexDropdown: number;
|
zIndexDropdown: number;
|
||||||
|
zIndexAffix: number;
|
||||||
|
|
||||||
boxShadow?: string;
|
boxShadow?: string;
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ export default function formatToken(derivativeToken: RawMergedToken): AliasToken
|
|||||||
durationFast: '0.1s',
|
durationFast: '0.1s',
|
||||||
|
|
||||||
zIndexDropdown: 1050,
|
zIndexDropdown: 1050,
|
||||||
|
zIndexAffix: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
return aliasToken;
|
return aliasToken;
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
getFixedTop,
|
getFixedTop,
|
||||||
getFixedBottom,
|
getFixedBottom,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
import useStyle from './style';
|
||||||
|
|
||||||
function getDefaultTarget() {
|
function getDefaultTarget() {
|
||||||
return typeof window !== 'undefined' ? window : null;
|
return typeof window !== 'undefined' ? window : null;
|
||||||
@ -35,6 +36,7 @@ export interface AffixProps {
|
|||||||
|
|
||||||
export interface InternalAffixProps extends AffixProps {
|
export interface InternalAffixProps extends AffixProps {
|
||||||
affixPrefixCls: string;
|
affixPrefixCls: string;
|
||||||
|
rootClassName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AffixStatus {
|
enum AffixStatus {
|
||||||
@ -255,8 +257,9 @@ class Affix extends React.Component<InternalAffixProps, AffixState> {
|
|||||||
// =================== Render ===================
|
// =================== Render ===================
|
||||||
render() {
|
render() {
|
||||||
const { affixStyle, placeholderStyle } = this.state;
|
const { affixStyle, placeholderStyle } = this.state;
|
||||||
const { affixPrefixCls, children } = this.props;
|
const { affixPrefixCls, rootClassName, children } = this.props;
|
||||||
const className = classNames({
|
const className = classNames({
|
||||||
|
[rootClassName]: !!affixStyle,
|
||||||
[affixPrefixCls]: !!affixStyle,
|
[affixPrefixCls]: !!affixStyle,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -267,6 +270,7 @@ class Affix extends React.Component<InternalAffixProps, AffixState> {
|
|||||||
'target',
|
'target',
|
||||||
'onChange',
|
'onChange',
|
||||||
'affixPrefixCls',
|
'affixPrefixCls',
|
||||||
|
'rootClassName',
|
||||||
]);
|
]);
|
||||||
// Omit this since `onTestUpdatePosition` only works on test.
|
// Omit this since `onTestUpdatePosition` only works on test.
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test') {
|
||||||
@ -299,16 +303,18 @@ class Affix extends React.Component<InternalAffixProps, AffixState> {
|
|||||||
const AffixFC = React.forwardRef<Affix, AffixProps>((props, ref) => {
|
const AffixFC = React.forwardRef<Affix, AffixProps>((props, ref) => {
|
||||||
const { prefixCls: customizePrefixCls } = props;
|
const { prefixCls: customizePrefixCls } = props;
|
||||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||||
|
|
||||||
const affixPrefixCls = getPrefixCls('affix', customizePrefixCls);
|
const affixPrefixCls = getPrefixCls('affix', customizePrefixCls);
|
||||||
|
|
||||||
|
const [wrapSSR, hashId] = useStyle(affixPrefixCls);
|
||||||
|
|
||||||
const AffixProps: InternalAffixProps = {
|
const AffixProps: InternalAffixProps = {
|
||||||
...props,
|
...props,
|
||||||
|
|
||||||
affixPrefixCls,
|
affixPrefixCls,
|
||||||
|
rootClassName: hashId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return <Affix {...AffixProps} ref={ref} />;
|
return wrapSSR(<Affix {...AffixProps} ref={ref} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
@import '../../style/themes/index';
|
// @import '../../style/themes/index';
|
||||||
|
|
||||||
.@{ant-prefix}-affix {
|
// .@{ant-prefix}-affix {
|
||||||
position: fixed;
|
// position: fixed;
|
||||||
z-index: @zindex-affix;
|
// z-index: @zindex-affix;
|
||||||
}
|
// }
|
||||||
|
@ -1,2 +1,43 @@
|
|||||||
import '../../style/index.less';
|
// deps-lint-skip-all
|
||||||
import './index.less';
|
import { CSSObject } from '@ant-design/cssinjs';
|
||||||
|
import {
|
||||||
|
DerivativeToken,
|
||||||
|
useStyleRegister,
|
||||||
|
useToken,
|
||||||
|
UseComponentStyleResult,
|
||||||
|
GenerateStyle,
|
||||||
|
} from '../../_util/theme';
|
||||||
|
|
||||||
|
interface AffixToken extends DerivativeToken {
|
||||||
|
affixCls: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================== Shared ==============================
|
||||||
|
const genSharedAffixStyle: GenerateStyle<AffixToken> = (token): CSSObject => {
|
||||||
|
const { affixCls } = token;
|
||||||
|
|
||||||
|
return {
|
||||||
|
[affixCls]: {
|
||||||
|
position: 'fixed',
|
||||||
|
zIndex: token.zIndexAffix,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============================== Export ==============================
|
||||||
|
export default function useStyle(prefixCls: string): UseComponentStyleResult {
|
||||||
|
const [theme, token, hashId] = useToken();
|
||||||
|
|
||||||
|
const affixToken: AffixToken = {
|
||||||
|
...token,
|
||||||
|
|
||||||
|
affixCls: `.${prefixCls}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
useStyleRegister({ theme, token, hashId, path: [prefixCls] }, () => [
|
||||||
|
genSharedAffixStyle(affixToken),
|
||||||
|
]),
|
||||||
|
hashId,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user