Skip to content

Commit

Permalink
Change the text color if the bg is dark
Browse files Browse the repository at this point in the history
  • Loading branch information
agatemosu committed Jul 24, 2024
1 parent c413cbd commit e90348e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ function createColorPicker(colorPicker, tierLabel, defaultColor) {
});

pickr.on("save", (color) => {
let selectedColor;

if (color === null) {
pickr.setColor(clearColor);
selectedColor = clearColor;
} else {
selectedColor = color.toHEXA().toString();
return;
}

tierLabel.style.backgroundColor = selectedColor;
const hsl = color.toHSLA();
const lightness = hsl[2];

tierLabel.style.backgroundColor = color.toHEXA().toString();
tierLabel.style.color = lightness < 50 ? "white" : "black";

pickr.hide();
});
}
Expand Down

0 comments on commit e90348e

Please sign in to comment.