Spaces:
Running
Running
fix dark mode background
Browse files- client/index.html +27 -0
- client/src/App.jsx +26 -4
- client/src/index.css +43 -3
client/index.html
CHANGED
|
@@ -19,8 +19,35 @@
|
|
| 19 |
window.matchMedia &&
|
| 20 |
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
| 21 |
var theme = prefersDarkMode ? "dark" : "light";
|
|
|
|
|
|
|
|
|
|
| 22 |
document.documentElement.setAttribute("data-theme", theme);
|
| 23 |
document.documentElement.classList.add(theme + "-mode");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
})();
|
| 25 |
</script>
|
| 26 |
</head>
|
|
|
|
| 19 |
window.matchMedia &&
|
| 20 |
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
| 21 |
var theme = prefersDarkMode ? "dark" : "light";
|
| 22 |
+
var bgColor = prefersDarkMode ? "#0a0a0a" : "#f8f9fa";
|
| 23 |
+
|
| 24 |
+
// Apply theme to document elements
|
| 25 |
document.documentElement.setAttribute("data-theme", theme);
|
| 26 |
document.documentElement.classList.add(theme + "-mode");
|
| 27 |
+
|
| 28 |
+
// Set background color directly on HTML and BODY
|
| 29 |
+
document.documentElement.style.backgroundColor = bgColor;
|
| 30 |
+
|
| 31 |
+
// Create and apply a style tag for immediate styling
|
| 32 |
+
var style = document.createElement("style");
|
| 33 |
+
style.textContent = `
|
| 34 |
+
html, body {
|
| 35 |
+
background-color: ${bgColor} !important;
|
| 36 |
+
transition: background-color 0s;
|
| 37 |
+
}
|
| 38 |
+
html.${theme}-mode,
|
| 39 |
+
body.${theme}-mode,
|
| 40 |
+
#root {
|
| 41 |
+
background-color: ${bgColor} !important;
|
| 42 |
+
}
|
| 43 |
+
`;
|
| 44 |
+
document.head.appendChild(style);
|
| 45 |
+
|
| 46 |
+
// Apply theme class to body as well
|
| 47 |
+
document.addEventListener("DOMContentLoaded", function () {
|
| 48 |
+
document.body.classList.add(theme + "-mode");
|
| 49 |
+
document.body.style.backgroundColor = bgColor;
|
| 50 |
+
});
|
| 51 |
})();
|
| 52 |
</script>
|
| 53 |
</head>
|
client/src/App.jsx
CHANGED
|
@@ -20,22 +20,44 @@ function App() {
|
|
| 20 |
|
| 21 |
// Apply theme to document as early as possible
|
| 22 |
useEffect(() => {
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
document.body.classList.remove("light-mode", "dark-mode");
|
| 25 |
document.body.classList.add(`${mode}-mode`);
|
|
|
|
| 26 |
|
| 27 |
-
//
|
| 28 |
-
document.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}, [mode]);
|
| 30 |
|
| 31 |
return (
|
| 32 |
<div
|
| 33 |
-
className=
|
| 34 |
style={{
|
| 35 |
height: "100%",
|
| 36 |
width: "100%",
|
| 37 |
WebkitOverflowScrolling: "touch",
|
| 38 |
overflow: "auto",
|
|
|
|
| 39 |
}}
|
| 40 |
>
|
| 41 |
<ThemeProvider theme={theme}>
|
|
|
|
| 20 |
|
| 21 |
// Apply theme to document as early as possible
|
| 22 |
useEffect(() => {
|
| 23 |
+
const bgColor = mode === "dark" ? "#0a0a0a" : "#f8f9fa";
|
| 24 |
+
|
| 25 |
+
// Apply theme class to document elements
|
| 26 |
+
document.documentElement.setAttribute("data-theme", mode);
|
| 27 |
+
document.documentElement.classList.remove("light-mode", "dark-mode");
|
| 28 |
+
document.documentElement.classList.add(`${mode}-mode`);
|
| 29 |
+
document.documentElement.style.backgroundColor = bgColor;
|
| 30 |
+
|
| 31 |
+
// Apply theme class to body
|
| 32 |
document.body.classList.remove("light-mode", "dark-mode");
|
| 33 |
document.body.classList.add(`${mode}-mode`);
|
| 34 |
+
document.body.style.backgroundColor = bgColor;
|
| 35 |
|
| 36 |
+
// Apply to root element as well
|
| 37 |
+
const rootElement = document.getElementById("root");
|
| 38 |
+
if (rootElement) {
|
| 39 |
+
rootElement.style.backgroundColor = bgColor;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Update meta theme-color for mobile browsers
|
| 43 |
+
let metaThemeColor = document.querySelector("meta[name=theme-color]");
|
| 44 |
+
if (!metaThemeColor) {
|
| 45 |
+
metaThemeColor = document.createElement("meta");
|
| 46 |
+
metaThemeColor.name = "theme-color";
|
| 47 |
+
document.head.appendChild(metaThemeColor);
|
| 48 |
+
}
|
| 49 |
+
metaThemeColor.content = bgColor;
|
| 50 |
}, [mode]);
|
| 51 |
|
| 52 |
return (
|
| 53 |
<div
|
| 54 |
+
className={`App ${mode}-mode`}
|
| 55 |
style={{
|
| 56 |
height: "100%",
|
| 57 |
width: "100%",
|
| 58 |
WebkitOverflowScrolling: "touch",
|
| 59 |
overflow: "auto",
|
| 60 |
+
backgroundColor: mode === "dark" ? "#0a0a0a" : "#f8f9fa",
|
| 61 |
}}
|
| 62 |
>
|
| 63 |
<ThemeProvider theme={theme}>
|
client/src/index.css
CHANGED
|
@@ -3,13 +3,22 @@
|
|
| 3 |
line-height: 1.5;
|
| 4 |
font-weight: 400;
|
| 5 |
color-scheme: light dark;
|
| 6 |
-
background-color: #f5f5f5;
|
| 7 |
font-synthesis: none;
|
| 8 |
text-rendering: optimizeLegibility;
|
| 9 |
-webkit-font-smoothing: antialiased;
|
| 10 |
-moz-osx-font-smoothing: grayscale;
|
| 11 |
}
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
* {
|
| 14 |
margin: 0;
|
| 15 |
padding: 0;
|
|
@@ -20,18 +29,49 @@ html,
|
|
| 20 |
body,
|
| 21 |
#root {
|
| 22 |
width: 100%;
|
|
|
|
| 23 |
min-height: 100vh;
|
| 24 |
font-family: "Source Sans Pro", sans-serif;
|
| 25 |
}
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
body {
|
| 28 |
margin: 0;
|
| 29 |
min-width: 320px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
|
|
|
| 32 |
@media (prefers-color-scheme: light) {
|
| 33 |
:root {
|
| 34 |
-
|
| 35 |
-
background-color: #f5f5f5;
|
| 36 |
}
|
| 37 |
}
|
|
|
|
| 3 |
line-height: 1.5;
|
| 4 |
font-weight: 400;
|
| 5 |
color-scheme: light dark;
|
|
|
|
| 6 |
font-synthesis: none;
|
| 7 |
text-rendering: optimizeLegibility;
|
| 8 |
-webkit-font-smoothing: antialiased;
|
| 9 |
-moz-osx-font-smoothing: grayscale;
|
| 10 |
}
|
| 11 |
|
| 12 |
+
:root[data-theme="light"] {
|
| 13 |
+
color: #213547;
|
| 14 |
+
background-color: #f8f9fa;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
:root[data-theme="dark"] {
|
| 18 |
+
color: #ffffff;
|
| 19 |
+
background-color: #0a0a0a;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
* {
|
| 23 |
margin: 0;
|
| 24 |
padding: 0;
|
|
|
|
| 29 |
body,
|
| 30 |
#root {
|
| 31 |
width: 100%;
|
| 32 |
+
height: 100%;
|
| 33 |
min-height: 100vh;
|
| 34 |
font-family: "Source Sans Pro", sans-serif;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
html {
|
| 38 |
+
background-color: inherit;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
body {
|
| 42 |
margin: 0;
|
| 43 |
min-width: 320px;
|
| 44 |
+
background-color: inherit;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
overflow-x: hidden;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#root {
|
| 50 |
+
background-color: inherit;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* Styles spécifiques pour le mode sombre */
|
| 54 |
+
.dark-mode {
|
| 55 |
+
background-color: #0a0a0a !important;
|
| 56 |
+
color: #ffffff;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* Styles spécifiques pour le mode clair */
|
| 60 |
+
.light-mode {
|
| 61 |
+
background-color: #f8f9fa !important;
|
| 62 |
+
color: #213547;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* Assurer que le défilement est fluide */
|
| 66 |
+
@media (prefers-reduced-motion: no-preference) {
|
| 67 |
+
html {
|
| 68 |
+
scroll-behavior: smooth;
|
| 69 |
+
}
|
| 70 |
}
|
| 71 |
|
| 72 |
+
/* Supprimer les styles media query qui pourraient interférer */
|
| 73 |
@media (prefers-color-scheme: light) {
|
| 74 |
:root {
|
| 75 |
+
/* Ces styles sont maintenant gérés par les attributs data-theme */
|
|
|
|
| 76 |
}
|
| 77 |
}
|