27 lines
690 B
TypeScript
27 lines
690 B
TypeScript
import { useMediaQuery } from '@vueuse/core'
|
|||
|
|
import { onUnmounted, watch } from 'vue'
|
||
|
|
import { DESKTOP_LAYOUT_MIN_WIDTH } from '../constants'
|
||
|
|
|
||
|
|
const DESKTOP_LAYOUT_CLASS = 'app-layout--desktop'
|
||
|
|
|
||
|
|
export function useDesktopBreakpoint() {
|
||
|
|
return useMediaQuery(`(min-width: ${DESKTOP_LAYOUT_MIN_WIDTH}px)`)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useApplyDesktopLayoutClass() {
|
||
|
|
const isDesktopLayout = useDesktopBreakpoint()
|
||
|
|
|
||
|
|
const stop = watch(
|
||
|
|
isDesktopLayout,
|
||
|
|
(desktop) => {
|
||
|
|
document.documentElement.classList.toggle(DESKTOP_LAYOUT_CLASS, desktop)
|
||
|
|
},
|
||
|
|
{ immediate: true }
|
||
|
|
)
|
||
|
|
|
||
|
|
onUnmounted(() => {
|
||
|
|
stop()
|
||
|
|
document.documentElement.classList.remove(DESKTOP_LAYOUT_CLASS)
|
||
|
|
})
|
||
|
|
}
|