|
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/"; |
8 | 2 |
|
| 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 | + */ |
9 | 9 | function getColors(theme) {
|
10 |
| - |
11 |
| - switch(theme) { |
| 10 | + switch (theme) { |
12 | 11 | 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`); |
22 | 13 | case "light_high_contrast":
|
23 |
| - return lightHighContrastColors; |
| 14 | + return require(`${path}light_high_contrast.json`); |
24 | 15 | case "light_colorblind":
|
25 |
| - return lightColorblindColors; |
| 16 | + return require(`${path}light_colorblind.json`); |
26 | 17 | 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`); |
38 | 19 | case "dark_high_contrast":
|
39 |
| - return darkHighContrastColors; |
| 20 | + return require(`${path}dark_high_contrast.json`); |
40 | 21 | case "dark_colorblind":
|
41 |
| - return darkColorblindColors; |
| 22 | + return require(`${path}dark_colorblind.json`); |
42 | 23 | case "dark_dimmed":
|
43 |
| - return dimmedColors; |
| 24 | + return require(`${path}dark_dimmed.json`); |
44 | 25 | default:
|
45 | 26 | throw new Error(`Colors are missing for value: ${theme}`);
|
46 | 27 | }
|
47 | 28 | }
|
48 | 29 |
|
| 30 | +// Exports the `getColors` function |
49 | 31 | module.exports = {
|
50 | 32 | getColors,
|
51 | 33 | };
|
| 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