ray-template/packages/admin-shell/src/layout-css-vars.ts
XiaoDaiGua-Ray 403fdd589a feat!: rebuild Ray Template as a monorepo
Share workspace packages between Ray Admin and the interactive docs.

BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
2026-11-04 14:01:28 +08:00

34 lines
1.2 KiB
TypeScript

import { useElementBounding } from '@vueuse/core'
import { computed } from 'vue'
import type { Ref } from 'vue'
/**
*
* @description
* 动态获取 SiderBar 和 MenuTag 高度,用于 LayoutContent 高度实时获取与渲染;
* 可以动态更改 MenuTag 样式后,使得 LayoutContent 也可以准确的获取高度。
*/
export const layoutCssVars = (
element: [
Ref<HTMLElement | undefined>,
Ref<HTMLElement | undefined>,
Ref<HTMLElement | undefined>,
],
) => {
const siderBar = useElementBounding(element[0])
const menuTag = useElementBounding(element[1])
const footer = useElementBounding(element[2])
return computed(() => {
return {
'--window-width': 'var(--html-width, 100vw)',
'--window-height': 'var(--html-height, 100dvh)',
'--layout-content-height': `calc(var(--html-height, 100dvh) - ${siderBar.height.value}px - ${menuTag.height.value}px - ${footer.height.value}px)`,
'--layout-content-width': `${siderBar.width.value}px`,
'--layout-siderbar-height': `${siderBar.height.value}px`,
'--layout-menutag-height': `${menuTag.height.value}px`,
'--layout-footer-height': `${footer.height.value}px`,
}
})
}