mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 13:08:41 +08:00
b95d5674fa
* feat: color picker * chore: improve component logic * test: update snapshots * test: update snapshots * fix: remove unuse code * fix: adjusting the UI * fix: hairy edge in dark mode * fix: demo case * chore: rollback file * fix: improve code logic * perf: improve code * test: add test case * refactor: trigger use Popover instead * test: add test case * refactor: improve code logic * test: update snapshots * refactor: improve code * docs: add overview img * feat: style * chore: update snapshot * chore: code clean * chore: code clean * chore: fix lint * chore: update snapshot * feat: color block * chore: pure render * refactor: hex input number reduced to 6 digits * fix: rename React to react * refactor: trigger demo * docs: remove disabled demo --------- Co-authored-by: MadCcc <1075746765@qq.com>
46 lines
1006 B
TypeScript
46 lines
1006 B
TypeScript
/* eslint-disable class-methods-use-this */
|
|
import type { ColorGenInput } from '@rc-component/color-picker';
|
|
import { Color as RcColor } from '@rc-component/color-picker';
|
|
import { getHex } from './util';
|
|
|
|
export interface Color
|
|
extends Pick<
|
|
RcColor,
|
|
'toHsb' | 'toHsbString' | 'toHex' | 'toHexString' | 'toRgb' | 'toRgbString'
|
|
> {}
|
|
|
|
export class ColorFactory {
|
|
/** Original Color object */
|
|
private metaColor: RcColor;
|
|
|
|
constructor(color: ColorGenInput<Color>) {
|
|
this.metaColor = new RcColor(color as ColorGenInput);
|
|
}
|
|
|
|
toHsb() {
|
|
return this.metaColor.toHsb();
|
|
}
|
|
|
|
toHsbString() {
|
|
return this.metaColor.toHsbString();
|
|
}
|
|
|
|
toHex() {
|
|
return getHex(this.toHexString(), this.metaColor.getAlpha() < 1);
|
|
}
|
|
|
|
toHexString() {
|
|
return this.metaColor.getAlpha() === 1
|
|
? this.metaColor.toHexString()
|
|
: this.metaColor.toHex8String();
|
|
}
|
|
|
|
toRgb() {
|
|
return this.metaColor.toRgb();
|
|
}
|
|
|
|
toRgbString() {
|
|
return this.metaColor.toRgbString();
|
|
}
|
|
}
|