UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

212 lines (205 loc) 7.8 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { createElementVNode, openBlock, createElementBlock, defineComponent, ref, onMounted, onBeforeUnmount, computed, createVNode, Fragment, createTextVNode } from 'vue'; import { _ as _defineProperty } from '../_chunks/dep-f9e836af.mjs'; import { _ as _typeof } from '../_chunks/dep-82805301.mjs'; import { scrollTo } from '../utils/dom.mjs'; import '../hooks/index.mjs'; import props from './props.mjs'; import { usePrefixClass } from '../hooks/useConfig.mjs'; import { useConfig } from '../config-provider/useConfig.mjs'; import { useContent } from '../hooks/tnode.mjs'; import { useChildSlots } from '../hooks/slot.mjs'; import '../_chunks/dep-10a947a6.mjs'; import '../_chunks/dep-11fa9c2c.mjs'; import '../_chunks/dep-b75d8d74.mjs'; import '../_chunks/dep-a95026f2.mjs'; import '../_chunks/dep-068e912d.mjs'; import '../_chunks/dep-addc2a84.mjs'; import '../_chunks/dep-1cc1c24f.mjs'; import '../_chunks/dep-6ad18815.mjs'; import '../utils/easing.mjs'; import '../hooks/icon.mjs'; import '../hooks/useCommonClassName.mjs'; import '../hooks/useDefaultValue.mjs'; import '../_chunks/dep-ae4bffa5.mjs'; import '../_chunks/dep-8db27830.mjs'; import '../_chunks/dep-4903a8a8.mjs'; import '../_chunks/dep-7dcfa37a.mjs'; import '../hooks/useDestroyOnClose.mjs'; import '../hooks/useKeepAnimation.mjs'; import '../_chunks/dep-b09f48fa.mjs'; import '../_chunks/dep-81c83986.mjs'; import '../_chunks/dep-6aa0223b.mjs'; import '../_chunks/dep-db381ece.mjs'; import '../_chunks/dep-5755c21c.mjs'; import '../_chunks/dep-7f239c43.mjs'; import '../_chunks/dep-6f04869e.mjs'; import '../_chunks/dep-d32fbbb3.mjs'; import '../_chunks/dep-dafada74.mjs'; import '../_chunks/dep-6e7b37b8.mjs'; import '../_chunks/dep-e1ab85c5.mjs'; import '../_chunks/dep-5f0e0453.mjs'; import '../_chunks/dep-71f84cf2.mjs'; import '../_chunks/dep-0e832fc7.mjs'; import '../_chunks/dep-26bf361a.mjs'; import '../_chunks/dep-3ec3335a.mjs'; import '../_chunks/dep-ed4e7c50.mjs'; import '../_chunks/dep-a666b9ad.mjs'; import '../_common/js/global-config/default-config.mjs'; import '../_common/js/global-config/locale/en_US.mjs'; import '../hooks/useRipple.mjs'; import '../utils/set-style.mjs'; import '../hooks/useVirtualScroll.mjs'; import '../hooks/useVModel.mjs'; import '../hooks/useImagePreviewUrl.mjs'; import '../_chunks/dep-32d4c595.mjs'; import '../_chunks/dep-89b966f4.mjs'; import '../_common/js/upload/utils.mjs'; import '../_common/js/log/log.mjs'; import '../_chunks/dep-91ac8f71.mjs'; import '../_chunks/dep-c4737535.mjs'; import '../_chunks/dep-69963a8c.mjs'; import '../_chunks/dep-8d1c9a23.mjs'; import '../_chunks/dep-03412fab.mjs'; import '../_chunks/dep-205ff58d.mjs'; import '../config-provider/type.mjs'; import '../_chunks/dep-a628549d.mjs'; import '../_chunks/dep-f4eba04c.mjs'; import '../_chunks/dep-735bcd0d.mjs'; import '../_chunks/dep-765678ef.mjs'; import '../utils/render-tnode.mjs'; import '../_chunks/dep-9d7ebc32.mjs'; const _hoisted_1 = { class: "x-icon", viewBox: "0 0 24 24", width: "1.1em", height: "1.1em" }; const _hoisted_2 = /*#__PURE__*/createElementVNode("path", { fill: "currentColor", d: "m12 13.914l4.793 4.793l1.414-1.414L12 11.086l-6.207 6.207l1.414 1.414L12 13.914ZM6 7h12v2H6V7Z" }, null, -1 /* HOISTED */); const _hoisted_3 = [ _hoisted_2 ]; function render(_ctx, _cache) { return (openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_3)) } var __unplugin_components_0 = { name: 'ri-skip-up-line', render }; /* vite-plugin-components disabled */ var _BackTop = defineComponent({ name: "XBackTop", props: props, setup: function setup(props2) { var visible = ref(false); var containerRef = ref(null); var componentName = usePrefixClass("back-top"); var _useConfig = useConfig("alert"), classPrefix = _useConfig.classPrefix; var renderContent = useContent(); var getContainer = function getContainer(container) { if (typeof container === "string" && (typeof document === "undefined" ? "undefined" : _typeof(document)) !== void 0) { if (container === "body") { return document; } return document.querySelector(container); } if (typeof container === "function") { return container(); } return null; }; onMounted(function () { containerRef.value = getContainer(props2.container); var visibleHeight; if (typeof props2.visibleHeight === "string") { visibleHeight = Number(props2.visibleHeight.replace("px", "")); } else { visibleHeight = props2.visibleHeight; } if (visibleHeight === 0) { visible.value = true; return; } var scrollDOM; if (containerRef.value.scrollTop === void 0) { scrollDOM = document.documentElement; } else { scrollDOM = containerRef.value; } containerRef.value.onscroll = function () { var _scrollDOM; var scrollTop = (_scrollDOM = scrollDOM) === null || _scrollDOM === void 0 ? void 0 : _scrollDOM.scrollTop; if (scrollTop >= visibleHeight) { visible.value = true; } if (scrollTop < visibleHeight && visible.value) { visible.value = false; } }; }); onBeforeUnmount(function () { containerRef.value.onscroll = null; }); return function () { var theme = props2.theme, shape = props2.shape, size = props2.size, target = props2.target, duration = props2.duration, offset = props2.offset, container = props2.container; var getChild = useChildSlots(); var children = getChild(); if (children.length < 1) children = null; var cls = computed(function () { var _ref; return _ref = {}, _defineProperty(_ref, componentName.value, true), _defineProperty(_ref, "".concat(componentName.value, "--theme-").concat(theme), true), _defineProperty(_ref, "".concat(componentName.value, "--").concat(shape), true), _defineProperty(_ref, "".concat(componentName.value, "--show"), visible.value), _defineProperty(_ref, "".concat(classPrefix.value, "-size-s"), size === "small"), _defineProperty(_ref, "".concat(classPrefix.value, "-size-m"), size === "medium"), _ref; }); var defaultContent = createVNode(Fragment, null, [createVNode(__unplugin_components_0, { "class": "".concat(componentName.value, "__icon"), "style": "font-size: 2.2em;" }, null), createVNode("span", { "class": "".concat(componentName.value, "__text") }, [createTextVNode("TOP")])]); var getBackTo = function getBackTo() { if (target === container) return 0; if (target === "body") return 0; if (!target) return 0; var targetNode = getContainer(target); if (!targetNode) return 0; var y = targetNode.getBoundingClientRect().y; return y; }; var handleClick = function handleClick(e) { var _props2$onClick; var y = getBackTo(); scrollTo(y, { container: containerRef.value, duration: duration }); (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, { e: e }); }; var positionStyle = computed(function () { return { insetInlineEnd: offset[0], insetBlockEnd: offset[1] }; }); return createVNode("button", { "type": "button", "class": cls.value, "style": positionStyle.value, "onClick": handleClick }, [renderContent("content", "default", defaultContent)]); }; } }); export { _BackTop as default }; //# sourceMappingURL=back-top.mjs.map