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.
36 lines
1.1 KiB
36 lines
1.1 KiB
2 years ago
|
/* eslint-disable import/prefer-default-export */
|
||
|
import type { CSSObject } from '@ant-design/cssinjs';
|
||
2 years ago
|
import type { AliasToken, PresetColorKey } from '../internal';
|
||
|
import { PresetColors } from '../interface';
|
||
|
import type { TokenWithCommonCls } from './genComponentStyleHook';
|
||
2 years ago
|
|
||
|
interface CalcColor {
|
||
|
/** token[`${colorKey}-1`] */
|
||
|
lightColor: string;
|
||
|
/** token[`${colorKey}-3`] */
|
||
|
lightBorderColor: string;
|
||
|
/** token[`${colorKey}-6`] */
|
||
|
darkColor: string;
|
||
|
/** token[`${colorKey}-7`] */
|
||
|
textColor: string;
|
||
|
}
|
||
|
|
||
|
type GenCSS = (colorKey: PresetColorKey, calcColor: CalcColor) => CSSObject;
|
||
|
|
||
2 years ago
|
export default function genPresetColor<Token extends TokenWithCommonCls<AliasToken>>(
|
||
2 years ago
|
token: Token,
|
||
|
genCss: GenCSS,
|
||
|
): CSSObject {
|
||
|
return PresetColors.reduce((prev: CSSObject, colorKey: PresetColorKey) => {
|
||
2 years ago
|
const lightColor = token[`${colorKey}1`];
|
||
|
const lightBorderColor = token[`${colorKey}3`];
|
||
|
const darkColor = token[`${colorKey}6`];
|
||
|
const textColor = token[`${colorKey}7`];
|
||
2 years ago
|
|
||
|
return {
|
||
|
...prev,
|
||
|
...genCss(colorKey, { lightColor, lightBorderColor, darkColor, textColor }),
|
||
|
};
|
||
|
}, {} as CSSObject);
|
||
|
}
|