UNPKG

tdesign-mobile-vue

Version:
133 lines (129 loc) 4.96 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed, ref, onMounted, onUnmounted, createVNode, withDirectives, vShow } from 'vue'; import { useElementBounding } from '@vueuse/core'; import { BacktopIcon } from 'tdesign-icons-vue-next'; import '../shared/index.js'; import props from './props.js'; import config from '../config.js'; import { useTNodeJSX } from '../hooks/tnode.js'; import { usePrefixClass } from '../hooks/useClass.js'; import { isBrowser } from '../shared/util.js'; import '../shared/functions.js'; import '../shared/component.js'; import '../shared/constants.js'; import '../shared/render.js'; import '@babel/runtime/helpers/typeof'; import 'lodash/camelCase'; import '../shared/dom.js'; import 'lodash/isFunction'; import 'lodash/isString'; import '../shared/render-tnode.js'; import '../shared/useToggle/index.js'; import '../shared/useCountDown/index.js'; import '@babel/runtime/helpers/asyncToGenerator'; import '@babel/runtime/regenerator'; import '../shared/useCountDown/utils.js'; import '../shared/useDefault/index.js'; import '../shared/useChildSlots/index.js'; import '@babel/runtime/helpers/toConsumableArray'; import '../shared/useVModel/index.js'; import 'lodash/kebabCase'; import '../shared/useTouch/index.js'; import '../shared/useScrollParent/index.js'; import '../shared/useExpose/index.js'; import '../shared/useTest/index.js'; import '../shared/useClickAway/index.js'; import 'lodash/isArray'; import '../shared/useGesture/index.js'; import '@babel/runtime/helpers/slicedToArray'; import '@use-gesture/vanilla'; import '../shared/hover.js'; import 'lodash/isNumber'; import '../hooks/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isObject'; import '../config-provider/useConfig.js'; import 'lodash/cloneDeep'; import '../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../_common/js/global-config/mobile/default-config.js'; import '../_common/js/global-config/mobile/locale/zh_CN.js'; import '../_chunks/dep-6c582337.js'; import '../_chunks/dep-38637d40.js'; import 'dayjs'; import '../_chunks/dep-959cdc59.js'; import '../config-provider/type.js'; 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 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 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, "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