UNPKG

@ly-js/ui

Version:

`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入

115 lines (112 loc) 3.44 kB
import { defineComponent, ref, computed, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, createBlock, Teleport, createElementVNode, renderSlot } from 'vue'; import { useElementSize } from '@vueuse/core'; import { isDef, addUnit } from '@ly-js/utils'; import { name, fixedWrapProps, bem } from './base.mjs'; const __default__ = { name, inheritAttrs: false }; const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: fixedWrapProps, setup(__props) { const props = __props; const wrapRef = ref(null); const { height: placeholderHeight, width: placeholderWidth } = useElementSize(wrapRef); const wrapStyle = computed(() => { const { direction, top, right, bottom, left } = props; let offset = props.offset; if (offset > 0) { offset = `${offset}px`; } let o = { position: props.position, zIndex: props.zIndex }; switch (direction) { case "top": o.top = offset; if (isDef(left)) { o.left = addUnit(left); } if (isDef(right)) { o.right = addUnit(right); } break; case "right": o.right = offset; if (isDef(top)) { o.top = addUnit(top); } if (isDef(bottom)) { o.bottom = addUnit(bottom); } break; case "bottom": o.bottom = offset; if (isDef(left)) { o.left = addUnit(left); } if (isDef(right)) { o.right = addUnit(right); } break; case "left": o.left = offset; if (isDef(top)) { o.top = addUnit(top); } if (isDef(bottom)) { o.bottom = addUnit(bottom); } break; } if (props.width) { o.width = addUnit(props.width); } if (props.height) { o.height = addUnit(props.height); } return o; }); const safeAreaInsetCss = computed(() => { return `safe-area-inset-${props.direction}`; }); const placeholderStyle = computed(() => { const direction = props.direction; if (direction === "left" || direction === "right") { return { width: placeholderWidth.value + "px" }; } return { height: placeholderHeight.value + "px" }; }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass([unref(bem)()]) }, [ _ctx.placeholder ? (openBlock(), createElementBlock("div", { key: 0, class: normalizeClass([[unref(bem)("placeholder"), unref(safeAreaInsetCss)], "safe-area-inset-bottom"]), style: normalizeStyle(unref(placeholderStyle)) }, null, 6)) : createCommentVNode("v-if", true), (openBlock(), createBlock(Teleport, { to: "body", disabled: !_ctx.appendToBody }, [ createElementVNode("div", { ref_key: "wrapRef", ref: wrapRef, class: normalizeClass([unref(bem)("wrap"), _ctx.wrapClass]), style: normalizeStyle(unref(wrapStyle)) }, [ renderSlot(_ctx.$slots, "default") ], 6) ], 8, ["disabled"])) ], 2); }; } }); export { _sfc_main as default };