chore: full token of anchor (#35588)

* chore: full token of anchor

* chore: rename
This commit is contained in:
二货机器人 2022-05-17 18:04:24 +08:00 committed by GitHub
parent ee8ce6c916
commit a09333d287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 38 deletions

View File

@ -230,6 +230,9 @@ export interface DerivativeToken extends SeedToken, ColorPalettes {
gridSpaceXL: number; gridSpaceXL: number;
gridSpaceXXL: number; gridSpaceXXL: number;
// Line
lineWidthBold: number;
// Motion // Motion
motionDurationFast: string; motionDurationFast: string;
motionDurationMid: string; motionDurationMid: string;

View File

@ -37,6 +37,7 @@ export function derivative(token: SeedToken): DerivativeToken {
gridBaseStep, gridBaseStep,
radiusBase, radiusBase,
controlHeight, controlHeight,
lineWidth,
} = token; } = token;
const primaryColors = generate(colorPrimary); const primaryColors = generate(colorPrimary);
@ -94,6 +95,9 @@ export function derivative(token: SeedToken): DerivativeToken {
gridSpaceXL: gridUnit * (gridBaseStep + 2), gridSpaceXL: gridUnit * (gridBaseStep + 2),
gridSpaceXXL: gridUnit * (gridBaseStep + 5), gridSpaceXXL: gridUnit * (gridBaseStep + 5),
// line
lineWidthBold: lineWidth + 1,
// radius // radius
radiusSM: radiusBase / 2, radiusSM: radiusBase / 2,
radiusLG: radiusBase * 2, radiusLG: radiusBase * 2,

View File

@ -4,68 +4,65 @@ import { genComponentStyleHook, mergeToken, resetComponent } from '../../_util/t
import type { GenerateStyle, FullToken } from '../../_util/theme'; import type { GenerateStyle, FullToken } from '../../_util/theme';
export interface ComponentToken {} export interface ComponentToken {}
interface AnchorToken extends FullToken<'Anchor'> { interface AnchorToken extends FullToken<'Anchor'> {
anchorLinkTop: number; holderOffsetBlock: number;
anchorLinkLeft: number; anchorPaddingBlock: number;
anchorPaddingBlockSecondary: number;
anchorPaddingInline: number;
anchorLineHeight: number;
anchorBallSize: number;
anchorTitleBlock: number;
} }
// ============================== Shared ============================== // ============================== Shared ==============================
const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => { const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
const { componentCls } = token; const { componentCls, holderOffsetBlock, anchorBallSize, lineWidthBold } = token;
return { return {
[`${componentCls}-wrapper`]: { [`${componentCls}-wrapper`]: {
// FIX ME marginBlockStart: -holderOffsetBlock,
marginBlockStart: -4, paddingBlockStart: holderOffsetBlock,
// FIX ME
paddingBlockStart: 4,
// delete overflow: auto // delete overflow: auto
// overflow: 'auto', // overflow: 'auto',
// @anchor-bg
backgroundColor: 'transparent', backgroundColor: 'transparent',
[componentCls]: { [componentCls]: {
...resetComponent(token), ...resetComponent(token),
position: 'relative', position: 'relative',
// FIX ME @anchor-border-width paddingInlineStart: lineWidthBold,
paddingInlineStart: 2,
[`${componentCls}-ink`]: { [`${componentCls}-ink`]: {
position: 'absolute', position: 'absolute',
// top: 0
insetBlockStart: 0, insetBlockStart: 0,
// left: 0
insetInlineStart: 0, insetInlineStart: 0,
height: '100%', height: '100%',
'&::before': { '&::before': {
position: 'relative', position: 'relative',
display: 'block', display: 'block',
// FIX ME width: lineWidthBold,
width: 2,
height: '100%', height: '100%',
margin: '0 auto', margin: '0 auto',
// FIX ME @border-color-split backgroundColor: token.colorBorderSecondary,
backgroundColor: 'rgba(0, 0, 0, 0.06)',
content: '" "', content: '" "',
}, },
}, },
[`${componentCls}-ink-ball`]: { [`${componentCls}-ink-ball`]: {
position: 'absolute', position: 'absolute',
// left 50% left: {
insetInlineStart: '50%', _skip_check_: true,
value: '50%',
},
display: 'none', display: 'none',
// FIX ME width: anchorBallSize,
width: 8, height: anchorBallSize,
// FIX ME backgroundColor: token.colorBgComponent,
height: 8, border: `${lineWidthBold}px solid ${token.colorPrimary}`,
// FIX '@component-background' borderRadius: anchorBallSize,
backgroundColor: '#fff',
border: `2px solid ${token.colorPrimary}`,
borderRadius: 8,
transform: 'translateX(-50%)', transform: 'translateX(-50%)',
transition: `top ${token.motionDurationSlow} ease-in-out`, transition: `top ${token.motionDurationSlow} ease-in-out`,
@ -75,21 +72,19 @@ const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
}, },
[`${componentCls}-link`]: { [`${componentCls}-link`]: {
// FIX ME @anchor-link-padding paddingBlock: token.anchorPaddingBlock,
paddingBlock: token.anchorLinkTop, paddingInline: `${token.anchorPaddingInline}px 0`,
paddingInline: `${token.anchorLinkLeft}px 0`, lineHeight: token.anchorLineHeight,
lineHeight: '1.143',
'&-title': { '&-title': {
position: 'relative', position: 'relative',
display: 'block', display: 'block',
// FIX ME margin-bottom marginBlockEnd: token.anchorTitleBlock,
marginBlockEnd: 6,
overflow: 'hidden', overflow: 'hidden',
color: token.colorText, color: token.colorText,
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
transition: `all ${token.motionDurationSlow}s`, transition: `all ${token.motionDurationSlow}`,
'&:only-child': { '&:only-child': {
marginBlockEnd: 0, marginBlockEnd: 0,
@ -102,7 +97,7 @@ const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
// link link // link link
[`${componentCls}-link`]: { [`${componentCls}-link`]: {
paddingBlock: 5, paddingBlock: token.anchorPaddingBlockSecondary,
}, },
}, },
}, },
@ -116,9 +111,25 @@ const genSharedAnchorStyle: GenerateStyle<AnchorToken> = (token): CSSObject => {
// ============================== Export ============================== // ============================== Export ==============================
export default genComponentStyleHook('Anchor', token => { export default genComponentStyleHook('Anchor', token => {
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;
const anchorToken = mergeToken<AnchorToken>(token, { const anchorToken = mergeToken<AnchorToken>(token, {
anchorLinkTop: 7, holderOffsetBlock: paddingXXS,
anchorLinkLeft: 16, anchorPaddingBlock: paddingBlock,
anchorPaddingBlockSecondary: paddingBlockSecondary,
anchorPaddingInline: padding,
anchorLineHeight,
anchorTitleBlock: titleBlock,
anchorBallSize: fontSizeLG / 2,
}); });
return [genSharedAnchorStyle(anchorToken)]; return [genSharedAnchorStyle(anchorToken)];
}); });

View File

@ -108,7 +108,7 @@ export const genCheckboxStyle: GenerateStyle<CheckboxToken> = token => {
display: 'table', display: 'table',
width: (token.fontSizeLG / 14) * 5, width: (token.fontSizeLG / 14) * 5,
height: (token.fontSizeLG / 14) * 8, height: (token.fontSizeLG / 14) * 8,
border: `2px solid ${token.colorBgComponent}`, border: `${token.lineWidthBold}px solid ${token.colorBgComponent}`,
borderTop: 0, borderTop: 0,
borderInlineStart: 0, borderInlineStart: 0,
transform: 'rotate(45deg) scale(0) translate(-50%,-50%)', transform: 'rotate(45deg) scale(0) translate(-50%,-50%)',

View File

@ -49,7 +49,7 @@ const getDropIndicatorStyle = (prefixCls: string, token: DerivativeToken) => ({
width: 8, width: 8,
height: 8, height: 8,
backgroundColor: 'transparent', backgroundColor: 'transparent',
border: `2px solid ${token.colorPrimary}`, border: `${token.lineWidthBold}px solid ${token.colorPrimary}`,
borderRadius: '50%', borderRadius: '50%',
content: '""', content: '""',
}, },