You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.6 KiB
128 lines
3.6 KiB
2 years ago
|
import { generate } from '@ant-design/colors';
|
||
|
import { TinyColor } from '@ctrl/tinycolor';
|
||
2 years ago
|
import type { ColorPalettes, MapToken, PresetColorType, SeedToken } from '../../interface';
|
||
2 years ago
|
import { defaultPresetColors } from '../seed';
|
||
|
import { getFontSizes } from '../shared';
|
||
|
import { generateBgPalettes, generateTextAlphaPalettes } from './palettes';
|
||
2 years ago
|
|
||
2 years ago
|
export default function derivative(token: SeedToken): MapToken {
|
||
2 years ago
|
const {
|
||
|
colorPrimary,
|
||
|
colorSuccess,
|
||
|
colorWarning,
|
||
|
colorError,
|
||
|
colorInfo,
|
||
2 years ago
|
colorBg,
|
||
2 years ago
|
motionUnit,
|
||
|
motionBase,
|
||
|
fontSizeBase,
|
||
|
sizeUnit,
|
||
|
sizeBaseStep,
|
||
|
gridUnit,
|
||
|
gridBaseStep,
|
||
|
radiusBase,
|
||
|
controlHeight,
|
||
|
lineWidth,
|
||
|
} = token;
|
||
|
|
||
|
const colorPalettes = Object.keys(defaultPresetColors)
|
||
|
.map((colorKey: keyof PresetColorType) => {
|
||
|
const colors = generate(token[colorKey]);
|
||
|
|
||
|
return new Array(10).fill(1).reduce((prev, _, i) => {
|
||
|
prev[`${colorKey}-${i + 1}`] = colors[i];
|
||
|
return prev;
|
||
|
}, {}) as ColorPalettes;
|
||
|
})
|
||
|
.reduce((prev, cur) => {
|
||
|
prev = {
|
||
|
...prev,
|
||
|
...cur,
|
||
|
};
|
||
|
return prev;
|
||
|
}, {} as ColorPalettes);
|
||
|
|
||
2 years ago
|
const primaryColors = generate(colorPrimary);
|
||
|
const successColors = generate(colorSuccess);
|
||
|
const warningColors = generate(colorWarning);
|
||
|
const errorColors = generate(colorError);
|
||
|
const infoColors = generate(colorInfo);
|
||
|
const bgColors = generateBgPalettes(colorBg);
|
||
|
// FIXME: need seedToken '#000'
|
||
|
const textColors = generateTextAlphaPalettes('#000');
|
||
2 years ago
|
|
||
2 years ago
|
const fontSizes = getFontSizes(fontSizeBase);
|
||
2 years ago
|
|
||
|
return {
|
||
|
...token,
|
||
|
...colorPalettes,
|
||
|
|
||
|
// motion
|
||
|
motionDurationFast: `${(motionBase + motionUnit * 1).toFixed(1)}s`,
|
||
|
motionDurationMid: `${(motionBase + motionUnit * 2).toFixed(1)}s`,
|
||
|
motionDurationSlow: `${(motionBase + motionUnit * 3).toFixed(1)}s`,
|
||
|
|
||
|
// font
|
||
|
fontSizes: fontSizes.map(fs => fs.size),
|
||
|
lineHeights: fontSizes.map(fs => fs.lineHeight),
|
||
|
|
||
|
// size
|
||
|
sizeSpaceSM: sizeUnit * (sizeBaseStep - 1),
|
||
|
sizeSpace: sizeUnit * sizeBaseStep,
|
||
|
sizeSpaceXS: sizeUnit * (sizeBaseStep - 2),
|
||
|
sizeSpaceXXS: sizeUnit * (sizeBaseStep - 3),
|
||
|
|
||
|
// grid
|
||
|
gridSpaceSM: gridUnit * (gridBaseStep - 1),
|
||
|
gridSpaceBase: gridUnit * gridBaseStep,
|
||
|
gridSpaceLG: gridUnit * (gridBaseStep + 1),
|
||
|
gridSpaceXL: gridUnit * (gridBaseStep + 2),
|
||
|
gridSpaceXXL: gridUnit * (gridBaseStep + 5),
|
||
|
|
||
|
// line
|
||
|
lineWidthBold: lineWidth + 1,
|
||
|
|
||
|
// radius
|
||
|
radiusSM: radiusBase / 2,
|
||
|
radiusLG: radiusBase * 2,
|
||
|
radiusXL: radiusBase * 4,
|
||
|
|
||
2 years ago
|
colorDefaultOutline: textColors['4'],
|
||
2 years ago
|
|
||
|
colorPrimaryActive: primaryColors[6],
|
||
|
colorPrimaryHover: primaryColors[4],
|
||
|
colorPrimaryOutline: new TinyColor(colorPrimary).setAlpha(0.2).toRgbString(),
|
||
|
colorPrimarySecondary: primaryColors[2],
|
||
|
colorPrimaryBorderHover: primaryColors[3],
|
||
|
|
||
|
colorSuccessSecondary: successColors[2],
|
||
2 years ago
|
colorSuccessBg: successColors[0],
|
||
2 years ago
|
|
||
|
colorErrorActive: errorColors[6],
|
||
|
colorErrorHover: errorColors[4],
|
||
|
colorErrorOutline: new TinyColor(colorError).setAlpha(0.2).toRgbString(),
|
||
|
colorErrorSecondary: errorColors[2],
|
||
2 years ago
|
colorErrorBg: errorColors[0],
|
||
2 years ago
|
|
||
|
colorWarningActive: warningColors[6],
|
||
|
colorWarningHover: warningColors[4],
|
||
|
colorWarningOutline: new TinyColor(colorWarning).setAlpha(0.2).toRgbString(),
|
||
|
colorWarningSecondary: warningColors[2],
|
||
2 years ago
|
colorWarningBg: warningColors[0],
|
||
2 years ago
|
|
||
|
colorInfoSecondary: infoColors[2],
|
||
2 years ago
|
colorInfoBg: infoColors[0],
|
||
2 years ago
|
|
||
|
colorHighlight: errorColors[4],
|
||
|
|
||
|
// control
|
||
|
controlHeightSM: controlHeight * 0.75,
|
||
|
controlHeightXS: controlHeight * 0.5,
|
||
|
controlHeightLG: controlHeight * 1.25,
|
||
2 years ago
|
|
||
|
// map token
|
||
|
bgColors,
|
||
|
textColors,
|
||
2 years ago
|
};
|
||
|
}
|