uiwjs / react-color

🎨 Is a tiny color picker widget component for React apps.
https://uiwjs.github.io/react-color
MIT License
274 stars 92 forks source link

Change Value for Wheel #135

Closed spl1nt3r99 closed 9 months ago

spl1nt3r99 commented 9 months ago

Is there any slider I can use to change v for hsva wheel?

jaywcjlove commented 9 months ago

@spl1nt3r99 Like this ?

import React, { useState } from 'react';
import Slider from '@uiw/react-color-slider';
import Wheel from '@uiw/react-color-wheel';

export default function Demo() {
  const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 });
  return (
    <>
      <Slider
        color={hsva}
        style={{ paddingBottom: 10 }}
        onChange={(color) => {
          setHsva({ ...hsva, ...color.hsv });
        }}
      />
      <Wheel
        color={hsva}
        onChange={(color) => setHsva({ ...hsva, ...color.hsva })}
      />
    </>
  );
}
spl1nt3r99 commented 9 months ago

@jaywcjlove I mean like ShadeSlider. Can I reuse it for Value?

jaywcjlove commented 9 months ago

@spl1nt3r99 You can use it in combination, I don't understand what you need to do

spl1nt3r99 commented 9 months ago

@jaywcjlove For example, pre-default state of wheel is {h: 214, s: 43, v: 90, a: 1}. Any changes at wheel will modified only h and s properties. I want to add slider like this to change v property too. Снимок экрана 2023-11-29 в 14 23 12

jaywcjlove commented 9 months ago
image

@spl1nt3r99

jaywcjlove commented 9 months ago
import React, { useState, Fragment } from 'react';
import Wheel from '@uiw/react-color-wheel';
import ShadeSlider from '@uiw/react-color-shade-slider';
import { hsvaToHex } from '@uiw/color-convert';

function Demo() {
  const [hsva, setHsva] = useState({ h: 214, s: 43, v: 90, a: 1 });
  return (
    <Fragment>
      <Wheel color={hsva} onChange={(color) => setHsva({ ...hsva, ...color.hsva })} />
      <ShadeSlider
        hsva={hsva}
        style={{ width: 210, marginTop: 20 }}
        onChange={(newShade) => {
          setHsva({ ...hsva, ...newShade });
        }}
      />
      <div style={{ width: '100%', height: 34, marginTop: 20, background: hsvaToHex(hsva) }}></div>
    </Fragment>
  );
}

export default Demo;
spl1nt3r99 commented 9 months ago

@jaywcjlove Thank you!