UNPKG

tdesign-mobile-vue

Version:
119 lines (115 loc) 4.57 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-900db0e1.mjs'; import { defineComponent, ref, computed, onMounted, onUnmounted, createVNode, withDirectives, vShow } from 'vue'; import { useElementBounding } from '@vueuse/core'; import { BacktopIcon } from 'tdesign-icons-vue-next'; import '../shared/index.mjs'; import props from './props.mjs'; import config from '../config.mjs'; import { useTNodeJSX } from '../hooks/tnode.mjs'; import { usePrefixClass } from '../hooks/useClass.mjs'; import getScrollParent from '../_util/getScrollParent.mjs'; import { isBrowser } from '../shared/util.mjs'; import '../_chunks/dep-4915223e.mjs'; import '../shared/functions.mjs'; import '../shared/component.mjs'; import '../shared/render.mjs'; import 'lodash-es'; import '../shared/dom.mjs'; import '../shared/render-tnode.mjs'; import '../shared/useCountDown/index.mjs'; import '../_chunks/dep-99e43b7b.mjs'; import '../_chunks/dep-6b2b02fd.mjs'; import '../shared/useCountDown/utils.mjs'; import '../shared/useTouch/index.mjs'; import '../shared/useScrollParent/index.mjs'; import '../shared/useTest/index.mjs'; import '../shared/useClickAway/index.mjs'; import '../_chunks/dep-fb4113ef.mjs'; import '../_chunks/dep-a953013f.mjs'; import '../shared/hover.mjs'; import '../_chunks/dep-26b97ced.mjs'; import '../config-provider/useConfig.mjs'; 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-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 _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.mjs.map