-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorHelpers.js
40 lines (37 loc) · 1.09 KB
/
colorHelpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import chroma from "chroma-js";
const levels = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
function generatePalette(starterPalette) {
let newPalette = {
paletteName: starterPalette.paletteName,
id: starterPalette.id,
emoji: starterPalette.emoji,
colors: {},
};
for (let level of levels) {
newPalette.colors[level] = [];
}
for (let color of starterPalette.colors) {
let scale = getScale(color.color, 10).reverse();
for (let i in scale) {
newPalette.colors[levels[i]].push({
name: `${color.name} ${levels[i]}`,
id: color.name.toLowerCase().replace(/ /g, "-"),
hex: scale[i],
rgb: chroma(scale[i]).css(),
rgba: chroma(scale[i])
.css()
.replace("rgb", "rgba")
.replace(")", ",1.0)"),
});
}
}
return newPalette;
}
function getRange(hexColor) {
const end = "#fff";
return [chroma(hexColor).darken(1.4).hex(), hexColor, end];
}
function getScale(hexColor, numberOfColors) {
return chroma.scale(getRange(hexColor)).mode("lab").colors(numberOfColors);
}
export { generatePalette };