ant-design/components/color-picker/util.ts
红果汁 c377457104
feat: ColorPicker implement disabledAlpha API (#43355)
* feat: implement disabledAlpha api

* refactor: add genAlphaColor and optimization code

* chore: clean code

* refactor: add warning and optimization code

* chore: clean code

* docs: modify version number

* fix: fix prettier
2023-07-12 19:42:33 +08:00

23 lines
689 B
TypeScript

import type { ColorGenInput } from '@rc-component/color-picker';
import type { Color } from './color';
import { ColorFactory } from './color';
export const customizePrefixCls = 'ant-color-picker';
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);
};