casesandberg / casesandberg/react-color
There might be wrong usage in the `examples/basic-with-react-hooks`, that will cause the <Alpha/> component not working.
- Dominant language
- JavaScript
- Stars
- 12.3k
- Forks
- 920
- PR merge metrics
- No merged PRs in 30d
Description
When I try it out the demo using `SketchPicker`, I found out that the `Alpha` handle is not working.
After digging for a while I found the usage from the demo is wrong.
```
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color);
return (
);
```
After adding some logs in the source code(helpers/color.js -> toState()), you can see the `onChange` callback pass a color object to the setColor, which includes a param named `hex`, and that will cause the `toState` function to handle it as a pure hex, so the alpha is lost.
It should be used like this:
```
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color.rgb);
return (
);
```
Contributor guide
Research direction
Start in examples/basic-with-react-hooks and compare its SketchPicker state handling with the callback behavior described in the issue. Read helpers/color.js, especially toState(), then update the demo usage so the Alpha value is preserved and verify that the picker displays transparency correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100