|
|
@ -5,7 +5,7 @@ import type { |
|
|
|
import classNames from 'classnames'; |
|
|
|
import useMergedState from 'rc-util/lib/hooks/useMergedState'; |
|
|
|
import type { CSSProperties } from 'react'; |
|
|
|
import React, { useContext, useEffect, useState } from 'react'; |
|
|
|
import React, { useContext, useEffect, useRef, useState } from 'react'; |
|
|
|
import genPurePanel from '../_util/PurePanel'; |
|
|
|
import type { ConfigConsumerProps } from '../config-provider/context'; |
|
|
|
import { ConfigContext } from '../config-provider/context'; |
|
|
@ -97,8 +97,9 @@ const ColorPicker: CompoundedComponent = (props) => { |
|
|
|
[`${prefixCls}-rtl`]: direction, |
|
|
|
}); |
|
|
|
const mergeCls = classNames(mergeRootCls, className, hashId); |
|
|
|
const popupAllowCloseRef = useRef(true); |
|
|
|
|
|
|
|
const handleChange = (data: Color, type?: HsbaColorType) => { |
|
|
|
const handleChange = (data: Color, type?: HsbaColorType, pickColor?: boolean) => { |
|
|
|
let color: Color = generateColor(data); |
|
|
|
if (colorCleared) { |
|
|
|
setColorCleared(false); |
|
|
@ -112,6 +113,10 @@ const ColorPicker: CompoundedComponent = (props) => { |
|
|
|
if (!value) { |
|
|
|
setColorValue(color); |
|
|
|
} |
|
|
|
// Only for drag-and-drop color picking
|
|
|
|
if (pickColor) { |
|
|
|
popupAllowCloseRef.current = false; |
|
|
|
} |
|
|
|
onChange?.(color, color.toHexString()); |
|
|
|
}; |
|
|
|
|
|
|
@ -119,6 +124,10 @@ const ColorPicker: CompoundedComponent = (props) => { |
|
|
|
setColorCleared(clear); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleChangeComplete = () => { |
|
|
|
popupAllowCloseRef.current = true; |
|
|
|
}; |
|
|
|
|
|
|
|
const popoverProps: PopoverProps = { |
|
|
|
open: popupOpen, |
|
|
|
trigger, |
|
|
@ -149,9 +158,18 @@ const ColorPicker: CompoundedComponent = (props) => { |
|
|
|
return wrapSSR( |
|
|
|
<Popover |
|
|
|
style={styles?.popup} |
|
|
|
onOpenChange={setPopupOpen} |
|
|
|
onOpenChange={(visible) => { |
|
|
|
if (popupAllowCloseRef.current) { |
|
|
|
setPopupOpen(visible); |
|
|
|
} |
|
|
|
}} |
|
|
|
content={ |
|
|
|
<ColorPickerPanel {...colorBaseProps} onChange={handleChange} onClear={handleClear} /> |
|
|
|
<ColorPickerPanel |
|
|
|
{...colorBaseProps} |
|
|
|
onChange={handleChange} |
|
|
|
onChangeComplete={handleChangeComplete} |
|
|
|
onClear={handleClear} |
|
|
|
/> |
|
|
|
} |
|
|
|
overlayClassName={prefixCls} |
|
|
|
{...popoverProps} |
|
|
|