ant-design/components/theme/util/genPresetColor.ts
lijianan 2b629ef391
type: rm useless type of reducer (#49555)
* type: rm useless type of reducer

* Update components/_util/ActionButton.tsx

Signed-off-by: lijianan <574980606@qq.com>

---------

Signed-off-by: lijianan <574980606@qq.com>
2024-06-22 23:57:39 +08:00

36 lines
1.1 KiB
TypeScript

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