feat(fs.dev): Added theme support
This commit is contained in:
parent
84ffe26a76
commit
e1ecd0cb98
26 changed files with 834 additions and 96 deletions
42
packages/freesewing.dev/hooks/useApp.js
Normal file
42
packages/freesewing.dev/hooks/useApp.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { useState } from 'react'
|
||||
// Stores state in local storage
|
||||
import useLocalStorage from 'shared/hooks/useLocalStorage.js'
|
||||
|
||||
function useApp(full = true) {
|
||||
|
||||
// User color scheme preference
|
||||
const prefersDarkMode = (typeof window !== 'undefined' && typeof window.matchMedia === 'function')
|
||||
? window.matchMedia(`(prefers-color-scheme: dark`).matches
|
||||
: null
|
||||
|
||||
// React State
|
||||
const [primaryMenu, setPrimaryMenu] = useState(false)
|
||||
|
||||
// Persistent state
|
||||
const [account, setAccount] = useLocalStorage('account', { username: false })
|
||||
const [theme, setTheme] = useLocalStorage('theme', prefersDarkMode ? 'dark' : 'light')
|
||||
|
||||
|
||||
// State methods
|
||||
const togglePrimaryMenu = () => setPrimaryMenu(!primaryMenu)
|
||||
const openPrimaryMenu = () => setPrimaryMenu(true)
|
||||
const closePrimaryMenu = () => setPrimaryMenu(false)
|
||||
|
||||
|
||||
return {
|
||||
// State
|
||||
primaryMenu,
|
||||
theme,
|
||||
|
||||
// State setters
|
||||
setPrimaryMenu,
|
||||
setTheme,
|
||||
|
||||
// State handlers
|
||||
togglePrimaryMenu,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default useApp
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue