tdesign-mobile-vue
Version:
tdesign-mobile-vue
107 lines (101 loc) • 3.74 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
var sticky_props = require('./props.js');
var config = require('../config.js');
var hooks_useClass = require('../hooks/useClass.js');
var hooks_tnode = require('../hooks/tnode.js');
require('../config-provider/useConfig.js');
require('@babel/runtime/helpers/defineProperty');
require('lodash/isFunction');
require('lodash/cloneDeep');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/mobile/default-config.js');
require('../_common/js/global-config/mobile/locale/zh_CN.js');
require('../_chunks/dep-8d930798.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-a20a5149.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
var prefix = config["default"].prefix;
var _Sticky = vue.defineComponent({
name: "".concat(prefix, "-sticky"),
props: sticky_props["default"],
setup: function setup(props) {
var renderTNodeJSX = hooks_tnode.useTNodeJSX();
var stickyBarClass = hooks_useClass.usePrefixClass("sticky");
var boxRef = vue.ref();
var _useElementBounding = core.useElementBounding(boxRef),
boxTop = _useElementBounding.top;
var contentRef = vue.ref();
var _useElementBounding2 = core.useElementBounding(contentRef),
contentTop = _useElementBounding2.top,
height = _useElementBounding2.height;
var stickyStyle = vue.computed(function () {
return "height:".concat(height.value, "px;");
});
var container;
var containerHeight = vue.ref(0);
var containerTop = vue.ref(0);
vue.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 = vue.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 vue.createVNode("div", {
"ref": boxRef,
"class": stickyBarClass.value,
"style": stickyStyle.value
}, [vue.createVNode("div", {
"ref": contentRef,
"class": "".concat(stickyBarClass.value, "__content"),
"style": contentStyles.value
}, [renderTNodeJSX("default")])]);
};
}
});
exports["default"] = _Sticky;
//# sourceMappingURL=sticky.js.map