Skip to content

Commit 744f2ed

Browse files
committed
feat: after auto goes opposite to system
1 parent 483bcb2 commit 744f2ed

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/components/ThemeProvider.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ const setupPreferredListener = clientOnly(() => {
5555
return () => mediaQuery.removeEventListener('change', handler)
5656
})
5757

58+
const getNextTheme = clientOnly((current: ThemeMode): ThemeMode => {
59+
const themes: ThemeMode[] =
60+
getSystemTheme() === 'dark'
61+
? ['auto', 'light', 'dark']
62+
: ['auto', 'dark', 'light']
63+
return themes[(themes.indexOf(current) + 1) % themes.length]
64+
})
65+
5866
const themeDetectorScript = (function () {
5967
function themeFn() {
6068
try {
@@ -111,9 +119,7 @@ export function ThemeProvider({ children }: ThemeProviderProps) {
111119
}
112120

113121
const toggleMode = () => {
114-
setTheme(
115-
themeMode === 'light' ? 'dark' : themeMode === 'dark' ? 'auto' : 'light'
116-
)
122+
setTheme(getNextTheme(themeMode))
117123
}
118124

119125
return (

0 commit comments

Comments
 (0)