-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from sereneinserenade/feat/system-theme-option
feat: option to select system theme in theme dropdown
- Loading branch information
Showing
6 changed files
with
108 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useThemeDetector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export const useThemeDetector = () => { | ||
const getCurrentTheme = () => window.matchMedia("(prefers-color-scheme: dark)").matches | ||
const [isDarkTheme, setIsDarkTheme] = useState(getCurrentTheme()) | ||
|
||
const mqListener = (e: MediaQueryListEvent) => setIsDarkTheme(e.matches) | ||
|
||
useEffect(() => { | ||
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)") | ||
|
||
darkThemeMq.addEventListener('change', mqListener) | ||
|
||
return () => darkThemeMq.removeEventListener('change', mqListener) | ||
}, []) | ||
|
||
return isDarkTheme | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { createRoot } from 'react-dom/client' | ||
import { RecoilRoot } from 'recoil' | ||
|
||
import App from './App'; | ||
import './index.scss'; | ||
import App from './App' | ||
import './index.scss' | ||
|
||
const container = document.getElementById('root'); | ||
const container = document.getElementById('root') | ||
|
||
const root = createRoot(container!); // createRoot(container!) if you use TypeScript | ||
root.render(<App />); | ||
const root = createRoot(container!) | ||
root.render( | ||
<RecoilRoot> | ||
<App /> | ||
</RecoilRoot> | ||
); |