tdesign-mobile-vue
Version:
tdesign-mobile-vue
101 lines (97 loc) • 3.88 kB
JavaScript
/**
* tdesign v1.9.3
* (c) 2025 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, onMounted, onUnmounted, withDirectives, createVNode, vShow } from 'vue';
import { useElementBounding } from '@vueuse/core';
import { BacktopIcon } from 'tdesign-icons-vue-next';
import props from './props.js';
import config from '../config.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useClass.js';
import getScrollParent from '../_util/getScrollParent.js';
import { isBrowser } from '../shared/util.js';
import 'lodash-es';
import '../hooks/render-tnode.js';
import '../_common/js/utils/general.js';
import '../config-provider/useConfig.js';
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-f785f3d3.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-0d44b254.js';
import 'dayjs';
import '@babel/runtime/helpers/slicedToArray';
var prefix = config.prefix;
var _BackTop = defineComponent({
name: "".concat(prefix, "-back-top"),
props: props,
setup: function setup(props2) {
var renderTNodeJSX = useTNodeJSX();
var backTopClass = usePrefixClass("back-top");
var root = ref();
var target = computed(function () {
if (!isBrowser) return void 0;
return props2.target ? props2.target() : window.document.documentElement;
});
var container = ref();
var _useElementBounding = useElementBounding(target),
top = _useElementBounding.top;
var visible = ref(false);
var backTopClasses = computed(function () {
return _defineProperty(_defineProperty(_defineProperty({}, "".concat(backTopClass.value), true), "".concat(backTopClass.value, "--fixed"), props2.fixed), "".concat(backTopClass.value, "--").concat(props2.theme), true);
});
var handleClick = function handleClick() {
if (isBrowser) {
var _props2$onToTop;
container.value.scrollTop = 0 + top.value;
(_props2$onToTop = props2.onToTop) === null || _props2$onToTop === void 0 || _props2$onToTop.call(props2);
}
};
var getContainer = function getContainer(container2) {
if (typeof container2 === "function") {
return container2();
}
return getScrollParent(root.value, document.documentElement);
};
onMounted(function () {
if (isBrowser) {
container.value = getContainer(props2.container);
container.value.onscroll = function () {
var _container$value, _container$value2;
if (((_container$value = container.value) === null || _container$value === void 0 ? void 0 : _container$value.scrollTop) >= props2.visibilityHeight) {
visible.value = true;
}
if (visible.value && ((_container$value2 = container.value) === null || _container$value2 === void 0 ? void 0 : _container$value2.scrollTop) < props2.visibilityHeight) {
visible.value = false;
}
};
}
});
onUnmounted(function () {
container.value.onscroll = null;
});
var readerIcon = function readerIcon() {
if (props2.icon === true) {
return createVNode(BacktopIcon, {
"size": "22px"
}, null);
}
return renderTNodeJSX("icon");
};
return function () {
return withDirectives(createVNode("div", {
"class": backTopClasses.value,
"ref": root,
"onClick": handleClick
}, [readerIcon(), props2.text && createVNode("span", {
"class": "".concat(backTopClass.value, "__text--").concat(props2.theme)
}, [props2.text])]), [[vShow, visible.value]]);
};
}
});
export { _BackTop as default };
//# sourceMappingURL=back-top.js.map