@ -15,6 +15,13 @@ import {MenuContext} from 'components/useMenu';
import { Logo } from '../../Logo' ;
import NavLink from './NavLink' ;
declare global {
interface Window {
__theme : string ;
__setPreferredTheme : ( theme : string ) = > void ;
}
}
const feedbackIcon = (
< svg
xmlns = "http://www.w3.org/2000/svg"
@ -92,14 +99,6 @@ function inferSection(pathname: string): 'learn' | 'reference' | 'home' {
export default function Nav() {
const { pathname } = useRouter ( ) ;
const { isOpen , toggleOpen } = React . useContext ( MenuContext ) ;
// TODO: persist
// TODO: respect system pref
const [ isDark , setIsDark ] = React . useState ( ( ) = > {
if ( typeof document === 'undefined' ) {
return false ;
}
return document . documentElement . classList . contains ( 'dark' ) ;
} ) ;
const section = inferSection ( pathname ) ;
function handleFeedback() {
@ -137,21 +136,28 @@ export default function Nav() {
Beta
< / div >
< / div >
< button
type = "button"
aria - label = { isDark ? 'Use Light Mode' : 'Use Dark Mode' }
onClick = { ( ) = > {
if ( isDark ) {
document . documentElement . classList . remove ( 'dark' ) ;
setIsDark ( false ) ;
} else {
document . documentElement . classList . add ( 'dark' ) ;
setIsDark ( true ) ;
}
} }
className = "hidden lg:flex items-center h-full pr-2" >
{ isDark ? lightIcon : darkIcon }
< / button >
< div className = "block dark:hidden" >
< button
type = "button"
aria - label = "Use Dark Mode"
onClick = { ( ) = > {
window . __setPreferredTheme ( 'dark' ) ;
} }
className = "hidden lg:flex items-center h-full pr-2" >
{ darkIcon }
< / button >
< / div >
< div className = "hidden dark:block" >
< button
type = "button"
aria - label = "Use Light Mode"
onClick = { ( ) = > {
window . __setPreferredTheme ( 'light' ) ;
} }
className = "hidden lg:flex items-center h-full pr-2" >
{ lightIcon }
< / button >
< / div >
< / div >
< 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" >
< NavLink href = "/" isActive = { section === 'home' } >
@ -172,21 +178,28 @@ export default function Nav() {
onClick = { handleFeedback } >
{ feedbackIcon }
< / button >
< button
type = "button"
aria - label = { isDark ? 'Use Light Mode' : 'Use Dark Mode' }
onClick = { ( ) = > {
if ( isDark ) {
document . documentElement . classList . remove ( 'dark' ) ;
setIsDark ( false ) ;
} else {
document . documentElement . classList . add ( 'dark' ) ;
setIsDark ( true ) ;
}
} }
className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
{ isDark ? lightIcon : darkIcon }
< / button >
< div className = "block dark:hidden" >
< button
type = "button"
aria - label = "Use Dark Mode"
onClick = { ( ) = > {
window . __setPreferredTheme ( 'dark' ) ;
} }
className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
{ darkIcon }
< / button >
< / div >
< div className = "hidden dark:block" >
< button
type = "button"
aria - label = "Use Light Mode"
onClick = { ( ) = > {
window . __setPreferredTheme ( 'light' ) ;
} }
className = "flex lg:hidden items-center p-1 h-full ml-4 lg:ml-6" >
{ lightIcon }
< / button >
< / div >
< / div >
< / nav >
) ;