@ly-js/ui
Version:
`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入
119 lines (114 loc) • 3.54 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
var utils = require('@ly-js/utils');
var base = require('./base.js');
const __default__ = {
name: base.name,
inheritAttrs: false
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: base.fixedWrapProps,
setup(__props) {
const props = __props;
const wrapRef = vue.ref(null);
const { height: placeholderHeight, width: placeholderWidth } = core.useElementSize(wrapRef);
const wrapStyle = vue.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 (utils.isDef(left)) {
o.left = utils.addUnit(left);
}
if (utils.isDef(right)) {
o.right = utils.addUnit(right);
}
break;
case "right":
o.right = offset;
if (utils.isDef(top)) {
o.top = utils.addUnit(top);
}
if (utils.isDef(bottom)) {
o.bottom = utils.addUnit(bottom);
}
break;
case "bottom":
o.bottom = offset;
if (utils.isDef(left)) {
o.left = utils.addUnit(left);
}
if (utils.isDef(right)) {
o.right = utils.addUnit(right);
}
break;
case "left":
o.left = offset;
if (utils.isDef(top)) {
o.top = utils.addUnit(top);
}
if (utils.isDef(bottom)) {
o.bottom = utils.addUnit(bottom);
}
break;
}
if (props.width) {
o.width = utils.addUnit(props.width);
}
if (props.height) {
o.height = utils.addUnit(props.height);
}
return o;
});
const safeAreaInsetCss = vue.computed(() => {
return `safe-area-inset-${props.direction}`;
});
const placeholderStyle = vue.computed(() => {
const direction = props.direction;
if (direction === "left" || direction === "right") {
return {
width: placeholderWidth.value + "px"
};
}
return {
height: placeholderHeight.value + "px"
};
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass([vue.unref(base.bem)()])
}, [
_ctx.placeholder ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: vue.normalizeClass([[vue.unref(base.bem)("placeholder"), vue.unref(safeAreaInsetCss)], "safe-area-inset-bottom"]),
style: vue.normalizeStyle(vue.unref(placeholderStyle))
}, null, 6)) : vue.createCommentVNode("v-if", true),
(vue.openBlock(), vue.createBlock(vue.Teleport, {
to: "body",
disabled: !_ctx.appendToBody
}, [
vue.createElementVNode("div", {
ref_key: "wrapRef",
ref: wrapRef,
class: vue.normalizeClass([vue.unref(base.bem)("wrap"), _ctx.wrapClass]),
style: vue.normalizeStyle(vue.unref(wrapStyle))
}, [
vue.renderSlot(_ctx.$slots, "default")
], 6)
], 8, ["disabled"]))
], 2);
};
}
});
exports["default"] = _sfc_main;