mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 15:07:17 +02:00
fix(v2): switch a toggle when system theme changed (#2325)
* fix(v2): switch a toggle when system theme changed * fix: add check on disabled dark mode
This commit is contained in:
parent
68a5cd5df1
commit
37dff050ce
2 changed files with 12 additions and 7 deletions
|
@ -61,6 +61,18 @@ const useTheme = () => {
|
|||
}
|
||||
}, [setTheme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (disableDarkMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
window
|
||||
.matchMedia('(prefers-color-scheme: dark)')
|
||||
.addListener(({matches}) => {
|
||||
setTheme(matches ? themes.dark : themes.light);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return {
|
||||
isDarkTheme: theme === themes.dark,
|
||||
setLightTheme,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue