2026-07-30 13:55:28 +08:00
|
|
|
import { type ReactNode, useEffect } from "react"
|
|
|
|
|
import { useLayout } from "./layout-context"
|
|
|
|
|
|
|
|
|
|
type Breakpoints = {
|
|
|
|
|
sm: boolean
|
|
|
|
|
md: boolean
|
|
|
|
|
lg: boolean
|
|
|
|
|
xl: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const breakpoints: Breakpoints = { sm: false, md: false, lg: false, xl: false }
|
|
|
|
|
|
|
|
|
|
export function useBreakpoint() {
|
|
|
|
|
return breakpoints
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const bp = breakpoints
|
|
|
|
|
|
|
|
|
|
export default function Effects(props: { children?: ReactNode }) {
|
|
|
|
|
const { setNavbar } = useLayout()
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const sm = window.matchMedia("(width >= 40rem)")
|
|
|
|
|
const md = window.matchMedia("(width >= 48rem)")
|
|
|
|
|
const lg = window.matchMedia("(width >= 64rem)")
|
|
|
|
|
const xl = window.matchMedia("(width >= 80rem)")
|
|
|
|
|
|
|
|
|
|
breakpoints.sm = sm.matches
|
|
|
|
|
breakpoints.md = md.matches
|
|
|
|
|
breakpoints.lg = lg.matches
|
|
|
|
|
breakpoints.xl = xl.matches
|
|
|
|
|
|
|
|
|
|
setNavbar(md.matches)
|
|
|
|
|
|
2026-08-03 10:53:12 +08:00
|
|
|
sm.addEventListener("change", e => {
|
2026-07-30 13:55:28 +08:00
|
|
|
breakpoints.sm = e.matches
|
|
|
|
|
})
|
2026-08-03 10:53:12 +08:00
|
|
|
md.addEventListener("change", e => {
|
2026-07-30 13:55:28 +08:00
|
|
|
breakpoints.md = e.matches
|
|
|
|
|
setNavbar(e.matches)
|
|
|
|
|
})
|
2026-08-03 10:53:12 +08:00
|
|
|
lg.addEventListener("change", e => {
|
2026-07-30 13:55:28 +08:00
|
|
|
breakpoints.lg = e.matches
|
|
|
|
|
})
|
2026-08-03 10:53:12 +08:00
|
|
|
xl.addEventListener("change", e => {
|
2026-07-30 13:55:28 +08:00
|
|
|
breakpoints.xl = e.matches
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const html = document.documentElement
|
|
|
|
|
const originalFontSize = html.style.fontSize
|
|
|
|
|
html.style.fontSize = "16px"
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
html.style.fontSize = originalFontSize
|
|
|
|
|
}
|
|
|
|
|
}, [setNavbar])
|
|
|
|
|
|
|
|
|
|
return <>{props.children}</>
|
|
|
|
|
}
|