feat: extract function

This commit is contained in:
Caio Cabral committed 2025-01-11 16:40:07 -05:00
1 parent b0aa5e64f4
commit 6bb38c9339
4 files changed
+37 -46

No files matched your search

+10
View File
@@ -267,6 +267,7 @@ const newColors = {
blueGray600: "#344054",
blueGray800: "#1C2130",
blueBlueWave: "#1570EF",
/* I changed green 100 and green 700. Need to change red and warning as well, and refactor the object following the structure */
green100: "#67cd78",
green200: "#4B9B77",
green400: "#079455",
@@ -281,6 +282,15 @@ const newColors = {
red700: "#791515",
};
/* Structure:
Key:
main: background color
contrastText: color for main contrast text
light and dark: should be transparent (since we don't want MUI to make the light dark automatic calculations for us)
lowerContrastText: if there are any, use nested keys secondary and tertiary
lowContrast: if we need some low contrast for that color (for borders, and decorative elements). This should never be usend in text
*/
const newSemanticColors = {
accent: {
main: {
+1 -23
View File
@@ -1,30 +1,8 @@
import { createTheme } from "@mui/material";
import { baseTheme } from "./globalTheme";
import { /* colors, */ newSemanticColors } from "./constants";
import { extractThemeColors } from "./extractColorObject";
function extractThemeColors(themeType, colorObject) {
if (!["light", "dark"].includes(themeType)) {
throw new Error('Invalid theme type. Use "light" or "dark".');
}
const extract = (obj) => {
if (typeof obj !== "object" || obj === null) {
return obj;
}
if ("light" in obj && "dark" in obj) {
return obj[themeType]; // Return the value for the specified theme
}
// Reduce the object, keeping only the extracted themeType values
return Object.keys(obj).reduce((acc, key) => {
acc[key] = extract(obj[key]);
return acc;
}, {});
};
return extract(colorObject);
}
const palette = extractThemeColors("dark", newSemanticColors);
const darkTheme = createTheme({
@@ -0,0 +1,24 @@
function extractThemeColors(themeType, colorObject) {
if (!["light", "dark"].includes(themeType)) {
throw new Error('Invalid theme type. Use "light" or "dark".');
}
const extract = (obj) => {
if (typeof obj !== "object" || obj === null) {
return obj;
}
if ("light" in obj && "dark" in obj) {
return obj[themeType]; // Return the value for the specified theme
}
// Reduce the object, keeping only the extracted themeType values
return Object.keys(obj).reduce((acc, key) => {
acc[key] = extract(obj[key]);
return acc;
}, {});
};
return extract(colorObject);
}
export { extractThemeColors };
+2 -23
View File
@@ -1,31 +1,10 @@
import { createTheme } from "@mui/material";
import { baseTheme } from "./globalTheme";
import { /* colors, */ newSemanticColors } from "./constants";
import { extractThemeColors } from "./extractColorObject";
function extractThemeColors(themeType, colorObject) {
if (!["light", "dark"].includes(themeType)) {
throw new Error('Invalid theme type. Use "light" or "dark".');
}
const extract = (obj) => {
if (typeof obj !== "object" || obj === null) {
return obj;
}
if ("light" in obj && "dark" in obj) {
return obj[themeType]; // Return the value for the specified theme
}
// Reduce the object, keeping only the extracted themeType values
return Object.keys(obj).reduce((acc, key) => {
acc[key] = extract(obj[key]);
return acc;
}, {});
};
return extract(colorObject);
}
const palette = extractThemeColors("light", newSemanticColors);
/* TODO I figured out we could have just one theme by passing mode as parameter for theme function. Implement later */
const lightTheme = createTheme({
palette,