Skip to content

Commit 3469a4f

Browse files
committed
refactor: reduce repetition and simplify syntax
1 parent c9c7333 commit 3469a4f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/shared/colors.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
export function getColor(color) {
66
if (!color) return "color: inherit";
77
const isDark = matchMedia("(prefers-color-scheme: dark)").matches;
8-
/** @type {string} */
9-
let hex;
10-
if (color === "blue") {
11-
hex = isDark ? "#006fff" : "#317eff";
12-
} else if (color === "green") {
13-
hex = isDark ? "#60f36c" : "#2bb239";
14-
} else if (color === "yellow") {
15-
hex = isDark ? "#fff600" : "#b8722c";
16-
} else {
17-
return "";
8+
const colors = {
9+
blue: { dark: "#006fff", light: "#317eff" },
10+
green: { dark: "#60f36c", light: "#2bb239" },
11+
yellow: { dark: "#fff600", light: "#b8722c" },
12+
};
13+
if (color in colors) {
14+
const hex = isDark ? colors[color].dark : colors[color].light;
15+
return `color: ${hex}`;
1816
}
19-
return `color: ${hex}`;
17+
return "";
2018
}

0 commit comments

Comments
 (0)