File size: 5,477 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
import { unit } from '@ant-design/cssinjs';
import { resetComponent, textEllipsis } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
export interface ComponentToken {
/**
* @desc 链接纵向内间距
* @descEN Vertical padding of link
*/
linkPaddingBlock: number;
/**
* @desc 链接横向内间距
* @descEN Horizontal padding of link
*/
linkPaddingInlineStart: number;
}
/**
* @desc Anchor 组件的 Token
* @descEN Token for Anchor component
*/
interface AnchorToken extends FullToken<'Anchor'> {
/**
* @desc 容器块偏移量
* @descEN Holder block offset
*/
holderOffsetBlock: number;
/**
* @desc 次级锚点块内间距
* @descEN Secondary anchor block padding
*/
anchorPaddingBlockSecondary: number | string;
/**
* @desc 锚点球大小
* @descEN Anchor ball size
*/
anchorBallSize: number | string;
/**
* @desc 锚点标题块
* @descEN Anchor title block
*/
anchorTitleBlock: number | string;
}
// ============================== Shared ==============================
const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token) => {
const {
componentCls,
holderOffsetBlock,
motionDurationSlow,
lineWidthBold,
colorPrimary,
lineType,
colorSplit,
calc,
} = token;
return {
[`${componentCls}-wrapper`]: {
marginBlockStart: calc(holderOffsetBlock).mul(-1).equal(),
paddingBlockStart: holderOffsetBlock,
// delete overflow: auto
// overflow: 'auto',
[componentCls]: {
...resetComponent(token),
position: 'relative',
paddingInlineStart: lineWidthBold,
[`${componentCls}-link`]: {
paddingBlock: token.linkPaddingBlock,
paddingInline: `${unit(token.linkPaddingInlineStart)} 0`,
'&-title': {
...textEllipsis,
position: 'relative',
display: 'block',
marginBlockEnd: token.anchorTitleBlock,
color: token.colorText,
transition: `all ${token.motionDurationSlow}`,
'&:only-child': {
marginBlockEnd: 0,
},
},
[`&-active > ${componentCls}-link-title`]: {
color: token.colorPrimary,
},
// link link
[`${componentCls}-link`]: {
paddingBlock: token.anchorPaddingBlockSecondary,
},
},
},
[`&:not(${componentCls}-wrapper-horizontal)`]: {
[componentCls]: {
'&::before': {
position: 'absolute',
insetInlineStart: 0,
top: 0,
height: '100%',
borderInlineStart: `${unit(lineWidthBold)} ${lineType} ${colorSplit}`,
content: '" "',
},
[`${componentCls}-ink`]: {
position: 'absolute',
insetInlineStart: 0,
display: 'none',
transform: 'translateY(-50%)',
transition: `top ${motionDurationSlow} ease-in-out`,
width: lineWidthBold,
backgroundColor: colorPrimary,
[`&${componentCls}-ink-visible`]: {
display: 'inline-block',
},
},
},
},
[`${componentCls}-fixed ${componentCls}-ink ${componentCls}-ink`]: {
display: 'none',
},
},
};
};
const genSharedAnchorHorizontalStyle: GenerateStyle<AnchorToken> = (token) => {
const { componentCls, motionDurationSlow, lineWidthBold, colorPrimary } = token;
return {
[`${componentCls}-wrapper-horizontal`]: {
position: 'relative',
'&::before': {
position: 'absolute',
left: {
_skip_check_: true,
value: 0,
},
right: {
_skip_check_: true,
value: 0,
},
bottom: 0,
borderBottom: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
content: '" "',
},
[componentCls]: {
overflowX: 'scroll',
position: 'relative',
display: 'flex',
scrollbarWidth: 'none' /* Firefox */,
'&::-webkit-scrollbar': {
display: 'none' /* Safari and Chrome */,
},
[`${componentCls}-link:first-of-type`]: {
paddingInline: 0,
},
[`${componentCls}-ink`]: {
position: 'absolute',
bottom: 0,
transition: `left ${motionDurationSlow} ease-in-out, width ${motionDurationSlow} ease-in-out`,
height: lineWidthBold,
backgroundColor: colorPrimary,
},
},
},
};
};
export const prepareComponentToken: GetDefaultToken<'Anchor'> = (token) => ({
linkPaddingBlock: token.paddingXXS,
linkPaddingInlineStart: token.padding,
});
// ============================== Export ==============================
export default genStyleHooks(
'Anchor',
(token) => {
const { fontSize, fontSizeLG, paddingXXS, calc } = token;
const anchorToken = mergeToken<AnchorToken>(token, {
holderOffsetBlock: paddingXXS,
anchorPaddingBlockSecondary: calc(paddingXXS).div(2).equal(),
anchorTitleBlock: calc(fontSize).div(14).mul(3).equal(),
anchorBallSize: calc(fontSizeLG).div(2).equal(),
});
return [genSharedAnchorStyle(anchorToken), genSharedAnchorHorizontalStyle(anchorToken)];
},
prepareComponentToken,
);
|