Skip to content

Commit

Permalink
refactor: Improve image display in Playground component
Browse files Browse the repository at this point in the history
  • Loading branch information
HasanYahya101 committed Jun 4, 2024
1 parent 7fe9d27 commit f4aa994
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/components/component/playground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ export function Playground() {
);
};

const hslToRgb = (h, s, l) => {
h /= 360;
s /= 100;
l /= 100;
let r, g, b;
if (s === 0) {
r = g = b = l;
} else {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1 / 3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1 / 3);
}
return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) };
};

const hexToRgb = (hex) => {
const match = hex.replace(/#/, '').match(/.{1,2}/g);
return {
Expand Down Expand Up @@ -171,7 +196,7 @@ export function Playground() {
onClick: () => toast.dismiss(),
}
});
}
};

function CopyHEX() {
navigator.clipboard.writeText(hexValue);
Expand All @@ -182,7 +207,7 @@ export function Playground() {
onClick: () => toast.dismiss(),
}
});
}
};

function CopyHSL() {
navigator.clipboard.writeText(`${defaultHue}°, ${defaultSaturation}%, ${defaultBrightness}%`);
Expand All @@ -193,7 +218,10 @@ export function Playground() {
onClick: () => toast.dismiss(),
}
});
}
};

hvalueChanged = (value) => {
};

if (!imageUploaded) {
return (
Expand Down

0 comments on commit f4aa994

Please sign in to comment.