UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

52 lines (51 loc) 1.91 kB
/*! * KoliBri - The accessible HTML-Standard */ import { isInitialized } from "../../core/bootstrap"; import { KolToastContainerTag } from "../../core/component-names"; import { Log } from "../../schema"; export class ToasterService { constructor(document, options) { var _a; this.document = document; this.options = options; this.toastContainerElement = this.document.createElement(KolToastContainerTag); this.document.body.prepend(this.toastContainerElement); if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.defaultVariant) { Log.info(`ToasterService: Default variant is deprecated. Use 'card' variant for all toasts instead.`); } } static getInstance(document, options) { if (!isInitialized()) { throw new Error('Toaster: Call KoliBri bootstrap/register method first.'); } let instance = this.instances.get(document); if (!instance) { instance = new ToasterService(document, options); this.instances.set(document, instance); } return instance; } dispose() { const element = this.toastContainerElement; if (element) { this.toastContainerElement = undefined; element.remove(); } else { Log.warn('Toaster service is already disposed.'); } } enqueue(toast) { if (this.toastContainerElement && typeof this.toastContainerElement.enqueue === 'function') { return this.toastContainerElement.enqueue(toast); } } closeAll(immediate = false) { if (this.toastContainerElement && typeof this.toastContainerElement.closeAll === 'function') { void this.toastContainerElement.closeAll(immediate); } } } ToasterService.instances = new Map(); //# sourceMappingURL=toaster.js.map