Skip to content

Commit ad2ec4f

Browse files
Update colors.js
1 parent 38b50d4 commit ad2ec4f

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

src/colors.js

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,40 @@
1-
const lightColors = require("@primer/primitives/dist/json/colors/light.json");
2-
const lightHighContrastColors = require("@primer/primitives/dist/json/colors/light_high_contrast.json");
3-
const lightColorblindColors = require("@primer/primitives/dist/json/colors/light_colorblind.json");
4-
const darkColors = require("@primer/primitives/dist/json/colors/dark.json");
5-
const darkHighContrastColors = require("@primer/primitives/dist/json/colors/dark_high_contrast.json");
6-
const darkColorblindColors = require("@primer/primitives/dist/json/colors/dark_colorblind.json");
7-
const dimmedColors = require("@primer/primitives/dist/json/colors/dark_dimmed.json");
1+
const path = "@primer/primitives/dist/json/colors/";
82

3+
/**
4+
* Returns a theme object based on the provided theme name.
5+
* @param {string} theme - The name of the theme to retrieve.
6+
* @returns {Object} - The theme object.
7+
* @throws Will throw an error if the given theme is not a valid option.
8+
*/
99
function getColors(theme) {
10-
11-
switch(theme) {
10+
switch (theme) {
1211
case "light":
13-
14-
// Temp override until Primitives are updated
15-
lightColors.success.emphasis = "#1f883d";
16-
lightColors.btn.primary.bg = lightColors.success.emphasis;
17-
lightColors.btn.primary.hoverBg = lightColors.scale.green[5];
18-
lightColors.fg.default = "#1f2328";
19-
lightColors.fg.muted = "#656d76";
20-
21-
return lightColors;
12+
return require(`${path}light.json`);
2213
case "light_high_contrast":
23-
return lightHighContrastColors;
14+
return require(`${path}light_high_contrast.json`);
2415
case "light_colorblind":
25-
return lightColorblindColors;
16+
return require(`${path}light_colorblind.json`);
2617
case "dark":
27-
28-
// Temp override until Primitives are updated
29-
darkColors.fg.default = "#e6edf3";
30-
darkColors.fg.muted = "#7d8590";
31-
darkColors.accent.fg = "#2f81f7";
32-
darkColors.severe.subtle = "rgba(219, 109, 40, 0.1)";
33-
darkColors.danger.subtle = "rgba(248, 81, 73, 0.1)";
34-
darkColors.done.subtle = "rgba(163, 113, 247, 0.1)";
35-
darkColors.sponsors.subtle = "rgba(219, 97, 162, 0.1)";
36-
37-
return darkColors;
18+
return require(`${path}dark.json`);
3819
case "dark_high_contrast":
39-
return darkHighContrastColors;
20+
return require(`${path}dark_high_contrast.json`);
4021
case "dark_colorblind":
41-
return darkColorblindColors;
22+
return require(`${path}dark_colorblind.json`);
4223
case "dark_dimmed":
43-
return dimmedColors;
24+
return require(`${path}dark_dimmed.json`);
4425
default:
4526
throw new Error(`Colors are missing for value: ${theme}`);
4627
}
4728
}
4829

30+
// Exports the `getColors` function
4931
module.exports = {
5032
getColors,
5133
};
34+
35+
// IIFE to prevent global scope pollution
36+
(() => {
37+
// Example usage
38+
const lightColors = getColors("light");
39+
console.log(lightColors);
40+
})();

0 commit comments

Comments
 (0)