hxf31891 / react-gradient-color-picker

An easy to use color/gradient picker for React.js
MIT License
146 stars 49 forks source link

Update useColorPicker.ts to use current selected value from picker #110

Closed khoshrou closed 2 weeks ago

khoshrou commented 2 weeks ago

I like to create a component that contains ColorPicker and I like to pass the gradient object to the upper component. getGradientObject not returning the correct object coz color not updated with value yet. this happens for value to hex too. like this

const [color, setColor] = useState('rgba(70,70,142,1)');
const { getGradientObject, valueToHex } = useColorPicker(color, setColor);

function onChange(value: string) {
  setColor(value);

  if (props.onChange) {
      const g = getGradientObject();
      props.onChange(value, g.isGradient ? g : undefined);
  }
}
<ColorPicker value={color} onChange={onChange} width={290} />
hxf31891 commented 2 weeks ago

@khoshrou thanks for putting this PR together, going to merge now. Hope it resolves your issue.

khoshrou commented 2 weeks ago

Thanks, seems we need more changes. I will other pr's when I finished debugging.

hxf31891 commented 2 weeks ago

@khoshrou whats going on with it? Are you getting any bugs or just looking for different functionality?

khoshrou commented 1 week ago

please check the new pull request and seems npm not updated with the latest changes