-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
97 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { curtain, root } from './DesktopTopNav.css.js' | ||
import { useTheme } from '../hooks/useTheme.js' | ||
import * as styles from './DesktopTopNav.css.js' | ||
import { Icon } from './Icon.js' | ||
|
||
DesktopTopNav.Curtain = Curtain | ||
|
||
export function DesktopTopNav() { | ||
return <div className={root} /> | ||
const { toggle, theme } = useTheme() | ||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.section} /> | ||
<div className={styles.section}> | ||
<div className={styles.item}> | ||
<button className={styles.button} onClick={toggle} type="button"> | ||
{theme === 'dark' ? ( | ||
<Icon size="18px" label="Light" src="/.vocs/icons/sun.svg" /> | ||
) : ( | ||
<Icon size="18px" label="Dark" src="/.vocs/icons/moon.svg" /> | ||
)} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export function Curtain() { | ||
return <div className={curtain} /> | ||
return <div className={styles.curtain} /> | ||
} |
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 was deleted.
Oops, something went wrong.
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,26 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export function useTheme() { | ||
const [theme, setTheme] = useState(() => { | ||
if (typeof window === 'undefined') return 'dark' | ||
if (localStorage.getItem('vocs.theme')) { | ||
const storedTheme = localStorage.getItem('vocs.theme') | ||
if (storedTheme) return storedTheme | ||
} | ||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' | ||
}) | ||
|
||
useEffect(() => { | ||
localStorage.setItem('vocs.theme', theme) | ||
|
||
if (theme === 'dark') document.documentElement.classList.add('dark') | ||
else document.documentElement.classList.remove('dark') | ||
}, [theme]) | ||
|
||
return { | ||
theme, | ||
toggle() { | ||
setTheme((theme) => (theme === 'light' ? 'dark' : 'light')) | ||
}, | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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