2022-03-21 16:48:25 +08:00
|
|
|
import { generate } from '@ant-design/colors';
|
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
|
|
|
import type { AliasToken, DerivativeToken, OverrideToken } from '../interface';
|
|
|
|
|
|
|
|
/** Raw merge of `@ant-design/cssinjs` token. Which need additional process */
|
|
|
|
type RawMergedToken = DerivativeToken & OverrideToken;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seed (designer) > Derivative (designer) > Alias (developer).
|
|
|
|
*
|
|
|
|
* Merge seed & derivative & override token and generate alias token for developer.
|
|
|
|
*/
|
|
|
|
export default function formatToken(derivativeToken: RawMergedToken): AliasToken {
|
|
|
|
const { derivative, ...restToken } = derivativeToken;
|
|
|
|
|
|
|
|
const mergedToken = {
|
|
|
|
...restToken,
|
|
|
|
...derivative,
|
|
|
|
};
|
|
|
|
|
2022-03-22 09:37:37 +08:00
|
|
|
const { fontSizes, lineHeights } = mergedToken;
|
|
|
|
|
2022-03-21 16:48:25 +08:00
|
|
|
// FIXME: tmp
|
|
|
|
const primaryColors = generate(mergedToken.colorPrimary);
|
|
|
|
const infoColors = generate(mergedToken.colorInfo);
|
|
|
|
const successColors = generate(mergedToken.colorSuccess);
|
|
|
|
const warningColors = generate(mergedToken.colorWarning);
|
|
|
|
const errorColors = generate(mergedToken.colorError);
|
|
|
|
|
|
|
|
// Generate alias token
|
|
|
|
const aliasToken: AliasToken = {
|
|
|
|
...mergedToken,
|
|
|
|
|
|
|
|
// Colors
|
2022-03-22 13:26:29 +08:00
|
|
|
colorTextSecondary: mergedToken.colorTextBelow,
|
|
|
|
colorTextDisabled: mergedToken.colorTextBelow2,
|
2022-03-22 20:02:04 +08:00
|
|
|
colorPlaceholder: mergedToken.colorTextBelow2,
|
|
|
|
colorTextHeading: mergedToken.colorText,
|
|
|
|
|
|
|
|
colorBgContainer: mergedToken.colorBgBelow2,
|
|
|
|
colorBgComponent: mergedToken.colorBg,
|
2022-03-24 14:30:48 +08:00
|
|
|
colorBgComponentSecondary: mergedToken.colorBg2,
|
2022-03-22 20:02:04 +08:00
|
|
|
colorBgComponentDisabled: mergedToken.colorBgBelow2,
|
2022-03-22 13:26:29 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorLink: mergedToken.colorPrimary,
|
|
|
|
colorLinkHover: primaryColors[4],
|
|
|
|
colorLinkActive: primaryColors[6],
|
|
|
|
|
|
|
|
colorAction: mergedToken.colorTextBelow,
|
|
|
|
colorActionHover: mergedToken.colorText,
|
|
|
|
|
2022-03-22 09:37:37 +08:00
|
|
|
// Font
|
|
|
|
fontSizeSM: fontSizes[0],
|
|
|
|
fontSize: fontSizes[1],
|
|
|
|
fontSizeLG: fontSizes[2],
|
|
|
|
fontSizeXL: fontSizes[3],
|
|
|
|
fontSizeHeading1: fontSizes[6],
|
|
|
|
fontSizeHeading2: fontSizes[5],
|
|
|
|
fontSizeHeading3: fontSizes[4],
|
|
|
|
fontSizeHeading4: fontSizes[3],
|
|
|
|
fontSizeHeading5: fontSizes[2],
|
|
|
|
|
|
|
|
lineHeight: lineHeights[1],
|
|
|
|
lineHeightLG: lineHeights[2],
|
|
|
|
|
|
|
|
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-03-22 20:02:04 +08:00
|
|
|
controlItemBgHover: mergedToken.colorBgBelow2,
|
2022-03-22 13:26:29 +08:00
|
|
|
|
|
|
|
// 👀👀👀👀👀👀👀👀👀 Not align with Derivative 👀👀👀👀👀👀👀👀👀
|
|
|
|
// FIXME: @arvinxx handle this
|
|
|
|
controlLineType: 'solid',
|
|
|
|
controlRadius: mergedToken.radiusBase,
|
|
|
|
colorBorder: new TinyColor({ h: 0, s: 0, v: 85 }).toHexString(),
|
|
|
|
colorSplit: new TinyColor({ h: 0, s: 0, v: 94 }).toHexString(),
|
2022-03-22 20:02:04 +08:00
|
|
|
controlItemBgActive: primaryColors[0],
|
2022-03-22 13:26:29 +08:00
|
|
|
|
2022-03-21 16:48:25 +08:00
|
|
|
// 🔥🔥🔥🔥🔥🔥🔥🔥🔥 All TMP Token leaves here 🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
|
|
|
// FIXME: Handle this when derivative is ready
|
2022-03-24 14:30:48 +08:00
|
|
|
// primaryColors,
|
|
|
|
// warningColors,
|
|
|
|
// errorColors,
|
|
|
|
|
|
|
|
colorSuccessSecondary: successColors[2],
|
|
|
|
colorWarningSecondary: warningColors[2],
|
|
|
|
colorErrorSecondary: errorColors[2],
|
|
|
|
colorInfoSecondary: infoColors[2],
|
|
|
|
|
2022-03-21 16:48:25 +08:00
|
|
|
linkDecoration: 'none',
|
|
|
|
linkHoverDecoration: 'none',
|
|
|
|
linkFocusDecoration: 'none',
|
|
|
|
|
|
|
|
controlPaddingHorizontal: 16,
|
|
|
|
controlPaddingHorizontalSM: 12,
|
|
|
|
|
|
|
|
padding: 16,
|
|
|
|
margin: 16,
|
|
|
|
|
|
|
|
paddingXXS: 2,
|
|
|
|
paddingXS: 4,
|
|
|
|
paddingSM: 8,
|
|
|
|
paddingLG: 32,
|
|
|
|
|
|
|
|
marginXXS: 2,
|
|
|
|
marginXS: 4,
|
2022-03-25 13:20:42 +08:00
|
|
|
marginSM: 8,
|
2022-03-21 16:48:25 +08:00
|
|
|
marginLG: 32,
|
|
|
|
|
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-21 16:48:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return aliasToken;
|
|
|
|
}
|