Refactor dark mode handling and update UI components
Extract dark mode logic into a reusable helper function to improve code clarity and maintainability. Updated the UI layout for better structure and styling, including replacing placeholder logos and enhancing card design.
This commit is contained in:
25
react-vite-client/src/theme_helpers/ThemeHelpers.ts
Normal file
25
react-vite-client/src/theme_helpers/ThemeHelpers.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export function handleDarkMode(): () => void {
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
|
||||
// Function to update dark mode for Syncfusion controls
|
||||
const updateDarkMode = (e: MediaQueryList | MediaQueryListEvent) => {
|
||||
if (e.matches) {
|
||||
// If the system is in dark mode, add the class
|
||||
document.body.classList.add("e-dark-mode");
|
||||
} else {
|
||||
// Otherwise, remove it
|
||||
document.body.classList.remove("e-dark-mode");
|
||||
}
|
||||
};
|
||||
|
||||
// Set initial mode based on system preference:
|
||||
updateDarkMode(mediaQuery); // Pass the initial `mediaQuery` directly
|
||||
|
||||
// Listen for changes in system preference:
|
||||
mediaQuery.addEventListener("change", updateDarkMode);
|
||||
|
||||
// Cleanup function to remove the event listener
|
||||
return () => {
|
||||
mediaQuery.removeEventListener("change", updateDarkMode);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user