From 058b5d34d8494f04cf3a079563574207454c2132 Mon Sep 17 00:00:00 2001 From: Hasan Yahya Date: Tue, 4 Jun 2024 14:57:40 +0500 Subject: [PATCH] refactor: Improve image display and functionality in Playground component --- src/components/component/playground.jsx | 41 ++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/components/component/playground.jsx b/src/components/component/playground.jsx index d383520..b42f6f6 100644 --- a/src/components/component/playground.jsx +++ b/src/components/component/playground.jsx @@ -220,7 +220,40 @@ export function Playground() { }); }; - hvalueChanged = (value) => { + const hvalueChanged = (value) => { + // set hue value + setDefaultHue(value); + // convert hsl to rgb + const rgb = hslToRgb(value, defaultSaturation, defaultBrightness); + setRValue(rgb.r); + setGValue(rgb.g); + setBValue(rgb.b); + // convert to hex + setHexValue(rgbToHex(rgb.r, rgb.g, rgb.b)); + }; + + const svalueChanged = (value) => { + // set saturation value + setDefaultSaturation(value); + // convert hsl to rgb + const rgb = hslToRgb(defaultHue, value, defaultBrightness); + setRValue(rgb.r); + setGValue(rgb.g); + setBValue(rgb.b); + // convert to hex + setHexValue(rgbToHex(rgb.r, rgb.g, rgb.b)); + }; + + const _lvalueChanged = (value) => { + // set brightness value + setDefaultBrightness(value); + // convert hsl to rgb + const rgb = hslToRgb(defaultHue, defaultSaturation, value); + setRValue(rgb.r); + setGValue(rgb.g); + setBValue(rgb.b); + // convert to hex + setHexValue(rgbToHex(rgb.r, rgb.g, rgb.b)); }; if (!imageUploaded) { @@ -277,7 +310,7 @@ export function Playground() {
Hue
- setDefaultHue(value)} + hvalueChanged(value)} />
{defaultHue}°
@@ -285,7 +318,7 @@ export function Playground() {
Saturation
- setDefaultSaturation(value)} + svalueChanged(value)} />
{defaultSaturation}%
@@ -293,7 +326,7 @@ export function Playground() {
Brightness
- setDefaultBrightness(value)} + _lvalueChanged(value)} />
{defaultBrightness}%