2022-04-29 17:23:23 +08:00
|
|
|
// deps-lint-skip-all
|
2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-04-29 17:23:23 +08:00
|
|
|
import { genComponentStyleHook, mergeToken, resetComponent } from '../../_util/theme';
|
|
|
|
import type { GenerateStyle, FullToken } from '../../_util/theme';
|
2019-03-10 21:04:38 +08:00
|
|
|
|
2022-04-29 17:23:23 +08:00
|
|
|
export interface ComponentToken {}
|
2022-05-17 18:04:24 +08:00
|
|
|
|
2022-04-29 17:23:23 +08:00
|
|
|
interface AnchorToken extends FullToken<'Anchor'> {
|
2022-05-17 18:04:24 +08:00
|
|
|
holderOffsetBlock: number;
|
|
|
|
anchorPaddingBlock: number;
|
|
|
|
anchorPaddingBlockSecondary: number;
|
|
|
|
anchorPaddingInline: number;
|
|
|
|
anchorLineHeight: number;
|
|
|
|
anchorBallSize: number;
|
|
|
|
anchorTitleBlock: number;
|
2022-04-29 17:23:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================== Shared ==============================
|
|
|
|
const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
|
2022-05-17 18:04:24 +08:00
|
|
|
const { componentCls, holderOffsetBlock, anchorBallSize, lineWidthBold } = token;
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-wrapper`]: {
|
2022-05-17 18:04:24 +08:00
|
|
|
marginBlockStart: -holderOffsetBlock,
|
|
|
|
paddingBlockStart: holderOffsetBlock,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
// delete overflow: auto
|
|
|
|
// overflow: 'auto',
|
|
|
|
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
position: 'relative',
|
2022-05-17 18:04:24 +08:00
|
|
|
paddingInlineStart: lineWidthBold,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
[`${componentCls}-ink`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
insetBlockStart: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
height: '100%',
|
|
|
|
|
|
|
|
'&::before': {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
2022-05-17 18:04:24 +08:00
|
|
|
width: lineWidthBold,
|
2022-04-29 17:23:23 +08:00
|
|
|
height: '100%',
|
|
|
|
margin: '0 auto',
|
2022-05-17 18:04:24 +08:00
|
|
|
backgroundColor: token.colorBorderSecondary,
|
2022-04-29 17:23:23 +08:00
|
|
|
content: '" "',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-ink-ball`]: {
|
|
|
|
position: 'absolute',
|
2022-05-17 18:04:24 +08:00
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
2022-04-29 17:23:23 +08:00
|
|
|
display: 'none',
|
2022-05-17 18:04:24 +08:00
|
|
|
width: anchorBallSize,
|
|
|
|
height: anchorBallSize,
|
|
|
|
backgroundColor: token.colorBgComponent,
|
|
|
|
border: `${lineWidthBold}px solid ${token.colorPrimary}`,
|
|
|
|
borderRadius: anchorBallSize,
|
2022-04-29 17:23:23 +08:00
|
|
|
transform: 'translateX(-50%)',
|
|
|
|
transition: `top ${token.motionDurationSlow} ease-in-out`,
|
|
|
|
|
|
|
|
'&.visible': {
|
|
|
|
display: 'inline-block',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-link`]: {
|
2022-05-17 18:04:24 +08:00
|
|
|
paddingBlock: token.anchorPaddingBlock,
|
|
|
|
paddingInline: `${token.anchorPaddingInline}px 0`,
|
|
|
|
lineHeight: token.anchorLineHeight,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
'&-title': {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
2022-05-17 18:04:24 +08:00
|
|
|
marginBlockEnd: token.anchorTitleBlock,
|
2022-04-29 17:23:23 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
color: token.colorText,
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
2022-05-17 18:04:24 +08:00
|
|
|
transition: `all ${token.motionDurationSlow}`,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
'&:only-child': {
|
|
|
|
marginBlockEnd: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-active > ${componentCls}-link-title`]: {
|
|
|
|
color: token.colorPrimary,
|
|
|
|
},
|
|
|
|
|
|
|
|
// link link
|
|
|
|
[`${componentCls}-link`]: {
|
2022-05-17 18:04:24 +08:00
|
|
|
paddingBlock: token.anchorPaddingBlockSecondary,
|
2022-04-29 17:23:23 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-fixed ${componentCls}-ink ${componentCls}-ink-ball`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
|
|
|
export default genComponentStyleHook('Anchor', token => {
|
2022-05-17 18:04:24 +08:00
|
|
|
const { controlHeight, controlLineWidth, fontSize, lineHeight, fontSizeLG, padding, paddingXXS } =
|
|
|
|
token;
|
|
|
|
const linkHeight = controlHeight - 2 * controlLineWidth;
|
|
|
|
const anchorLineHeight = fontSizeLG / fontSize; // Anchor is special that use less height
|
|
|
|
const paddingBlock = Math.round(linkHeight - fontSizeLG) / 2;
|
|
|
|
|
|
|
|
// Still a magic number: 22 - 16
|
|
|
|
const titleBlock = Math.round(fontSize * lineHeight - fontSizeLG);
|
|
|
|
|
|
|
|
const paddingBlockSecondary = Math.round(linkHeight - paddingXXS - fontSizeLG) / 2;
|
|
|
|
|
2022-04-29 17:23:23 +08:00
|
|
|
const anchorToken = mergeToken<AnchorToken>(token, {
|
2022-05-17 18:04:24 +08:00
|
|
|
holderOffsetBlock: paddingXXS,
|
|
|
|
anchorPaddingBlock: paddingBlock,
|
|
|
|
anchorPaddingBlockSecondary: paddingBlockSecondary,
|
|
|
|
anchorPaddingInline: padding,
|
|
|
|
anchorLineHeight,
|
|
|
|
anchorTitleBlock: titleBlock,
|
|
|
|
anchorBallSize: fontSizeLG / 2,
|
2022-04-29 17:23:23 +08:00
|
|
|
});
|
|
|
|
return [genSharedAnchorStyle(anchorToken)];
|
|
|
|
});
|