fix build
This commit is contained in:
parent
c0ee8a4a11
commit
71590024e7
28 changed files with 943 additions and 2 deletions
26
contexts/MenuContext.tsx
Normal file
26
contexts/MenuContext.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import { createContext, useState } from 'react'
|
||||
|
||||
const MenuContext = createContext<any>({})
|
||||
|
||||
const MenuContextProvider = (props: any) => {
|
||||
const [showMenu, setShowMenu] = useState<boolean>(false)
|
||||
const [showUser, setShowUser] = useState<boolean>(false)
|
||||
|
||||
return (
|
||||
<MenuContext.Provider
|
||||
value={{
|
||||
showMenu,
|
||||
setShowMenu,
|
||||
showUser,
|
||||
setShowUser,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</MenuContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export { MenuContext, MenuContextProvider }
|
||||
56
contexts/ThemeContext.tsx
Normal file
56
contexts/ThemeContext.tsx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import { createContext, useEffect, useState } from 'react'
|
||||
|
||||
export const cachedDarkKey = 'chora-web-dark'
|
||||
|
||||
const initDarkTheme = () => {
|
||||
let initDarkTheme = false
|
||||
|
||||
if (
|
||||
typeof localStorage !== 'undefined' &&
|
||||
localStorage.getItem(cachedDarkKey)
|
||||
) {
|
||||
initDarkTheme = localStorage.getItem(cachedDarkKey) === 'true'
|
||||
} else if (typeof window !== 'undefined') {
|
||||
initDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
}
|
||||
|
||||
return initDarkTheme
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<any>({})
|
||||
|
||||
const ThemeContextProvider = (props: any) => {
|
||||
const [darkTheme, setDarkTheme] = useState<boolean>(initDarkTheme())
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
|
||||
const root = window.document.documentElement
|
||||
|
||||
if (darkTheme) {
|
||||
root.classList.add('dark-theme')
|
||||
root.style.backgroundColor = '#161616' // --background-secondary (dark-theme)
|
||||
} else {
|
||||
root.classList.remove('dark-theme')
|
||||
root.style.backgroundColor = '#FCFCFC' // --background-secondary (light-theme)
|
||||
}
|
||||
|
||||
localStorage.setItem(cachedDarkKey, darkTheme ? 'true' : 'false')
|
||||
}
|
||||
}, [darkTheme])
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider
|
||||
value={{
|
||||
darkTheme,
|
||||
setDarkTheme,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</ThemeContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export { ThemeContext, ThemeContextProvider }
|
||||
4
contexts/index.ts
Normal file
4
contexts/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
'use client'
|
||||
|
||||
export { MenuContext, MenuContextProvider } from './MenuContext'
|
||||
export { ThemeContext, ThemeContextProvider } from './ThemeContext'
|
||||
Loading…
Add table
Add a link
Reference in a new issue