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-06-27 11:54:31 +08:00
|
|
|
type RawMergedToken = MapToken & OverrideToken;
|
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-06-09 10:42:22 +08:00
|
|
|
const { derivative, alias, ...restToken } = derivativeToken;
|
2022-03-21 16:48:25 +08:00
|
|
|
|
|
|
|
const mergedToken = {
|
|
|
|
...restToken,
|
|
|
|
...derivative,
|
|
|
|
};
|
|
|
|
|
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-08-03 20:04:58 +08:00
|
|
|
colorLink: mergedToken.colorPrimaryText,
|
|
|
|
colorLinkHover: mergedToken.colorPrimaryTextHover,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorLinkActive: mergedToken.colorPrimaryActive,
|
|
|
|
|
|
|
|
// ============== Background ============== //
|
|
|
|
colorFillContent: mergedToken.colorFillSecondary,
|
|
|
|
colorFillContentHover: mergedToken.colorFill,
|
|
|
|
colorFillAlter: mergedToken.colorFillQuaternary,
|
|
|
|
colorBgContainerDisabled: mergedToken.colorFillTertiary,
|
|
|
|
|
|
|
|
// ============== Split ============== //
|
|
|
|
colorBorderBg: mergedToken.colorBgLayout,
|
|
|
|
|
|
|
|
// ============== Text ============== //
|
|
|
|
colorTextPlaceholder: mergedToken.colorTextQuaternary,
|
|
|
|
colorTextDisabled: mergedToken.colorTextQuaternary,
|
|
|
|
colorTextHeading: mergedToken.colorText,
|
|
|
|
colorTextLabel: mergedToken.colorTextSecondary,
|
2022-06-29 21:24:29 +08:00
|
|
|
colorHighlight: mergedToken.colorError,
|
|
|
|
|
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-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-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-03-21 16:48:25 +08:00
|
|
|
|
2022-03-22 20:02:04 +08:00
|
|
|
boxShadow: `
|
|
|
|
0 3px 6px -4px rgba(0, 0, 0, 0.12),
|
|
|
|
0 6px 16px 0 rgba(0, 0, 0, 0.08),
|
|
|
|
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)`,
|
|
|
|
boxShadowPopoverArrowBottom: `2px 2px 5px rgba(0, 0, 0, 0.1)`,
|
|
|
|
boxShadowSegmentedSelectedItem: [
|
|
|
|
`0 2px 8px -2px ${new TinyColor('#000').setAlpha(0.05).toRgbString()}`,
|
|
|
|
`0 1px 4px -1px ${new TinyColor('#000').setAlpha(0.07).toRgbString()}`,
|
|
|
|
`0 0 1px 0 ${new TinyColor('#000').setAlpha(0.08).toRgbString()}`,
|
|
|
|
].join(','),
|
|
|
|
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()}
|
|
|
|
`,
|
|
|
|
boxShadowDrawerRight:
|
|
|
|
'6px 0 16px -8px rgba(0, 0, 0, 0.08), 9px 0 28px 0 rgba(0, 0, 0, 0.05),12px 0 48px 16px rgba(0, 0, 0, 0.03)',
|
|
|
|
boxShadowDrawerLeft:
|
|
|
|
'-6px 0 16px -8px rgba(0, 0, 0, 0.08), -9px 0 28px 0 rgba(0, 0, 0, 0.05), -12px 0 48px 16px rgba(0, 0, 0, 0.03)',
|
|
|
|
boxShadowDrawerUp:
|
|
|
|
'0 -6px 16px -8px rgba(0, 0, 0, 0.32), 0 -9px 28px 0 rgba(0, 0, 0, 0.2),0 -12px 48px 16px rgba(0, 0, 0, 0.12)',
|
|
|
|
boxShadowDrawerDown:
|
|
|
|
'0 6px 16px -8px rgba(0, 0, 0, 0.32), 0 9px 28px 0 rgba(0, 0, 0, 0.2), 0 12px 48px 16px rgba(0, 0, 0, 0.12)',
|
|
|
|
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
|
|
|
|
...alias,
|
2022-03-21 16:48:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return aliasToken;
|
|
|
|
}
|