1
1
import type { CSSProperties } from 'react' ;
2
2
import React , { forwardRef , useMemo } from 'react' ;
3
- import { ColorPickerPrefixCls , defaultColor , generateColor } from './util' ;
3
+ import { ColorPickerPrefixCls , defaultColor } from './util' ;
4
4
5
5
import classNames from 'classnames' ;
6
6
import { Color } from './color' ;
@@ -76,12 +76,10 @@ export default forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
76
76
value,
77
77
defaultValue,
78
78
} ) ;
79
- const alphaColor = useMemo ( ( ) => {
80
- const rgb = generateColor ( colorValue . toRgbString ( ) ) ;
81
- // alpha color need equal 1 for base color
82
- rgb . setAlpha ( 1 ) ;
83
- return rgb . toRgbString ( ) ;
84
- } , [ colorValue ] ) ;
79
+ const alphaColor = useMemo (
80
+ ( ) => colorValue . setA ( 1 ) . toRgbString ( ) ,
81
+ [ colorValue ] ,
82
+ ) ;
85
83
86
84
// ============================ Events ============================
87
85
const handleChange : BaseColorPickerProps [ 'onChange' ] = ( data , type ) => {
@@ -92,17 +90,10 @@ export default forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
92
90
} ;
93
91
94
92
// Convert
95
- const getHueColor = ( hue : number ) => {
96
- const hsb = colorValue . toHsb ( ) ;
97
- hsb . h = hue ;
98
- return new Color ( hsb ) ;
99
- } ;
93
+ const getHueColor = ( hue : number ) => new Color ( colorValue . setHue ( hue ) ) ;
100
94
101
- const getAlphaColor = ( alpha : number ) => {
102
- const hsb = colorValue . toHsb ( ) ;
103
- hsb . a = Math . round ( alpha ) / 100 ;
104
- return new Color ( hsb ) ;
105
- } ;
95
+ const getAlphaColor = ( alpha : number ) =>
96
+ new Color ( colorValue . setA ( alpha / 100 ) ) ;
106
97
107
98
// Slider change
108
99
const onHueChange = ( hue : number ) => {
@@ -170,7 +161,7 @@ export default forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
170
161
] }
171
162
min = { 0 }
172
163
max = { 100 }
173
- value = { colorValue . getAlpha ( ) * 100 }
164
+ value = { colorValue . a * 100 }
174
165
onChange = { onAlphaChange }
175
166
onChangeComplete = { onAlphaChangeComplete }
176
167
/>
0 commit comments