@nuralyui/toast 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuralyui/toast",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Toast notification component for NuralyUI library",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -5,8 +5,6 @@
5
5
  */
6
6
  import { LitElement } from 'lit';
7
7
  import { ToastPosition, ToastAnimation, ToastConfig } from './toast.types.js';
8
- import '../icon/icon.component.js';
9
- import '../button/index.js';
10
8
  declare const NrToastElement_base: (new (...args: any[]) => import("@nuralyui/common/mixins").DependencyAware) & (new (...args: any[]) => import("@nuralyui/common/mixins").ThemeAware) & (new (...args: any[]) => import("@nuralyui/common/mixins").EventHandlerCapable) & typeof LitElement;
11
9
  /**
12
10
  * Toast notification component for displaying temporary messages.
@@ -17,8 +17,6 @@ import { styles } from './toast.style.js';
17
17
  import { NuralyUIBaseMixin } from '@nuralyui/common/mixins';
18
18
  import { DEFAULT_TOAST_DURATION, DEFAULT_MAX_TOASTS, EMPTY_STRING } from './toast.types.js';
19
19
  // Import required components
20
- import '../icon/icon.component.js';
21
- import '../button/index.js';
22
20
  /**
23
21
  * Toast notification component for displaying temporary messages.
24
22
  *
@@ -1 +1 @@
1
- {"version":3,"file":"toast.component.js","sourceRoot":"","sources":["../../../src/components/toast/toast.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,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;;YAExB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA,kCAAkC,MAAM,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,OAAO;YACtF,MAAM,CAAC,KAAK;;;KAGnB,CAAC;IACJ,CAAC;CACF,CAAA;AA5SiB,qBAAM,GAAG,MAAO,CAAA;AAMhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDACO;AAIjD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACI;AAI/B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDACc;AAIzC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACqB;AAIhD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;6CACf;AAIb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDACT;AAInB;IADC,KAAK,EAAE;8CACyB;AA/BtB,cAAc;IAD1B,aAAa,CAAC,UAAU,CAAC;GACb,cAAc,CA6S1B;SA7SY,cAAc","sourcesContent":["/**\n * @license\n * Copyright 2023 Nuraly, Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { LitElement, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styles } from './toast.style.js';\nimport { NuralyUIBaseMixin } from '@nuralyui/common/mixins';\nimport {\n ToastType,\n ToastPosition,\n ToastAnimation,\n ToastConfig,\n ToastItem,\n ToastEventDetail,\n ToastButton,\n DEFAULT_TOAST_DURATION,\n DEFAULT_MAX_TOASTS,\n EMPTY_STRING\n} from './toast.types.js';\n\n// Import required components\nimport '../icon/icon.component.js';\nimport '../button/index.js';\n\n/**\n * Toast notification component for displaying temporary messages.\n * \n * Provides a flexible notification system with multiple types, positions, and animations.\n * Supports stacking multiple toasts, auto-dismiss (enabled by default), action buttons, \n * custom HTML content, and manual closing.\n * \n * @example\n * ```html\n * <!-- Basic usage with auto-dismiss -->\n * <nr-toast position=\"top-right\"></nr-toast>\n * \n * <!-- Disable auto-dismiss to require manual closing -->\n * <nr-toast position=\"top-right\" auto-dismiss=\"false\"></nr-toast>\n * \n * <!-- Programmatic usage -->\n * <script>\n * const toast = document.querySelector('nr-toast');\n * toast.show({ text: 'Success!', type: 'success' });\n * toast.show({ text: 'Error occurred', type: 'error', duration: 7000 });\n * \n * // Disable auto-dismiss for specific toast\n * toast.show({ text: 'Persistent message', autoDismiss: false });\n * \n * // Toast with action button\n * toast.show({\n * text: 'Item deleted',\n * type: 'success',\n * button: {\n * label: 'Undo',\n * onClick: () => console.log('Undo clicked'),\n * type: 'primary'\n * }\n * });\n * \n * // Custom HTML content (GDPR consent example)\n * toast.show({\n * content: html`\n * <div>\n * <h4>Cookie Consent</h4>\n * <p>We use cookies to improve your experience.</p>\n * <div style=\"display: flex; gap: 0.5rem; margin-top: 0.5rem;\">\n * <nr-button size=\"small\" type=\"primary\">Accept</nr-button>\n * <nr-button size=\"small\" type=\"secondary\">Decline</nr-button>\n * </div>\n * </div>\n * `,\n * autoDismiss: false,\n * closable: true\n * });\n * </script>\n * ```\n * \n * @fires nr-toast-show - Toast shown\n * @fires nr-toast-close - Toast closed\n * @fires nr-toast-click - Toast clicked\n * \n * @cssproperty --nuraly-z-index-toast - Toast z-index\n * @cssproperty --nuraly-toast-default-background - Default toast background\n * @cssproperty --nuraly-toast-success-background - Success toast background\n * @cssproperty --nuraly-toast-error-background - Error toast background\n * @cssproperty --nuraly-toast-warning-background - Warning toast background\n * @cssproperty --nuraly-toast-info-background - Info toast background\n */\n@customElement('nr-toast')\nexport class NrToastElement extends NuralyUIBaseMixin(LitElement) {\n static override styles = styles;\n\n override requiredComponents = ['nr-icon', 'nr-button'];\n\n /** Position of toast container on screen */\n @property({ type: String, reflect: true })\n position: ToastPosition = ToastPosition.TopRight;\n\n /** Maximum number of toasts to display */\n @property({ type: Number })\n maxToasts = DEFAULT_MAX_TOASTS;\n\n /** Default duration for toasts in milliseconds */\n @property({ type: Number })\n defaultDuration = DEFAULT_TOAST_DURATION;\n\n /** Animation type for toasts */\n @property({ type: String })\n animation: ToastAnimation = ToastAnimation.Fade;\n\n /** Whether to stack toasts or replace */\n @property({ type: Boolean })\n stack = true;\n\n /** Auto dismiss toasts after duration (default: true) */\n @property({ type: Boolean })\n autoDismiss = true;\n\n /** Internal state: active toasts */\n @state()\n private toasts: ToastItem[] = [];\n\n /** Timeout map for auto-dismiss */\n private timeouts = new Map<string, number>();\n\n /**\n * Show a new toast notification\n * @param config - Toast configuration\n * @returns Toast ID for manual control\n */\n show(config: string | ToastConfig): string {\n const toastConfig: ToastConfig = typeof config === 'string' \n ? { text: config }\n : config;\n\n const toast: ToastItem = {\n id: this.generateId(),\n timestamp: Date.now(),\n text: toastConfig.text,\n content: toastConfig.content,\n type: toastConfig.type || ToastType.Default,\n duration: toastConfig.duration ?? this.defaultDuration,\n autoDismiss: toastConfig.autoDismiss ?? this.autoDismiss,\n closable: toastConfig.closable ?? true,\n icon: toastConfig.icon || this.getDefaultIcon(toastConfig.type),\n customClass: toastConfig.customClass,\n button: toastConfig.button,\n onClose: toastConfig.onClose,\n onClick: toastConfig.onClick,\n };\n\n // Handle max toasts\n if (!this.stack) {\n this.clearAll();\n } else if (this.toasts.length >= this.maxToasts) {\n this.removeToast(this.toasts[0].id);\n }\n\n // Add toast\n this.toasts = [...this.toasts, toast];\n\n // Emit show event\n this.emitToastEvent('nr-toast-show', toast, 'show');\n\n // Set auto-dismiss timeout\n if (toast.autoDismiss && toast.duration && toast.duration > 0) {\n const timeoutId = window.setTimeout(() => {\n this.removeToast(toast.id);\n }, toast.duration);\n this.timeouts.set(toast.id, timeoutId);\n }\n\n return toast.id;\n }\n\n /**\n * Show success toast\n */\n success(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Success, duration });\n }\n\n /**\n * Show error toast\n */\n error(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Error, duration });\n }\n\n /**\n * Show warning toast\n */\n warning(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Warning, duration });\n }\n\n /**\n * Show info toast\n */\n info(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Info, duration });\n }\n\n /**\n * Remove a specific toast\n */\n removeToast(id: string): void {\n const toast = this.toasts.find(t => t.id === id);\n if (!toast) return;\n\n // Mark as removing for animation\n toast.removing = true;\n this.requestUpdate();\n\n // Clear timeout\n const timeoutId = this.timeouts.get(id);\n if (timeoutId) {\n clearTimeout(timeoutId);\n this.timeouts.delete(id);\n }\n\n // Remove after animation\n setTimeout(() => {\n this.toasts = this.toasts.filter(t => t.id !== id);\n \n // Emit close event\n this.emitToastEvent('nr-toast-close', toast, 'close');\n \n // Call onClose callback\n toast.onClose?.();\n }, 300); // Animation duration\n }\n\n /**\n * Clear all toasts\n */\n clearAll(): void {\n this.toasts.forEach(toast => {\n const timeoutId = this.timeouts.get(toast.id);\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n });\n this.timeouts.clear();\n this.toasts = [];\n }\n\n /**\n * Handle toast click\n */\n private handleToastClick(toast: ToastItem): void {\n this.emitToastEvent('nr-toast-click', toast, 'click');\n toast.onClick?.();\n }\n\n /**\n * Handle close button click\n */\n private handleCloseClick(event: Event, toast: ToastItem): void {\n event.stopPropagation();\n this.removeToast(toast.id);\n }\n\n /**\n * Get default icon for toast type\n */\n private getDefaultIcon(type?: ToastType): string {\n switch (type) {\n case ToastType.Success:\n return 'check-circle';\n case ToastType.Error:\n return 'x-circle';\n case ToastType.Warning:\n return 'alert-triangle';\n case ToastType.Info:\n return 'info';\n default:\n return EMPTY_STRING;\n }\n }\n\n /**\n * Generate unique ID\n */\n private generateId(): string {\n return `toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n }\n\n /**\n * Get animation class\n */\n private getAnimationClass(toast: ToastItem): string {\n const isRemoving = toast.removing;\n const suffix = isRemoving ? 'out' : 'in';\n return `toast--${this.animation}-${suffix}`;\n }\n\n /**\n * Emit toast event\n */\n private emitToastEvent(eventName: string, toast: ToastItem, action: ToastEventDetail['action']): void {\n this.dispatchEvent(new CustomEvent<ToastEventDetail>(eventName, {\n detail: { toast, action },\n bubbles: true,\n composed: true\n }));\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.clearAll();\n }\n\n override render() {\n return html`\n <div class=\"toast-container\">\n ${repeat(\n this.toasts,\n toast => toast.id,\n toast => this.renderToast(toast)\n )}\n </div>\n `;\n }\n\n private renderToast(toast: ToastItem) {\n const classes = {\n 'toast': true,\n [`toast--${toast.type}`]: true,\n [this.getAnimationClass(toast)]: true,\n [toast.customClass || EMPTY_STRING]: !!toast.customClass,\n };\n\n return html`\n <div\n class=${classMap(classes)}\n @click=${() => this.handleToastClick(toast)}\n role=\"alert\"\n aria-live=\"polite\"\n >\n ${toast.icon ? html`\n <div class=\"toast__icon\">\n <nr-icon name=${toast.icon} size=\"medium\"></nr-icon>\n </div>\n ` : nothing}\n \n <div class=\"toast__content\">\n ${toast.content \n ? toast.content \n : html`\n <div class=\"toast__text\">${toast.text}</div>\n ${toast.button ? this.renderButton(toast.button) : nothing}\n `\n }\n </div>\n \n ${toast.closable ? html`\n <button\n class=\"toast__close\"\n @click=${(e: Event) => this.handleCloseClick(e, toast)}\n aria-label=\"Close notification\"\n type=\"button\"\n >\n <nr-icon name=\"x\" size=\"small\"></nr-icon>\n </button>\n ` : nothing}\n </div>\n `;\n }\n\n private renderButton(button: ToastButton) {\n const handleButtonClick = (e: Event) => {\n e.stopPropagation();\n button.onClick(e);\n };\n\n return html`\n <div class=\"toast__button\">\n <nr-button\n type=${button.type || 'default'}\n size=${button.size || 'small'}\n ?disabled=${button.disabled || false}\n @click=${handleButtonClick}\n >\n ${button.icon ? html`<nr-icon slot=\"icon-left\" name=${button.icon}></nr-icon>` : nothing}\n ${button.label}\n </nr-button>\n </div>\n `;\n }\n}\n"]}
1
+ {"version":3,"file":"toast.component.js","sourceRoot":"","sources":["../../../src/components/toast/toast.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAQL,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,6BAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IAAjE;;QAGW,uBAAkB,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEvD,4CAA4C;QAE5C,aAAQ,4CAAyC;QAEjD,0CAA0C;QAE1C,cAAS,GAAG,kBAAkB,CAAC;QAE/B,kDAAkD;QAElD,oBAAe,GAAG,sBAAsB,CAAC;QAEzC,gCAAgC;QAEhC,cAAS,oCAAuC;QAEhD,yCAAyC;QAEzC,UAAK,GAAG,IAAI,CAAC;QAEb,yDAAyD;QAEzD,gBAAW,GAAG,IAAI,CAAC;QAEnB,oCAAoC;QAE5B,WAAM,GAAgB,EAAE,CAAC;QAEjC,mCAAmC;QAC3B,aAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IA2Q/C,CAAC;IAzQC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CAAC,OAAO;;KAEd,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,MAAmB;QACtC,MAAM,iBAAiB,GAAG,CAAC,CAAQ,EAAE,EAAE;YACrC,CAAC,CAAC,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC;QAEF,OAAO,IAAI,CAAA;;;iBAGE,MAAM,CAAC,IAAI,IAAI,SAAS;iBACxB,MAAM,CAAC,IAAI,IAAI,OAAO;sBACjB,MAAM,CAAC,QAAQ,IAAI,KAAK;mBAC3B,iBAAiB;;YAExB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA,kCAAkC,MAAM,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,OAAO;YACtF,MAAM,CAAC,KAAK;;;KAGnB,CAAC;IACJ,CAAC;CACF,CAAA;AA5SiB,qBAAM,GAAG,MAAO,CAAA;AAMhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDACO;AAIjD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACI;AAI/B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDACc;AAIzC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACqB;AAIhD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;6CACf;AAIb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDACT;AAInB;IADC,KAAK,EAAE;8CACyB;AA/BtB,cAAc;IAD1B,aAAa,CAAC,UAAU,CAAC;GACb,cAAc,CA6S1B;SA7SY,cAAc","sourcesContent":["/**\n * @license\n * Copyright 2023 Nuraly, Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { LitElement, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styles } from './toast.style.js';\nimport { NuralyUIBaseMixin } from '@nuralyui/common/mixins';\nimport {\n ToastType,\n ToastPosition,\n ToastAnimation,\n ToastConfig,\n ToastItem,\n ToastEventDetail,\n ToastButton,\n DEFAULT_TOAST_DURATION,\n DEFAULT_MAX_TOASTS,\n EMPTY_STRING\n} from './toast.types.js';\n\n// Import required components\n\n/**\n * Toast notification component for displaying temporary messages.\n * \n * Provides a flexible notification system with multiple types, positions, and animations.\n * Supports stacking multiple toasts, auto-dismiss (enabled by default), action buttons, \n * custom HTML content, and manual closing.\n * \n * @example\n * ```html\n * <!-- Basic usage with auto-dismiss -->\n * <nr-toast position=\"top-right\"></nr-toast>\n * \n * <!-- Disable auto-dismiss to require manual closing -->\n * <nr-toast position=\"top-right\" auto-dismiss=\"false\"></nr-toast>\n * \n * <!-- Programmatic usage -->\n * <script>\n * const toast = document.querySelector('nr-toast');\n * toast.show({ text: 'Success!', type: 'success' });\n * toast.show({ text: 'Error occurred', type: 'error', duration: 7000 });\n * \n * // Disable auto-dismiss for specific toast\n * toast.show({ text: 'Persistent message', autoDismiss: false });\n * \n * // Toast with action button\n * toast.show({\n * text: 'Item deleted',\n * type: 'success',\n * button: {\n * label: 'Undo',\n * onClick: () => console.log('Undo clicked'),\n * type: 'primary'\n * }\n * });\n * \n * // Custom HTML content (GDPR consent example)\n * toast.show({\n * content: html`\n * <div>\n * <h4>Cookie Consent</h4>\n * <p>We use cookies to improve your experience.</p>\n * <div style=\"display: flex; gap: 0.5rem; margin-top: 0.5rem;\">\n * <nr-button size=\"small\" type=\"primary\">Accept</nr-button>\n * <nr-button size=\"small\" type=\"secondary\">Decline</nr-button>\n * </div>\n * </div>\n * `,\n * autoDismiss: false,\n * closable: true\n * });\n * </script>\n * ```\n * \n * @fires nr-toast-show - Toast shown\n * @fires nr-toast-close - Toast closed\n * @fires nr-toast-click - Toast clicked\n * \n * @cssproperty --nuraly-z-index-toast - Toast z-index\n * @cssproperty --nuraly-toast-default-background - Default toast background\n * @cssproperty --nuraly-toast-success-background - Success toast background\n * @cssproperty --nuraly-toast-error-background - Error toast background\n * @cssproperty --nuraly-toast-warning-background - Warning toast background\n * @cssproperty --nuraly-toast-info-background - Info toast background\n */\n@customElement('nr-toast')\nexport class NrToastElement extends NuralyUIBaseMixin(LitElement) {\n static override styles = styles;\n\n override requiredComponents = ['nr-icon', 'nr-button'];\n\n /** Position of toast container on screen */\n @property({ type: String, reflect: true })\n position: ToastPosition = ToastPosition.TopRight;\n\n /** Maximum number of toasts to display */\n @property({ type: Number })\n maxToasts = DEFAULT_MAX_TOASTS;\n\n /** Default duration for toasts in milliseconds */\n @property({ type: Number })\n defaultDuration = DEFAULT_TOAST_DURATION;\n\n /** Animation type for toasts */\n @property({ type: String })\n animation: ToastAnimation = ToastAnimation.Fade;\n\n /** Whether to stack toasts or replace */\n @property({ type: Boolean })\n stack = true;\n\n /** Auto dismiss toasts after duration (default: true) */\n @property({ type: Boolean })\n autoDismiss = true;\n\n /** Internal state: active toasts */\n @state()\n private toasts: ToastItem[] = [];\n\n /** Timeout map for auto-dismiss */\n private timeouts = new Map<string, number>();\n\n /**\n * Show a new toast notification\n * @param config - Toast configuration\n * @returns Toast ID for manual control\n */\n show(config: string | ToastConfig): string {\n const toastConfig: ToastConfig = typeof config === 'string' \n ? { text: config }\n : config;\n\n const toast: ToastItem = {\n id: this.generateId(),\n timestamp: Date.now(),\n text: toastConfig.text,\n content: toastConfig.content,\n type: toastConfig.type || ToastType.Default,\n duration: toastConfig.duration ?? this.defaultDuration,\n autoDismiss: toastConfig.autoDismiss ?? this.autoDismiss,\n closable: toastConfig.closable ?? true,\n icon: toastConfig.icon || this.getDefaultIcon(toastConfig.type),\n customClass: toastConfig.customClass,\n button: toastConfig.button,\n onClose: toastConfig.onClose,\n onClick: toastConfig.onClick,\n };\n\n // Handle max toasts\n if (!this.stack) {\n this.clearAll();\n } else if (this.toasts.length >= this.maxToasts) {\n this.removeToast(this.toasts[0].id);\n }\n\n // Add toast\n this.toasts = [...this.toasts, toast];\n\n // Emit show event\n this.emitToastEvent('nr-toast-show', toast, 'show');\n\n // Set auto-dismiss timeout\n if (toast.autoDismiss && toast.duration && toast.duration > 0) {\n const timeoutId = window.setTimeout(() => {\n this.removeToast(toast.id);\n }, toast.duration);\n this.timeouts.set(toast.id, timeoutId);\n }\n\n return toast.id;\n }\n\n /**\n * Show success toast\n */\n success(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Success, duration });\n }\n\n /**\n * Show error toast\n */\n error(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Error, duration });\n }\n\n /**\n * Show warning toast\n */\n warning(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Warning, duration });\n }\n\n /**\n * Show info toast\n */\n info(text: string, duration?: number): string {\n return this.show({ text, type: ToastType.Info, duration });\n }\n\n /**\n * Remove a specific toast\n */\n removeToast(id: string): void {\n const toast = this.toasts.find(t => t.id === id);\n if (!toast) return;\n\n // Mark as removing for animation\n toast.removing = true;\n this.requestUpdate();\n\n // Clear timeout\n const timeoutId = this.timeouts.get(id);\n if (timeoutId) {\n clearTimeout(timeoutId);\n this.timeouts.delete(id);\n }\n\n // Remove after animation\n setTimeout(() => {\n this.toasts = this.toasts.filter(t => t.id !== id);\n \n // Emit close event\n this.emitToastEvent('nr-toast-close', toast, 'close');\n \n // Call onClose callback\n toast.onClose?.();\n }, 300); // Animation duration\n }\n\n /**\n * Clear all toasts\n */\n clearAll(): void {\n this.toasts.forEach(toast => {\n const timeoutId = this.timeouts.get(toast.id);\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n });\n this.timeouts.clear();\n this.toasts = [];\n }\n\n /**\n * Handle toast click\n */\n private handleToastClick(toast: ToastItem): void {\n this.emitToastEvent('nr-toast-click', toast, 'click');\n toast.onClick?.();\n }\n\n /**\n * Handle close button click\n */\n private handleCloseClick(event: Event, toast: ToastItem): void {\n event.stopPropagation();\n this.removeToast(toast.id);\n }\n\n /**\n * Get default icon for toast type\n */\n private getDefaultIcon(type?: ToastType): string {\n switch (type) {\n case ToastType.Success:\n return 'check-circle';\n case ToastType.Error:\n return 'x-circle';\n case ToastType.Warning:\n return 'alert-triangle';\n case ToastType.Info:\n return 'info';\n default:\n return EMPTY_STRING;\n }\n }\n\n /**\n * Generate unique ID\n */\n private generateId(): string {\n return `toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n }\n\n /**\n * Get animation class\n */\n private getAnimationClass(toast: ToastItem): string {\n const isRemoving = toast.removing;\n const suffix = isRemoving ? 'out' : 'in';\n return `toast--${this.animation}-${suffix}`;\n }\n\n /**\n * Emit toast event\n */\n private emitToastEvent(eventName: string, toast: ToastItem, action: ToastEventDetail['action']): void {\n this.dispatchEvent(new CustomEvent<ToastEventDetail>(eventName, {\n detail: { toast, action },\n bubbles: true,\n composed: true\n }));\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.clearAll();\n }\n\n override render() {\n return html`\n <div class=\"toast-container\">\n ${repeat(\n this.toasts,\n toast => toast.id,\n toast => this.renderToast(toast)\n )}\n </div>\n `;\n }\n\n private renderToast(toast: ToastItem) {\n const classes = {\n 'toast': true,\n [`toast--${toast.type}`]: true,\n [this.getAnimationClass(toast)]: true,\n [toast.customClass || EMPTY_STRING]: !!toast.customClass,\n };\n\n return html`\n <div\n class=${classMap(classes)}\n @click=${() => this.handleToastClick(toast)}\n role=\"alert\"\n aria-live=\"polite\"\n >\n ${toast.icon ? html`\n <div class=\"toast__icon\">\n <nr-icon name=${toast.icon} size=\"medium\"></nr-icon>\n </div>\n ` : nothing}\n \n <div class=\"toast__content\">\n ${toast.content \n ? toast.content \n : html`\n <div class=\"toast__text\">${toast.text}</div>\n ${toast.button ? this.renderButton(toast.button) : nothing}\n `\n }\n </div>\n \n ${toast.closable ? html`\n <button\n class=\"toast__close\"\n @click=${(e: Event) => this.handleCloseClick(e, toast)}\n aria-label=\"Close notification\"\n type=\"button\"\n >\n <nr-icon name=\"x\" size=\"small\"></nr-icon>\n </button>\n ` : nothing}\n </div>\n `;\n }\n\n private renderButton(button: ToastButton) {\n const handleButtonClick = (e: Event) => {\n e.stopPropagation();\n button.onClick(e);\n };\n\n return html`\n <div class=\"toast__button\">\n <nr-button\n type=${button.type || 'default'}\n size=${button.size || 'small'}\n ?disabled=${button.disabled || false}\n @click=${handleButtonClick}\n >\n ${button.icon ? html`<nr-icon slot=\"icon-left\" name=${button.icon}></nr-icon>` : nothing}\n ${button.label}\n </nr-button>\n </div>\n `;\n }\n}\n"]}