Skip to content

Commit ce58bc4

Browse files
harish-sethuramangaearon
harish-sethuraman
authored andcommitted
Take system's theme for the site
1 parent a803dbf commit ce58bc4

File tree

1 file changed

+11
-1
lines changed
  • beta/src/components/Layout/Nav

1 file changed

+11
-1
lines changed

beta/src/components/Layout/Nav/Nav.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,23 @@ export default function Nav() {
9393
const {pathname} = useRouter();
9494
const {isOpen, toggleOpen} = React.useContext(MenuContext);
9595
// TODO: persist
96-
// TODO: respect system pref
96+
9797
const [isDark, setIsDark] = React.useState(() => {
9898
if (typeof document === 'undefined') {
9999
return false;
100100
}
101101
return document.documentElement.classList.contains('dark');
102102
});
103+
104+
React.useEffect(() => {
105+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
106+
document.documentElement.classList.add('dark');
107+
setIsDark(true);
108+
} else {
109+
setIsDark(false);
110+
}
111+
},[]);
112+
103113
const section = inferSection(pathname);
104114

105115
function handleFeedback() {

0 commit comments

Comments
 (0)