ant-design/components/color-picker/util.ts
二货爱吃白萝卜 76f6ddc7e6
fix: ColorPicker not support prefixCls (#46561)
* fix: ColorPicker should support prefixCls

* test: add test case
2023-12-21 14:39:43 +08:00

21 lines
634 B
TypeScript

import type { ColorGenInput } from '@rc-component/color-picker';
import type { Color } from './color';
import { ColorFactory } from './color';
export const generateColor = (color: ColorGenInput<Color>): Color => {
if (color instanceof ColorFactory) {
return color;
}
return new ColorFactory(color);
};
export const getRoundNumber = (value: number) => Math.round(Number(value || 0));
export const getAlphaColor = (color: Color) => getRoundNumber(color.toHsb().a * 100);
export const genAlphaColor = (color: Color, alpha?: number) => {
const hsba = color.toHsb();
hsba.a = alpha || 1;
return generateColor(hsba);
};