@@ -17,9 +17,8 @@ import NavLink from './NavLink';
17
17
18
18
declare global {
19
19
interface Window {
20
- __onThemeChange : ( ) => void ,
21
- __theme :string ,
22
- __setPreferredTheme : ( theme : string ) => void
20
+ __theme : string ;
21
+ __setPreferredTheme : ( theme : string ) => void ;
23
22
}
24
23
}
25
24
@@ -100,21 +99,6 @@ function inferSection(pathname: string): 'learn' | 'reference' | 'home' {
100
99
export default function Nav ( ) {
101
100
const { pathname} = useRouter ( ) ;
102
101
const { isOpen, toggleOpen} = React . useContext ( MenuContext ) ;
103
- // TODO: persist
104
-
105
- const [ isDark , setIsDark ] = React . useState ( ( ) => {
106
- if ( typeof document === 'undefined' ) {
107
- return false ;
108
- }
109
- return document . documentElement . classList . contains ( 'dark' ) ;
110
- } ) ;
111
-
112
- React . useEffect ( ( ) => {
113
- window . __onThemeChange = ( ) => {
114
- setIsDark ( window . __theme === 'dark' ? true : false ) ;
115
- } ;
116
- } , [ ] ) ;
117
-
118
102
const section = inferSection ( pathname ) ;
119
103
120
104
function handleFeedback ( ) {
@@ -152,17 +136,28 @@ export default function Nav() {
152
136
Beta
153
137
</ div >
154
138
</ div >
155
- < button
156
- type = "button"
157
- aria-label = { isDark ? 'Use Light Mode' : 'Use Dark Mode' }
158
- onClick = { ( ) => {
159
- window . __setPreferredTheme (
160
- window . __theme === 'light' ? 'dark' : 'light'
161
- ) ;
162
- } }
163
- className = "hidden lg:flex items-center h-full pr-2" >
164
- { isDark ? lightIcon : darkIcon }
165
- </ button >
139
+ < div className = "block dark:hidden" >
140
+ < button
141
+ type = "button"
142
+ aria-label = "Use Dark Mode"
143
+ onClick = { ( ) => {
144
+ window . __setPreferredTheme ( 'dark' ) ;
145
+ } }
146
+ className = "hidden lg:flex items-center h-full pr-2" >
147
+ { darkIcon }
148
+ </ button >
149
+ </ div >
150
+ < div className = "hidden dark:block" >
151
+ < button
152
+ type = "button"
153
+ aria-label = "Use Light Mode"
154
+ onClick = { ( ) => {
155
+ window . __setPreferredTheme ( 'light' ) ;
156
+ } }
157
+ className = "hidden lg:flex items-center h-full pr-2" >
158
+ { lightIcon }
159
+ </ button >
160
+ </ div >
166
161
</ div >
167
162
< div className = "px-0 pt-2 w-full 2xl:max-w-xs hidden lg:flex items-center self-center border-b-0 lg:border-b border-border dark:border-border-dark" >
168
163
< NavLink href = "/" isActive = { section === 'home' } >
@@ -183,17 +178,28 @@ export default function Nav() {
183
178
onClick = { handleFeedback } >
184
179
{ feedbackIcon }
185
180
</ button >
186
- < button
187
- type = "button"
188
- aria-label = { isDark ? 'Use Light Mode' : 'Use Dark Mode' }
189
- onClick = { ( ) => {
190
- window . __setPreferredTheme (
191
- window . __theme === 'light' ? 'dark' : 'light'
192
- ) ;
193
- } }
194
- className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
195
- { isDark ? lightIcon : darkIcon }
196
- </ button >
181
+ < div className = "block dark:hidden" >
182
+ < button
183
+ type = "button"
184
+ aria-label = "Use Dark Mode"
185
+ onClick = { ( ) => {
186
+ window . __setPreferredTheme ( 'dark' ) ;
187
+ } }
188
+ className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
189
+ { darkIcon }
190
+ </ button >
191
+ </ div >
192
+ < div className = "hidden dark:block" >
193
+ < button
194
+ type = "button"
195
+ aria-label = "Use Light Mode"
196
+ onClick = { ( ) => {
197
+ window . __setPreferredTheme ( 'light' ) ;
198
+ } }
199
+ className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
200
+ { lightIcon }
201
+ </ button >
202
+ </ div >
197
203
</ div >
198
204
</ nav >
199
205
) ;
0 commit comments