mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
22 lines
635 B
TypeScript
22 lines
635 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);
|
|
};
|