Skip to content

Commit

Permalink
refactor: simplify theme class workaround (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric authored Apr 5, 2024
1 parent 81f7c3a commit 2b9bf5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion webui/src/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Root({ children }: { children: React.ReactNode }) {
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</head>
<body>{children}</body>
<body className="dark-theme">{children}</body>
</html>
);
}
15 changes: 5 additions & 10 deletions webui/src/providers/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import { useColorScheme } from 'nativewind';
import { useEffect, type PropsWithChildren } from 'react';

export function ThemeProvider({ children }: PropsWithChildren) {
useWorkaroundForThemeClass();

return children;
}

function useWorkaroundForThemeClass() {
const { colorScheme } = useColorScheme();

useEffect(() => {
if (document.body) {
// Keep the prefered color scheme synced with the `body` class name
if (document.body && colorScheme) {
document.body.classList.remove('light-theme', 'dark-theme');
if (colorScheme) {
document.body.className = `${colorScheme}-theme`;
}
document.body.className = `${colorScheme}-theme`;
}
}, [colorScheme]);

return children;
}

0 comments on commit 2b9bf5a

Please sign in to comment.