tdesign-mobile-vue
Version:
tdesign-mobile-vue
97 lines (93 loc) • 3.48 kB
JavaScript
/**
* tdesign v1.9.3
* (c) 2025 TDesign Group
* @license MIT
*/
import { defineComponent, ref, computed, watch, createVNode } from 'vue';
import { useElementBounding } from '@vueuse/core';
import StickyProps from './props.mjs';
import config from '../config.mjs';
import { usePrefixClass } from '../hooks/useClass.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-900db0e1.mjs';
import '../_chunks/dep-4915223e.mjs';
import 'lodash-es';
import '../config-provider/context.mjs';
import '../_common/js/global-config/mobile/default-config.mjs';
import '../_common/js/global-config/mobile/locale/zh_CN.mjs';
import '../_chunks/dep-bca0f578.mjs';
import '../_chunks/dep-6b2b02fd.mjs';
import '../_chunks/dep-c6f44a15.mjs';
import '../_chunks/dep-c984d53e.mjs';
import '../config-provider/type.mjs';
import '../hooks/render-tnode.mjs';
import '../_common/js/utils/general.mjs';
var prefix = config.prefix;
var _Sticky = defineComponent({
name: "".concat(prefix, "-sticky"),
props: StickyProps,
setup: function setup(props) {
var renderTNodeJSX = useTNodeJSX();
var stickyBarClass = usePrefixClass("sticky");
var boxRef = ref();
var _useElementBounding = useElementBounding(boxRef),
boxTop = _useElementBounding.top;
var contentRef = ref();
var _useElementBounding2 = useElementBounding(contentRef),
contentTop = _useElementBounding2.top,
height = _useElementBounding2.height;
var stickyStyle = computed(function () {
return "height:".concat(height.value, "px;");
});
var container;
var containerHeight = ref(0);
var containerTop = ref(0);
watch(boxTop, function () {
if (props.container) {
container = document.querySelector(props.container);
var _container$getBoundin = container.getBoundingClientRect(),
top = _container$getBoundin.top,
height2 = _container$getBoundin.height;
containerHeight.value = height2;
containerTop.value = top;
}
});
var contentStyles = computed(function () {
var _props$onScroll;
var styleStr = "z-index:".concat(props.zIndex, ";");
var isFixed = false;
if (props.disabled) return styleStr;
var offsetTop = Number(props.offsetTop);
if (container) {
if (containerHeight.value + containerTop.value < offsetTop + height.value) {
styleStr += "transform:translate3d(0, ".concat(containerHeight.value - height.value, "px, 0);");
} else if (boxTop.value <= offsetTop) {
styleStr += "position:fixed;top:".concat(offsetTop, "px;");
isFixed = true;
}
} else if (boxTop.value <= offsetTop) {
styleStr += "position:fixed;top:".concat(offsetTop, "px;");
isFixed = true;
}
(_props$onScroll = props.onScroll) === null || _props$onScroll === void 0 || _props$onScroll.call(props, {
scrollTop: contentTop.value,
isFixed: isFixed
});
return styleStr;
});
return function () {
return createVNode("div", {
"ref": boxRef,
"class": stickyBarClass.value,
"style": stickyStyle.value
}, [createVNode("div", {
"ref": contentRef,
"class": "".concat(stickyBarClass.value, "__content"),
"style": contentStyles.value
}, [renderTNodeJSX("default")])]);
};
}
});
export { _Sticky as default };
//# sourceMappingURL=sticky.mjs.map