1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 02:25:09 +00:00
conky/web/components/Layout.tsx

62 lines
1.4 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react'
2022-10-14 14:55:06 +00:00
import Footer from './Footer'
import Header from './Header'
function darkModeDefault() {
if (typeof window === 'undefined') {
return false
} else {
const theme = localStorage.getItem('theme')
return (
theme === 'dark' ||
(!theme && window.matchMedia('(prefers-color-scheme: dark)').matches)
)
}
}
interface LayoutProps {
children: React.ReactNode
}
2024-02-26 18:18:49 +00:00
export default function Layout({ children }: LayoutProps) {
const [darkMode, setDarkMode] = useState(darkModeDefault())
useEffect(() => {
if (darkMode) {
document.documentElement.classList.add('dark')
localStorage.setItem('theme', 'dark')
} else {
document.documentElement.classList.remove('dark')
localStorage.setItem('theme', 'light')
}
}, [darkMode])
useEffect(() => {
const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')
darkQuery.onchange = (e) => {
if (e.matches) {
setDarkMode(true)
} else {
setDarkMode(false)
}
}
}, [])
return (
<div>
2024-04-22 07:13:56 +00:00
<div className="sticky top-0 z-10">
2024-02-26 18:18:49 +00:00
<Header name="Conky" setDarkMode={setDarkMode} />
</div>
2024-04-22 07:13:56 +00:00
<div className="relative pb-4 md:pt-4">
2022-09-30 21:15:06 +00:00
<div className="flex flex-col items-center max-w-3xl w-full mx-auto">
{children}
</div>
</div>
2022-10-14 14:55:06 +00:00
<div className="relative">
<Footer />
</div>
</div>
)
}