Skip to content

Commit 7a71cdc

Browse files
committed
fix: fix Saturation default value issue. #169
1 parent 035dd1e commit 7a71cdc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/color-saturation/src/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { useMemo, useState } from 'react';
1+
import React, { useEffect, useMemo, useState } from 'react';
22
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';
55

66
export interface SaturationProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
77
prefixCls?: string;
@@ -40,9 +40,15 @@ const Saturation = React.forwardRef<HTMLDivElement, SaturationProps>((props, ref
4040

4141
const pointerElement = useMemo(() => {
4242
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+
}
4349
const comProps = {
44-
top: `${interaction.y}px`,
45-
left: `${interaction.x}px`,
50+
top: ponitY,
51+
left: ponitX,
4652
color: hsvaToHslaString(hsva),
4753
};
4854
if (pointer && typeof pointer === 'function') {

0 commit comments

Comments
 (0)