UNPKG

@oiij/naive-ui

Version:

Some Composable Functions And Components for Vue 3

79 lines (77 loc) 2.82 kB
import BaseTransition_default from "../transition/BaseTransition.js"; import "../transition/index.js"; import { cName, loadingProviderCssr } from "./loading-provider.cssr.js"; import { loadingProviderInjectionKey } from "./index.js"; import { Fragment, Teleport, createBlock, createCommentVNode, createElementBlock, createSlots, createVNode, defineComponent, mergeProps, normalizeClass, normalizeStyle, openBlock, provide, ref, renderSlot, unref, watchEffect, withCtx } from "vue"; import { useStyle } from "@oiij/css-render"; import { NEl, NSpin } from "naive-ui"; //#region src/components/loading-provider/LoadingProvider.vue const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "LoadingProvider", props: { show: { type: Boolean }, appendTo: { default: "body" }, mask: { type: [Boolean, Object], default: true }, blur: { type: Boolean, default: true }, duration: {}, spinProps: {} }, setup(__props) { useStyle(cName, loadingProviderCssr()); const _show = ref(__props.show); watchEffect(() => { _show.value = __props.show; }); const textRef = ref(""); function hideLoading() { _show.value = false; } function showLoading(options) { const { text, duration: _duration } = options ?? {}; textRef.value = text ?? ""; _show.value = true; if (_duration ?? __props.duration) setTimeout(() => { _show.value = false; }, _duration ?? __props.duration); return { hide: hideLoading }; } provide(loadingProviderInjectionKey, { show: showLoading, hide: hideLoading }); return (_ctx, _cache) => { return openBlock(), createElementBlock(Fragment, null, [createVNode(unref(BaseTransition_default), null, { default: withCtx(() => [(openBlock(), createBlock(Teleport, { to: __props.appendTo }, [_show.value ? (openBlock(), createBlock(unref(NEl), { key: 0, class: normalizeClass([ unref(cName), { [`${unref(cName)}--mask`]: __props.mask }, { [`${unref(cName)}--blur`]: __props.blur } ]), style: normalizeStyle(typeof __props.mask === "object" ? __props.mask : {}) }, { default: withCtx(() => [createVNode(unref(NSpin), mergeProps({ description: textRef.value }, __props.spinProps), createSlots({ _: 2 }, [_ctx.$slots.description ? { name: "description", fn: withCtx(() => [renderSlot(_ctx.$slots, "description")]), key: "0" } : void 0, _ctx.$slots.icon ? { name: "icon", fn: withCtx(() => [renderSlot(_ctx.$slots, "icon")]), key: "1" } : void 0]), 1040, ["description"])]), _: 3 }, 8, ["class", "style"])) : createCommentVNode("v-if", true)], 8, ["to"]))]), _: 3 }), renderSlot(_ctx.$slots, "default")], 64); }; } }); var LoadingProvider_default = _sfc_main; //#endregion export { LoadingProvider_default as default };