mirror of https://github.com/vuejs/vitepress
Merge 6c2ac4a70b
into 0048787206
commit
2cae7c9d63
@ -0,0 +1,19 @@
|
|||||||
|
import { reactive } from 'vue'
|
||||||
|
import { clientComputed } from '../support/reactivity'
|
||||||
|
|
||||||
|
export const inertControls = reactive({
|
||||||
|
isScreenOpen: false,
|
||||||
|
isSidebarOpen: false,
|
||||||
|
isSidebarVisible: false
|
||||||
|
})
|
||||||
|
|
||||||
|
export function useInert() {
|
||||||
|
return clientComputed(() => ({
|
||||||
|
skipLink: inertControls.isSidebarOpen || inertControls.isScreenOpen,
|
||||||
|
nav: inertControls.isSidebarOpen,
|
||||||
|
localNav: inertControls.isSidebarOpen || inertControls.isScreenOpen,
|
||||||
|
sidebar: !inertControls.isSidebarVisible || inertControls.isScreenOpen,
|
||||||
|
content: inertControls.isSidebarOpen || inertControls.isScreenOpen,
|
||||||
|
footer: inertControls.isSidebarOpen || inertControls.isScreenOpen
|
||||||
|
}))
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
import {
|
||||||
|
onMounted,
|
||||||
|
shallowReadonly,
|
||||||
|
shallowRef,
|
||||||
|
toValue,
|
||||||
|
watchEffect,
|
||||||
|
type ShallowRef
|
||||||
|
} from 'vue'
|
||||||
|
|
||||||
|
export function clientComputed<T extends {}>(
|
||||||
|
fn: () => T,
|
||||||
|
defaultValue: any = {},
|
||||||
|
options?: { flush?: 'pre' | 'post' | 'sync' }
|
||||||
|
): Readonly<ShallowRef<T>> {
|
||||||
|
const data = shallowRef<T>(toValue(defaultValue))
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
watchEffect(() => {
|
||||||
|
data.value = toValue(fn)
|
||||||
|
}, options)
|
||||||
|
})
|
||||||
|
|
||||||
|
return shallowReadonly(data)
|
||||||
|
}
|
Loading…
Reference in new issue