|
1 | | -import React, { useMemo, useState } from 'react'; |
| 1 | +import React, { useEffect, useMemo, useState } from 'react'; |
2 | 2 | import { HsvaColor, hsvaToHslaString } from '@uiw/color-convert'; |
3 | | -import Interactive, { Interaction } from '@uiw/react-drag-event-interactive'; |
4 | | -import { Pointer, PointerProps } from './Pointer'; |
| 3 | +import Interactive, { type Interaction, clamp } from '@uiw/react-drag-event-interactive'; |
| 4 | +import { Pointer, type PointerProps } from './Pointer'; |
5 | 5 |
|
6 | 6 | export interface SaturationProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> { |
7 | 7 | prefixCls?: string; |
@@ -40,9 +40,15 @@ const Saturation = React.forwardRef<HTMLDivElement, SaturationProps>((props, ref |
40 | 40 |
|
41 | 41 | const pointerElement = useMemo(() => { |
42 | 42 | if (!hsva) return null; |
| 43 | + var ponitX = `${clamp(interaction.x, 0, interaction.width)}px`; |
| 44 | + var ponitY = `${clamp(interaction.y, 0, interaction.height)}px`; |
| 45 | + if (interaction.width === 0 || interaction.height === 0) { |
| 46 | + ponitX = `${hsva.s}%`; |
| 47 | + ponitY = `${100 - hsva.v}%`; |
| 48 | + } |
43 | 49 | const comProps = { |
44 | | - top: `${interaction.y}px`, |
45 | | - left: `${interaction.x}px`, |
| 50 | + top: ponitY, |
| 51 | + left: ponitX, |
46 | 52 | color: hsvaToHslaString(hsva), |
47 | 53 | }; |
48 | 54 | if (pointer && typeof pointer === 'function') { |
|
0 commit comments