ant-design/components/color-picker/util.ts
二货爱吃白萝卜 5dd072d3a0
refactor: Use @ant-design/fast-color instead (#49846)
* chore: use fast

* chore: tmp of it

* test: update snapshot

* fix: demo

* chore: fix warning

* fix: test

* chore: fix ts

* chore: fix lint

* test: update snapshot

* chore: use proxy

* test: coverage
2024-07-15 17:33:47 +08:00

21 lines
653 B
TypeScript

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