UNPKG

react-atom-toast

Version:
53 lines (50 loc) 1.37 kB
import { __publicField } from './chunk-5USKE2QT.js'; import ToastContainer from './components/toast-container.js'; import { mount } from './dom.js'; import { isBrowser } from './utils.js'; import { jsx } from 'react/jsx-runtime'; var Renderer = class { constructor(queue) { __publicField(this, "containerID", "react-atom-toast"); __publicField(this, "container", null); __publicField(this, "queue"); this.queue = queue; } createContainer() { if (isBrowser()) { let container = document.getElementById(this.containerID); if (!container) { container = document.createElement("div"); container.id = this.containerID; document.body.appendChild(container); } this.container = container; } } render(toasts) { if (!toasts.length && this.container) { this.container.remove(); this.container = null; return; } this.createContainer(); if (!this.container) return; this.reactMount(toasts, this.container); } reactMount(toasts, container) { mount( /* @__PURE__ */ jsx( ToastContainer, { toasts, onClosed: (key) => this.queue.remove(key), onOpenChange: (key, open) => { this.queue.update(key, { open }); } } ), container ); } }; export { Renderer };