UNPKG

@vuesax-alpha/nightly

Version:
56 lines (53 loc) 1.86 kB
import { isVNode, createVNode, render } from 'vue'; import '../../../utils/index.mjs'; import '../../../hooks/index.mjs'; import NotificationConstructor from './notification2.mjs'; import { useNotificationContainerId } from './use-notification.mjs'; import { isClient } from '@vueuse/core'; import { createContainer } from '../../../hooks/use-popper-container/index.mjs'; import { useGlobalComponentSettings } from '../../../hooks/use-global-config/index.mjs'; import { isObject } from '@vue/shared'; const globalContainer = { "top-right": null, "top-center": null, "top-left": null, "bottom-right": null, "bottom-center": null, "bottom-left": null }; const notification = (options = {}) => { var _a, _b; if (!isClient) return { close: () => void 0 }; if (typeof options === "string" || isVNode(options)) { options = { content: options }; } const position = options.position || "bottom-right"; const { id, selector } = useNotificationContainerId(); if (!globalContainer[position] && !document.body.querySelector(selector.value)) { globalContainer[position] = createContainer(`${id.value}-${position}`); const { ns } = useGlobalComponentSettings("notification"); (_a = globalContainer[position]) == null ? void 0 : _a.classList.add(ns.is(position)); } const vm = createVNode( NotificationConstructor, { ...options, position }, isVNode(options.content) ? { default: () => isObject(options) ? options.content : null } : null ); const container = document.createElement("div"); render(vm, container); (_b = globalContainer[position]) == null ? void 0 : _b.appendChild(container.firstChild); const close = () => { ; vm.component.exposed.close(); }; return { close }; }; export { notification as default, notification }; //# sourceMappingURL=notify.mjs.map