2022-03-21 16:48:25 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2022-09-19 15:08:09 +08:00
|
|
|
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../interface';
|
2022-09-16 14:58:05 +08:00
|
|
|
import getAlphaColor from './getAlphaColor';
|
2022-09-19 15:08:09 +08:00
|
|
|
import seedToken from '../themes/seed';
|
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-09-19 15:08:09 +08:00
|
|
|
const overrideTokens = { ...override };
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
Object.keys(seedToken).forEach((token) => {
|
2022-09-19 15:08:09 +08:00
|
|
|
delete overrideTokens[token as keyof SeedToken];
|
|
|
|
});
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
const mergedToken = {
|
|
|
|
...restToken,
|
2022-09-19 15:08:09 +08:00
|
|
|
...overrideTokens,
|
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-09-16 14:58:05 +08:00
|
|
|
colorSplit: getAlphaColor(mergedToken.colorBorderSecondary, 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-11-01 15:06:38 +08:00
|
|
|
colorTextLightSolid: mergedToken.colorWhite,
|
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,
|
|
|
|
|
2022-09-16 14:58:05 +08:00
|
|
|
colorErrorOutline: getAlphaColor(mergedToken.colorErrorBg, mergedToken.colorBgContainer),
|
|
|
|
colorWarningOutline: getAlphaColor(mergedToken.colorWarningBg, mergedToken.colorBgContainer),
|
2022-07-21 17:00:42 +08:00
|
|
|
|
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
|
2022-11-01 15:06:38 +08:00
|
|
|
lineWidth: mergedToken.lineWidth,
|
2022-03-22 13:26:29 +08:00
|
|
|
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-09-20 21:50:36 +08:00
|
|
|
controlItemBgActiveDisabled: mergedToken.colorFill,
|
2022-07-21 17:00:42 +08:00
|
|
|
controlTmpOutline: mergedToken.colorFillQuaternary,
|
2022-09-16 14:58:05 +08:00
|
|
|
controlOutline: getAlphaColor(mergedToken.colorPrimaryBg, mergedToken.colorBgContainer),
|
2022-06-24 11:11:42 +08:00
|
|
|
|
2022-11-01 15:06:38 +08:00
|
|
|
lineType: mergedToken.lineType,
|
|
|
|
borderRadius: mergedToken.borderRadius,
|
|
|
|
borderRadiusXS: mergedToken.borderRadiusXS,
|
|
|
|
borderRadiusSM: mergedToken.borderRadiusSM,
|
|
|
|
borderRadiusLG: mergedToken.borderRadiusLG,
|
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
|
|
|
|
2022-10-25 17:04:36 +08:00
|
|
|
paddingXXS: mergedToken.sizeXXS,
|
|
|
|
paddingXS: mergedToken.sizeXS,
|
|
|
|
paddingSM: mergedToken.sizeSM,
|
|
|
|
padding: mergedToken.size,
|
|
|
|
paddingMD: mergedToken.sizeMD,
|
|
|
|
paddingLG: mergedToken.sizeLG,
|
|
|
|
paddingXL: mergedToken.sizeXL,
|
|
|
|
|
|
|
|
paddingContentHorizontalLG: mergedToken.sizeLG,
|
|
|
|
paddingContentVerticalLG: mergedToken.sizeMS,
|
|
|
|
paddingContentHorizontal: mergedToken.sizeMS,
|
|
|
|
paddingContentVertical: mergedToken.sizeSM,
|
|
|
|
paddingContentHorizontalSM: mergedToken.size,
|
|
|
|
paddingContentVerticalSM: mergedToken.sizeXS,
|
|
|
|
|
|
|
|
marginXXS: mergedToken.sizeXXS,
|
|
|
|
marginXS: mergedToken.sizeXS,
|
|
|
|
marginSM: mergedToken.sizeSM,
|
|
|
|
margin: mergedToken.size,
|
|
|
|
marginMD: mergedToken.sizeMD,
|
|
|
|
marginLG: mergedToken.sizeLG,
|
|
|
|
marginXL: mergedToken.sizeXL,
|
|
|
|
marginXXL: mergedToken.sizeXXL,
|
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-19 15:08:09 +08:00
|
|
|
...overrideTokens,
|
2022-03-21 16:48:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return aliasToken;
|
|
|
|
}
|