tdesign-mobile-vue
Version:
tdesign-mobile-vue
101 lines (97 loc) • 3.53 kB
JavaScript
/**
* tdesign v1.13.2
* (c) 2026 TDesign Group
* @license MIT
*/
import { defineComponent, ref, computed, watch, createVNode } from 'vue';
import { useElementBounding } from '@vueuse/core';
import StickyProps from './props.js';
import config from '../config.js';
import { usePrefixClass } from '../hooks/useClass.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import useElementRect from '../hooks/useElementRect.js';
import '../config-provider/useConfig.js';
import '@babel/runtime/helpers/defineProperty';
import 'lodash-es';
import '../config-provider/context.js';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-4412ff17.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-8e82f508.js';
import 'dayjs';
import '../hooks/render-tnode.js';
import '../_common/js/utils/general.js';
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 containerRef = computed(function () {
return props.container;
});
var _useElementRect = useElementRect(containerRef, {
immediate: true
}),
containerElement = _useElementRect.element,
containerRect = _useElementRect.rect,
updateContainer = _useElementRect.updateElement;
watch(boxTop, function () {
if (containerElement.value) {
updateContainer();
}
});
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 (containerElement.value) {
var containerBottom = containerRect.value.bottom;
var shouldFix = boxTop.value <= offsetTop && containerBottom > 0;
if (shouldFix) {
styleStr += "position:fixed;top:".concat(offsetTop, "px;");
isFixed = true;
}
var difference = containerBottom - offsetTop - height.value;
if (difference < 0) {
styleStr += "transform:translate3d(0, ".concat(difference, "px, 0);");
}
} 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.js.map