2022-03-21 16:48:25 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2022-06-27 11:54:31 +08:00
|
|
|
import type { AliasToken, MapToken, OverrideToken } from '../interface';
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
/** Raw merge of `@ant-design/cssinjs` token. Which need additional process */
|
2022-09-15 21:26:04 +08:00
|
|
|
type RawMergedToken = MapToken & OverrideToken & { override: Partial<AliasToken> };
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Seed (designer) > Derivative (designer) > Alias (developer).
|
|
|
|
*
|
|
|
|
* Merge seed & derivative & override token and generate alias token for developer.
|
|
|
|
*/
|
|
|
|
export default function formatToken(derivativeToken: RawMergedToken): AliasToken {
|
2022-09-15 21:26:04 +08:00
|
|
|
const { override, ...restToken } = derivativeToken;
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
const mergedToken = {
|
|
|
|
...restToken,
|
2022-09-15 21:26:04 +08:00
|
|
|
...override,
|
2022-03-21 16:48:25 +08:00
|
|
|
};
|
|
|
|
|
2022-06-29 21:24:29 +08:00
|
|
|
const { fontSizes, lineHeights } = mergedToken;
|
2022-03-30 14:13:36 +08:00
|
|
|
const screenXS = 480;
|
|
|
|
const screenSM = 576;
|
|
|
|
const screenMD = 768;
|
|
|
|
const screenLG = 992;
|
|
|
|
const screenXL = 1200;
|
|
|
|
const screenXXL = 1600;
|
2022-03-21 16:48:25 +08:00
|
|
|
|
2022-03-29 15:57:39 +08:00
|
|
|
const fontSizeSM = fontSizes[0];
|
|
|
|
|
2022-03-21 16:48:25 +08:00
|
|
|
// Generate alias token
|
|
|
|
const aliasToken: AliasToken = {
|
|
|
|
...mergedToken,
|
|
|
|
|
2022-09-07 12:00:00 +08:00
|
|
|
colorLink: mergedToken.colorInfoText,
|
|
|
|
colorLinkHover: mergedToken.colorInfoHover,
|
|
|
|
colorLinkActive: mergedToken.colorInfoActive,
|
2022-07-21 17:00:42 +08:00
|
|
|
|
|
|
|
// ============== Background ============== //
|
|
|
|
colorFillContent: mergedToken.colorFillSecondary,
|
|
|
|
colorFillContentHover: mergedToken.colorFill,
|
|
|
|
colorFillAlter: mergedToken.colorFillQuaternary,
|
|
|
|
colorBgContainerDisabled: mergedToken.colorFillTertiary,
|
|
|
|
|
|
|
|
// ============== Split ============== //
|
2022-08-04 16:16:50 +08:00
|
|
|
colorBorderBg: mergedToken.colorBgContainer,
|
2022-07-21 17:00:42 +08:00
|
|
|
|
|
|
|
// ============== Text ============== //
|
|
|
|
colorTextPlaceholder: mergedToken.colorTextQuaternary,
|
|
|
|
colorTextDisabled: mergedToken.colorTextQuaternary,
|
|
|
|
colorTextHeading: mergedToken.colorText,
|
|
|
|
colorTextLabel: mergedToken.colorTextSecondary,
|
2022-08-05 16:15:24 +08:00
|
|
|
colorTextDescription: mergedToken.colorTextTertiary,
|
2022-06-29 21:24:29 +08:00
|
|
|
colorHighlight: mergedToken.colorError,
|
2022-09-07 12:00:00 +08:00
|
|
|
colorBgTextHover: mergedToken.colorFillSecondary,
|
|
|
|
colorBgTextActive: mergedToken.colorFill,
|
2022-06-29 21:24:29 +08:00
|
|
|
|
2022-07-21 17:00:42 +08:00
|
|
|
colorIcon: mergedToken.colorTextTertiary,
|
|
|
|
colorIconHover: mergedToken.colorText,
|
|
|
|
|
|
|
|
colorErrorOutline: mergedToken.colorErrorBg,
|
|
|
|
colorWarningOutline: mergedToken.colorWarningBg,
|
|
|
|
|
2022-03-22 09:37:37 +08:00
|
|
|
// Font
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSizeSM,
|
2022-03-22 09:37:37 +08:00
|
|
|
fontSize: fontSizes[1],
|
|
|
|
fontSizeLG: fontSizes[2],
|
|
|
|
fontSizeXL: fontSizes[3],
|
|
|
|
fontSizeHeading1: fontSizes[6],
|
|
|
|
fontSizeHeading2: fontSizes[5],
|
|
|
|
fontSizeHeading3: fontSizes[4],
|
|
|
|
fontSizeHeading4: fontSizes[3],
|
|
|
|
fontSizeHeading5: fontSizes[2],
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSizeIcon: fontSizeSM,
|
2022-03-22 09:37:37 +08:00
|
|
|
|
|
|
|
lineHeight: lineHeights[1],
|
|
|
|
lineHeightLG: lineHeights[2],
|
2022-05-20 14:33:33 +08:00
|
|
|
lineHeightSM: lineHeights[0],
|
2022-03-22 09:37:37 +08:00
|
|
|
|
|
|
|
lineHeightHeading1: lineHeights[6],
|
|
|
|
lineHeightHeading2: lineHeights[5],
|
|
|
|
lineHeightHeading3: lineHeights[4],
|
|
|
|
lineHeightHeading4: lineHeights[3],
|
|
|
|
lineHeightHeading5: lineHeights[2],
|
|
|
|
|
2022-03-22 13:26:29 +08:00
|
|
|
// Control
|
|
|
|
controlLineWidth: mergedToken.lineWidth,
|
|
|
|
controlOutlineWidth: mergedToken.lineWidth * 2,
|
2022-05-31 10:10:35 +08:00
|
|
|
// Checkbox size and expand icon size
|
|
|
|
controlInteractiveSize: mergedToken.controlHeight / 2,
|
2022-03-22 13:26:29 +08:00
|
|
|
|
2022-07-21 17:00:42 +08:00
|
|
|
controlItemBgHover: mergedToken.colorFillTertiary,
|
2022-06-29 21:24:29 +08:00
|
|
|
controlItemBgActive: mergedToken.colorPrimaryBg,
|
|
|
|
controlItemBgActiveHover: mergedToken.colorPrimaryBgHover,
|
2022-07-21 17:00:42 +08:00
|
|
|
controlItemBgActiveDisabled: mergedToken.colorTextQuaternary,
|
|
|
|
controlTmpOutline: mergedToken.colorFillQuaternary,
|
|
|
|
controlOutline: mergedToken.colorPrimaryBg,
|
2022-06-24 11:11:42 +08:00
|
|
|
|
2022-05-16 17:52:35 +08:00
|
|
|
controlLineType: mergedToken.lineType,
|
2022-03-22 13:26:29 +08:00
|
|
|
controlRadius: mergedToken.radiusBase,
|
2022-08-19 10:10:51 +08:00
|
|
|
controlRadiusXS: mergedToken.radiusXS,
|
|
|
|
controlRadiusSM: mergedToken.radiusSM,
|
|
|
|
controlRadiusLG: mergedToken.radiusLG,
|
2022-07-21 17:00:42 +08:00
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
fontWeightStrong: 600,
|
2022-03-22 13:26:29 +08:00
|
|
|
|
2022-06-17 18:47:47 +08:00
|
|
|
opacityLoading: 0.65,
|
2022-04-25 10:54:00 +08:00
|
|
|
|
2022-03-21 16:48:25 +08:00
|
|
|
linkDecoration: 'none',
|
|
|
|
linkHoverDecoration: 'none',
|
|
|
|
linkFocusDecoration: 'none',
|
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
controlPaddingHorizontal: 12,
|
|
|
|
controlPaddingHorizontalSM: 8,
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
padding: 16,
|
|
|
|
margin: 16,
|
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
paddingXXS: 4,
|
|
|
|
paddingXS: 8,
|
|
|
|
paddingSM: 12,
|
|
|
|
paddingLG: 24,
|
2022-05-23 10:58:30 +08:00
|
|
|
paddingXL: 32,
|
2022-08-26 16:05:16 +08:00
|
|
|
paddingTmp: 20,
|
2022-03-21 16:48:25 +08:00
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
marginXXS: 4,
|
|
|
|
marginXS: 8,
|
|
|
|
marginSM: 12,
|
|
|
|
marginLG: 24,
|
2022-05-18 15:37:27 +08:00
|
|
|
marginXL: 32,
|
|
|
|
marginXXL: 48,
|
2022-08-26 16:05:16 +08:00
|
|
|
marginTmp: 20,
|
2022-03-21 16:48:25 +08:00
|
|
|
|
2022-03-22 20:02:04 +08:00
|
|
|
boxShadow: `
|
2022-08-26 16:05:16 +08:00
|
|
|
0 1px 2px 0 rgba(0, 0, 0, 0.03),
|
|
|
|
0 1px 6px -1px rgba(0, 0, 0, 0.02),
|
|
|
|
0 2px 4px 0 rgba(0, 0, 0, 0.02)
|
|
|
|
`,
|
|
|
|
boxShadowSecondary: `
|
2022-03-22 20:02:04 +08:00
|
|
|
0 6px 16px 0 rgba(0, 0, 0, 0.08),
|
2022-08-26 16:05:16 +08:00
|
|
|
0 3px 6px -4px rgba(0, 0, 0, 0.12),
|
2022-03-22 20:02:04 +08:00
|
|
|
0 9px 28px 8px rgba(0, 0, 0, 0.05)
|
|
|
|
`,
|
2022-03-30 14:13:36 +08:00
|
|
|
|
|
|
|
screenXS,
|
|
|
|
screenXSMin: screenXS,
|
|
|
|
screenXSMax: screenXS - 1,
|
|
|
|
screenSM,
|
|
|
|
screenSMMin: screenSM,
|
|
|
|
screenSMMax: screenSM - 1,
|
|
|
|
screenMD,
|
|
|
|
screenMDMin: screenMD,
|
|
|
|
screenMDMax: screenMD - 1,
|
|
|
|
screenLG,
|
|
|
|
screenLGMin: screenLG,
|
|
|
|
screenLGMax: screenLG - 1,
|
|
|
|
screenXL,
|
|
|
|
screenXLMin: screenXL,
|
|
|
|
screenXLMax: screenXL - 1,
|
|
|
|
screenXXL,
|
|
|
|
screenXXLMin: screenXXL,
|
|
|
|
screenXXLMax: screenXXL - 1,
|
|
|
|
|
2022-06-24 10:45:29 +08:00
|
|
|
// FIXME: component box-shadow, should be removed
|
|
|
|
boxShadowPopoverArrow: `3px 3px 7px rgba(0, 0, 0, 0.1)`,
|
|
|
|
boxShadowCard: `
|
|
|
|
0 1px 2px -2px ${new TinyColor('rgba(0, 0, 0, 0.16)').toRgbString()},
|
|
|
|
0 3px 6px 0 ${new TinyColor('rgba(0, 0, 0, 0.12)').toRgbString()},
|
|
|
|
0 5px 12px 4px ${new TinyColor('rgba(0, 0, 0, 0.09)').toRgbString()}
|
|
|
|
`,
|
2022-08-26 16:05:16 +08:00
|
|
|
boxShadowDrawerRight: `
|
|
|
|
-6px 0 16px 0 rgba(0, 0, 0, 0.08),
|
|
|
|
-3px 0 6px -4px rgba(0, 0, 0, 0.12),
|
|
|
|
-9px 0 28px 8px rgba(0, 0, 0, 0.05)
|
|
|
|
`,
|
|
|
|
boxShadowDrawerLeft: `
|
|
|
|
6px 0 16px 0 rgba(0, 0, 0, 0.08),
|
|
|
|
3px 0 6px -4px rgba(0, 0, 0, 0.12),
|
|
|
|
9px 0 28px 8px rgba(0, 0, 0, 0.05)
|
|
|
|
`,
|
|
|
|
boxShadowDrawerUp: `
|
|
|
|
0 6px 16px 0 rgba(0, 0, 0, 0.08),
|
|
|
|
0 3px 6px -4px rgba(0, 0, 0, 0.12),
|
|
|
|
0 9px 28px 8px rgba(0, 0, 0, 0.05)
|
|
|
|
`,
|
|
|
|
boxShadowDrawerDown: `
|
|
|
|
0 -6px 16px 0 rgba(0, 0, 0, 0.08),
|
|
|
|
0 -3px 6px -4px rgba(0, 0, 0, 0.12),
|
|
|
|
0 -9px 28px 8px rgba(0, 0, 0, 0.05)
|
|
|
|
`,
|
2022-06-24 10:45:29 +08:00
|
|
|
boxShadowTabsOverflowLeft: `inset 10px 0 8px -8px rgba(0, 0, 0, 0.08)`,
|
|
|
|
boxShadowTabsOverflowRight: `inset -10px 0 8px -8px rgba(0, 0, 0, 0.08)`,
|
|
|
|
boxShadowTabsOverflowTop: `inset 0 10px 8px -8px rgba(0, 0, 0, 0.08)`,
|
|
|
|
boxShadowTabsOverflowBottom: `inset 0 -10px 8px -8px rgba(0, 0, 0, 0.08)`,
|
|
|
|
|
2022-06-09 10:42:22 +08:00
|
|
|
// Override AliasToken
|
2022-09-15 21:26:04 +08:00
|
|
|
...override,
|
2022-03-21 16:48:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return aliasToken;
|
|
|
|
}
|