2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-10-28 16:44:19 +08:00
|
|
|
import { resetComponent, textEllipsis } from '../../style';
|
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;
|
|
|
|
anchorBallSize: number;
|
|
|
|
anchorTitleBlock: number;
|
2022-04-29 17:23:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================== Shared ==============================
|
|
|
|
const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
|
2022-11-17 16:49:09 +08:00
|
|
|
const { componentCls, holderOffsetBlock, motionDurationSlow, lineWidthBold, colorPrimary } =
|
|
|
|
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-06-17 18:47:47 +08:00
|
|
|
backgroundColor: token.colorSplit,
|
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,
|
2022-11-17 16:49:09 +08:00
|
|
|
value: 0,
|
2022-05-17 18:04:24 +08:00
|
|
|
},
|
2022-04-29 17:23:23 +08:00
|
|
|
display: 'none',
|
2022-11-17 16:49:09 +08:00
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
transition: `top ${motionDurationSlow} ease-in-out`,
|
|
|
|
width: lineWidthBold,
|
|
|
|
backgroundColor: colorPrimary,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
2022-11-10 10:08:10 +08:00
|
|
|
[`&${componentCls}-ink-ball-visible`]: {
|
2022-04-29 17:23:23 +08:00
|
|
|
display: 'inline-block',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-link`]: {
|
2022-05-17 18:04:24 +08:00
|
|
|
paddingBlock: token.anchorPaddingBlock,
|
|
|
|
paddingInline: `${token.anchorPaddingInline}px 0`,
|
2022-04-29 17:23:23 +08:00
|
|
|
|
|
|
|
'&-title': {
|
2022-10-28 16:44:19 +08:00
|
|
|
...textEllipsis,
|
2022-04-29 17:23:23 +08:00
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
2022-05-17 18:04:24 +08:00
|
|
|
marginBlockEnd: token.anchorTitleBlock,
|
2022-04-29 17:23:23 +08:00
|
|
|
color: token.colorText,
|
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 ==============================
|
2022-11-17 16:49:09 +08:00
|
|
|
export default genComponentStyleHook('Anchor', (token) => {
|
2022-11-09 12:28:04 +08:00
|
|
|
const { fontSize, fontSizeLG, padding, paddingXXS } = token;
|
2022-05-17 18:04:24 +08:00
|
|
|
|
2022-04-29 17:23:23 +08:00
|
|
|
const anchorToken = mergeToken<AnchorToken>(token, {
|
2022-05-17 18:04:24 +08:00
|
|
|
holderOffsetBlock: paddingXXS,
|
2022-11-09 12:28:04 +08:00
|
|
|
anchorPaddingBlock: paddingXXS,
|
|
|
|
anchorPaddingBlockSecondary: paddingXXS / 2,
|
2022-05-17 18:04:24 +08:00
|
|
|
anchorPaddingInline: padding,
|
2022-05-21 22:53:33 +08:00
|
|
|
anchorTitleBlock: (fontSize / 14) * 3,
|
2022-05-17 18:04:24 +08:00
|
|
|
anchorBallSize: fontSizeLG / 2,
|
2022-04-29 17:23:23 +08:00
|
|
|
});
|
|
|
|
return [genSharedAnchorStyle(anchorToken)];
|
|
|
|
});
|