ant-design-vue/components/_util/colors.ts

35 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-01-26 03:13:29 +00:00
import type { PresetColorKey } from '../theme/interface';
import { PresetColors } from '../theme/interface';
2020-10-02 13:16:05 +00:00
2023-01-26 03:13:29 +00:00
type InverseColor = `${PresetColorKey}-inverse`;
const inverseColors = PresetColors.map<InverseColor>(color => `${color}-inverse`);
2020-10-02 13:16:05 +00:00
2023-01-26 03:13:29 +00:00
export const PresetStatusColorTypes = [
'success',
'processing',
'error',
'default',
'warning',
] as const;
2020-10-02 13:16:05 +00:00
2023-01-26 03:13:29 +00:00
export type PresetColorType = PresetColorKey | InverseColor;
export type PresetStatusColorType = typeof PresetStatusColorTypes[number];
/**
* determine if the color keyword belongs to the `Ant Design` {@link PresetColors}.
* @param color color to be judged
* @param includeInverse whether to include reversed colors
*/
export function isPresetColor(color?: any, includeInverse = true) {
if (includeInverse) {
return [...inverseColors, ...PresetColors].includes(color);
}
return PresetColors.includes(color);
}
export function isPresetStatusColor(color?: any): color is PresetStatusColorType {
return PresetStatusColorTypes.includes(color);
}