@nuralyui/toast 0.0.10 → 0.0.11
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/bundle.js +44 -16
- package/package.json +2 -2
- package/toast.component.d.ts +1 -1
- package/toast.component.js +1 -1
- package/toast.component.js.map +1 -1
package/bundle.js
CHANGED
|
@@ -560,7 +560,7 @@ const Kc=1,Xc=2,Qc=c=>(...a)=>({_$litDirective$:c,values:a});class Jc{constructo
|
|
|
560
560
|
|
|
561
561
|
/* Size properties with fallbacks */
|
|
562
562
|
--nuraly-icon-size-fallback: 18px;
|
|
563
|
-
--nuraly-icon-size-small-fallback:
|
|
563
|
+
--nuraly-icon-size-small-fallback: 14px;
|
|
564
564
|
--nuraly-icon-size-medium-fallback: 20px;
|
|
565
565
|
--nuraly-icon-size-large-fallback: 24px;
|
|
566
566
|
--nuraly-icon-size-xlarge-fallback: 32px;
|
|
@@ -694,7 +694,13 @@ var Zb=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.
|
|
|
694
694
|
>
|
|
695
695
|
<path d="${c}" />
|
|
696
696
|
</svg>
|
|
697
|
-
`}getIconPath(){if(!this.name)return console.warn("HyIconElement: Icon name is required"),"";const c="solid"==this.type?"fas":"far";try{const a=Si.definitions;if(!a||!a[c])return console.warn(`HyIconElement: Icon pack "${c}" not found`),"";const e=a[c][this.name];if(!e)return console.warn(`HyIconElement: Icon "${this.name}" not found in ${c} pack`),"";const s=e[4];return s&&"string"==typeof s?s:(console.warn(`HyIconElement: Invalid path data for icon "${this.name}"`),"")}catch(c){return console.error(`HyIconElement: Error loading icon "${this.name}":`,c),""}}getIconRole(){return this.clickable?"button":this.alt?"img":"presentation"}getIconTabIndex(){return this.clickable&&!this.disabled?"0":"-1"}getAriaDisabled(){return this.disabled?"true":void 0}};aN.styles=Qb,Zb([_c({type:String})],aN.prototype,"name",void 0),Zb([_c()],aN.prototype,"type",void 0),Zb([_c({type:String,attribute:"alt"})],aN.prototype,"alt",void 0),Zb([_c({type:String,reflect:!0})],aN.prototype,"size",void 0),Zb([_c({type:String})],aN.prototype,"color",void 0),Zb([_c({type:String})],aN.prototype,"width",void 0),Zb([_c({type:String})],aN.prototype,"height",void 0),aN=Zb([Gc("nr-icon")],aN);
|
|
697
|
+
`}getIconPath(){if(!this.name)return console.warn("HyIconElement: Icon name is required"),"";const c="solid"==this.type?"fas":"far";try{const a=Si.definitions;if(!a||!a[c])return console.warn(`HyIconElement: Icon pack "${c}" not found`),"";const e=a[c][this.name];if(!e)return console.warn(`HyIconElement: Icon "${this.name}" not found in ${c} pack`),"";const s=e[4];return s&&"string"==typeof s?s:(console.warn(`HyIconElement: Invalid path data for icon "${this.name}"`),"")}catch(c){return console.error(`HyIconElement: Error loading icon "${this.name}":`,c),""}}getIconRole(){return this.clickable?"button":this.alt?"img":"presentation"}getIconTabIndex(){return this.clickable&&!this.disabled?"0":"-1"}getAriaDisabled(){return this.disabled?"true":void 0}};aN.styles=Qb,Zb([_c({type:String})],aN.prototype,"name",void 0),Zb([_c()],aN.prototype,"type",void 0),Zb([_c({type:String,attribute:"alt"})],aN.prototype,"alt",void 0),Zb([_c({type:String,reflect:!0})],aN.prototype,"size",void 0),Zb([_c({type:String})],aN.prototype,"color",void 0),Zb([_c({type:String})],aN.prototype,"width",void 0),Zb([_c({type:String})],aN.prototype,"height",void 0),aN=Zb([Gc("nr-icon")],aN);
|
|
698
|
+
/**
|
|
699
|
+
* @license
|
|
700
|
+
* Copyright 2018 Google LLC
|
|
701
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
702
|
+
*/
|
|
703
|
+
const eN=c=>null!=c?c:E,sN="",iN=n`
|
|
698
704
|
:host {
|
|
699
705
|
display: inline-block;
|
|
700
706
|
vertical-align: middle;
|
|
@@ -769,6 +775,28 @@ var Zb=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.
|
|
|
769
775
|
color: inherit;
|
|
770
776
|
/* Override any size attribute with CSS variable */
|
|
771
777
|
font-size: var(--nuraly-button-icon-size, 1rem) !important;
|
|
778
|
+
transition: all var(--nuraly-transition-fast, 0.15s) ease;
|
|
779
|
+
/* Inherit cursor from button */
|
|
780
|
+
cursor: inherit;
|
|
781
|
+
/* Prevent icon from being focusable */
|
|
782
|
+
pointer-events: none;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/* Icon focus state */
|
|
786
|
+
&:focus:not(:disabled) nr-icon {
|
|
787
|
+
opacity: 1;
|
|
788
|
+
filter: brightness(1.1);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/* Icon active state */
|
|
792
|
+
&:active:not(:disabled) nr-icon {
|
|
793
|
+
opacity: 0.9;
|
|
794
|
+
transform: scale(0.95);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/* Icon hover state */
|
|
798
|
+
&:hover:not(:disabled) nr-icon {
|
|
799
|
+
opacity: 1;
|
|
772
800
|
}
|
|
773
801
|
|
|
774
802
|
/* Icon spacing - use gap for cleaner spacing */
|
|
@@ -1165,32 +1193,32 @@ var Zb=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.
|
|
|
1165
1193
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1166
1194
|
* SPDX-License-Identifier: MIT
|
|
1167
1195
|
*/
|
|
1168
|
-
class
|
|
1196
|
+
class nN{constructor(c){this._host=c,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}handleError(c,a){console.error(`[ButtonController:${this.constructor.name}] Error in ${a}:`,c),this._host.dispatchEvent(new CustomEvent("nr-button-error",{detail:{error:c.message,context:a,controller:this.constructor.name},bubbles:!0,composed:!0}))}requestUpdate(){try{this._host.requestUpdate()}catch(c){this.handleError(c,"requestUpdate")}}dispatchEvent(c){try{return this._host.dispatchEvent(c)}catch(c){return this.handleError(c,"dispatchEvent"),!1}}}
|
|
1169
1197
|
/**
|
|
1170
1198
|
* @license
|
|
1171
1199
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1172
1200
|
* SPDX-License-Identifier: MIT
|
|
1173
|
-
*/class
|
|
1201
|
+
*/class lN extends nN{createRipple(c){try{if(!this.host.ripple||this.host.disabled)return;const a=c.currentTarget,e=a.getBoundingClientRect(),s=2*Math.max(e.width,e.height),i=c.clientX-e.left-s/2,n=c.clientY-e.top-s/2,l=document.createElement("span");l.className="ripple",l.style.width=l.style.height=s+"px",l.style.left=i+"px",l.style.top=n+"px";a.querySelectorAll(".ripple").forEach((c=>c.remove())),a.appendChild(l),setTimeout((()=>{l.remove()}),600)}catch(c){this.handleError(c,"createRipple")}}handleRippleClick(c){try{this.createRipple(c),this.dispatchEvent(new CustomEvent("button-click",{detail:{disabled:this.host.disabled,timestamp:Date.now(),coordinates:{x:c.clientX,y:c.clientY}},bubbles:!0,composed:!0}))}catch(c){this.handleError(c,"handleRippleClick")}}}
|
|
1174
1202
|
/**
|
|
1175
1203
|
* @license
|
|
1176
1204
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1177
1205
|
* SPDX-License-Identifier: MIT
|
|
1178
|
-
*/class
|
|
1206
|
+
*/class oN extends nN{handleKeyboardActivation(c){try{if(this.host.disabled)return;this.isActivationKey(c)&&(c.preventDefault(),this.host.click(),this.dispatchEvent(new CustomEvent("keyboard-activation",{detail:{key:c.key,timestamp:Date.now(),target:this.host},bubbles:!0,composed:!0})))}catch(c){this.handleError(c,"handleKeyboardActivation")}}handleKeydown(c){try{if(this.host.disabled){if(!this.isReadonlyKeyAllowed(c))return void c.preventDefault()}this.handleKeyboardActivation(c)}catch(c){this.handleError(c,"handleKeydown")}}isActivationKey(c){return"Enter"===c.key||" "===c.key}isReadonlyKeyAllowed(c){return["Tab","Shift","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(c.key)}}
|
|
1179
1207
|
/**
|
|
1180
1208
|
* @license
|
|
1181
1209
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1182
1210
|
* SPDX-License-Identifier: MIT
|
|
1183
|
-
*/class
|
|
1211
|
+
*/class rN extends nN{isLinkType(){return"link"===this.host.type&&!!this.host.href}getElementTag(){return this.isLinkType()?"a":"button"}getLinkAttributes(){try{const c={};return this.isLinkType()?(c.href=this.host.href,this.host.target&&(c.target=this.host.target,"_blank"===this.host.target&&(c.rel="noopener noreferrer")),c.role="link"):c.role="button",c}catch(c){return this.handleError(c,"getLinkAttributes"),{role:"button"}}}handleLinkNavigation(c){try{this.isLinkType()&&this.dispatchEvent(new CustomEvent("link-navigation",{detail:{href:this.host.href,target:this.host.target,timestamp:Date.now(),originalEvent:c},bubbles:!0,composed:!0}))}catch(c){this.handleError(c,"handleLinkNavigation")}}}
|
|
1184
1212
|
/**
|
|
1185
1213
|
* @license
|
|
1186
1214
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1187
1215
|
* SPDX-License-Identifier: MIT
|
|
1188
|
-
*/var
|
|
1189
|
-
name=${
|
|
1190
|
-
type=${
|
|
1191
|
-
alt=${
|
|
1192
|
-
size=${
|
|
1193
|
-
color=${
|
|
1216
|
+
*/var fN=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.getOwnPropertyDescriptor(a,e):s,o=c.length-1;o>=0;o--)(i=c[o])&&(l=(n<3?i(l):n>3?i(a,e,l):i(a,e))||l);return n>3&&l&&Object.defineProperty(a,e,l),l};let tN=class extends(Va(Oc)){constructor(){super(...arguments),this.disabled=!1,this.loading=!1,this.size=sN,this.type="default",this.shape="default",this.block=!1,this.dashed=!1,this.icon=[],this.iconPosition="left",this.href=sN,this.target=sN,this.ripple=!0,this.buttonAriaLabel=sN,this.ariaDescribedBy=sN,this.htmlType=sN,this.requiredComponents=["nr-icon"],this.rippleController=new lN(this),this.keyboardController=new oN(this),this.linkController=new rN(this)}connectedCallback(){super.connectedCallback(),this.validateDependencies()}getCommonAttributes(){return{"data-type":this.type,"data-shape":this.shape,"data-size":this.size||xc,"data-state":this.loading?"loading":xc,"data-theme":this.currentTheme,"data-block":this.block?"true":xc,class:this.dashed?"button-dashed":"","aria-disabled":this.disabled?"true":"false","aria-label":this.buttonAriaLabel||xc,"aria-describedby":this.ariaDescribedBy||xc,tabindex:this.disabled?"-1":"0"}}renderIcon(c){if(!this.isComponentAvailable("nr-icon")){const a="string"==typeof c?c:c.name;return console.warn(`[nr-button] Icon component 'nr-icon' not available. Icon "${a}" will not render. Ensure the icon component is imported and registered.`),xc}const a=()=>{switch(this.size){case"small":return"small";case"medium":default:return"medium";case"large":return"large"}};if("string"==typeof c){const e=a();return Lc`<nr-icon name=${c} size=${eN(e)}></nr-icon>`}const{name:e,type:s="solid",size:i,color:n,alt:l}=c,o=i||a();return Lc`<nr-icon
|
|
1217
|
+
name=${e}
|
|
1218
|
+
type=${s}
|
|
1219
|
+
alt=${l||""}
|
|
1220
|
+
size=${eN(o)}
|
|
1221
|
+
color=${n||""}
|
|
1194
1222
|
></nr-icon>`}handleClick(c){this.disabled?c.preventDefault():(this.rippleController.handleRippleClick(c),this.linkController.isLinkType()&&this.linkController.handleLinkNavigation(c),this.dispatchEventWithMetadata("button-clicked",{type:this.type,disabled:this.disabled,loading:this.loading,href:this.href||null}))}handleKeydown(c){this.keyboardController.handleKeydown(c)}getResolvedLeftIcon(){var c,a;return this.iconLeft?this.iconLeft:(null===(c=this.icons)||void 0===c?void 0:c.left)?this.icons.left:(null===(a=this.icon)||void 0===a?void 0:a.length)>0?this.icon[0]:void 0}getResolvedRightIcon(){var c,a;return this.iconRight?this.iconRight:(null===(c=this.icons)||void 0===c?void 0:c.right)?this.icons.right:2===(null===(a=this.icon)||void 0===a?void 0:a.length)?this.icon[1]:void 0}render(){const c=this.linkController.getElementTag(),a=this.getCommonAttributes(),e=this.linkController.getLinkAttributes(),s=this.getResolvedLeftIcon(),i=this.getResolvedRightIcon(),n=Lc`
|
|
1195
1223
|
<span id="container" part="container">
|
|
1196
1224
|
${s?this.renderIcon(s):xc}
|
|
@@ -1240,13 +1268,13 @@ class iN{constructor(c){this._host=c,this._host.addController(this)}get host(){r
|
|
|
1240
1268
|
>
|
|
1241
1269
|
${n}
|
|
1242
1270
|
</button>
|
|
1243
|
-
`}};
|
|
1271
|
+
`}};tN.styles=iN,fN([_c({type:Boolean})],tN.prototype,"disabled",void 0),fN([_c({type:Boolean})],tN.prototype,"loading",void 0),fN([_c({type:String})],tN.prototype,"size",void 0),fN([_c({type:String})],tN.prototype,"type",void 0),fN([_c({type:String})],tN.prototype,"shape",void 0),fN([_c({type:Boolean})],tN.prototype,"block",void 0),fN([_c({type:Boolean})],tN.prototype,"dashed",void 0),fN([_c({type:Array})],tN.prototype,"icon",void 0),fN([_c({type:Object})],tN.prototype,"iconLeft",void 0),fN([_c({type:Object})],tN.prototype,"iconRight",void 0),fN([_c({type:Object})],tN.prototype,"icons",void 0),fN([_c({reflect:!0})],tN.prototype,"iconPosition",void 0),fN([_c({type:String})],tN.prototype,"href",void 0),fN([_c({type:String})],tN.prototype,"target",void 0),fN([_c({type:Boolean})],tN.prototype,"ripple",void 0),fN([_c({type:String})],tN.prototype,"buttonAriaLabel",void 0),fN([_c({type:String})],tN.prototype,"ariaDescribedBy",void 0),fN([_c({type:String})],tN.prototype,"htmlType",void 0),tN=fN([Gc("nr-button")],tN);
|
|
1244
1272
|
/**
|
|
1245
1273
|
* @license
|
|
1246
1274
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1247
1275
|
* SPDX-License-Identifier: MIT
|
|
1248
1276
|
*/
|
|
1249
|
-
var
|
|
1277
|
+
var zN=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.getOwnPropertyDescriptor(a,e):s,o=c.length-1;o>=0;o--)(i=c[o])&&(l=(n<3?i(l):n>3?i(a,e,l):i(a,e))||l);return n>3&&l&&Object.defineProperty(a,e,l),l};let mN=class extends(Va(Oc)){constructor(){super(...arguments),this.requiredComponents=["nr-icon","nr-button"],this.position="top-right",this.maxToasts=5,this.defaultDuration=5e3,this.animation="fade",this.stack=!0,this.autoDismiss=!0,this.toasts=[],this.timeouts=new Map}show(c){var a,e,s;const i="string"==typeof c?{text:c}:c,n={id:this.generateId(),timestamp:Date.now(),text:i.text,content:i.content,type:i.type||"default",duration:null!==(a=i.duration)&&void 0!==a?a:this.defaultDuration,autoDismiss:null!==(e=i.autoDismiss)&&void 0!==e?e:this.autoDismiss,closable:null===(s=i.closable)||void 0===s||s,icon:i.icon||this.getDefaultIcon(i.type),customClass:i.customClass,button:i.button,onClose:i.onClose,onClick:i.onClick};if(this.stack?this.toasts.length>=this.maxToasts&&this.removeToast(this.toasts[0].id):this.clearAll(),this.toasts=[...this.toasts,n],this.emitToastEvent("nr-toast-show",n,"show"),n.autoDismiss&&n.duration&&n.duration>0){const c=window.setTimeout((()=>{this.removeToast(n.id)}),n.duration);this.timeouts.set(n.id,c)}return n.id}success(c,a){return this.show({text:c,type:"success",duration:a})}error(c,a){return this.show({text:c,type:"error",duration:a})}warning(c,a){return this.show({text:c,type:"warning",duration:a})}info(c,a){return this.show({text:c,type:"info",duration:a})}removeToast(c){const a=this.toasts.find((a=>a.id===c));if(!a)return;a.removing=!0,this.requestUpdate();const e=this.timeouts.get(c);e&&(clearTimeout(e),this.timeouts.delete(c)),setTimeout((()=>{var e;this.toasts=this.toasts.filter((a=>a.id!==c)),this.emitToastEvent("nr-toast-close",a,"close"),null===(e=a.onClose)||void 0===e||e.call(a)}),300)}clearAll(){this.toasts.forEach((c=>{const a=this.timeouts.get(c.id);a&&clearTimeout(a)})),this.timeouts.clear(),this.toasts=[]}handleToastClick(c){var a;this.emitToastEvent("nr-toast-click",c,"click"),null===(a=c.onClick)||void 0===a||a.call(c)}handleCloseClick(c,a){c.stopPropagation(),this.removeToast(a.id)}getDefaultIcon(c){switch(c){case"success":return"check-circle";case"error":return"x-circle";case"warning":return"alert-triangle";case"info":return"info";default:return""}}generateId(){return`toast-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}getAnimationClass(c){const a=c.removing?"out":"in";return`toast--${this.animation}-${a}`}emitToastEvent(c,a,e){this.dispatchEvent(new CustomEvent(c,{detail:{toast:a,action:e},bubbles:!0,composed:!0}))}disconnectedCallback(){super.disconnectedCallback(),this.clearAll()}render(){return Lc`
|
|
1250
1278
|
<div class="toast-container">
|
|
1251
1279
|
${oa(this.toasts,(c=>c.id),(c=>this.renderToast(c)))}
|
|
1252
1280
|
</div>
|
|
@@ -1293,10 +1321,10 @@ var tN=function(c,a,e,s){for(var i,n=arguments.length,l=n<3?a:null===s?s=Object.
|
|
|
1293
1321
|
${c.label}
|
|
1294
1322
|
</nr-button>
|
|
1295
1323
|
</div>
|
|
1296
|
-
`}};
|
|
1324
|
+
`}};mN.styles=fa,zN([_c({type:String,reflect:!0})],mN.prototype,"position",void 0),zN([_c({type:Number})],mN.prototype,"maxToasts",void 0),zN([_c({type:Number})],mN.prototype,"defaultDuration",void 0),zN([_c({type:String})],mN.prototype,"animation",void 0),zN([_c({type:Boolean})],mN.prototype,"stack",void 0),zN([_c({type:Boolean})],mN.prototype,"autoDismiss",void 0),zN([function(c){return _c({...c,state:!0})}()],mN.prototype,"toasts",void 0),mN=zN([Gc("nr-toast")],mN);
|
|
1297
1325
|
/**
|
|
1298
1326
|
* @license
|
|
1299
1327
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
1300
1328
|
* SPDX-License-Identifier: MIT
|
|
1301
1329
|
*/
|
|
1302
|
-
class
|
|
1330
|
+
class HN{constructor(c){this._host=c,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}handleError(c,a){console.error(`[ToastController:${this.constructor.name}] Error in ${a}:`,c),this._host.dispatchEvent(new CustomEvent("nr-toast-error",{detail:{error:c.message,context:a,controller:this.constructor.name},bubbles:!0,composed:!0}))}requestUpdate(){try{this._host.requestUpdate()}catch(c){this.handleError(c,"requestUpdate")}}dispatchEvent(c){try{return this._host.dispatchEvent(c)}catch(c){return this.handleError(c,"dispatchEvent"),!1}}}export{HN as BaseToastController,pa as DEFAULT_MAX_TOASTS,Ma as DEFAULT_TOAST_DURATION,ha as EMPTY_STRING,mN as NrToastElement};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuralyui/toast",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Toast notification component for NuralyUI library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/
|
|
27
|
+
"url": "https://github.com/Nuralyio/NuralyUI.git",
|
|
28
28
|
"directory": "src/components/toast"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
package/toast.component.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { LitElement } from 'lit';
|
|
|
7
7
|
import { ToastPosition, ToastAnimation, ToastConfig } from './toast.types.js';
|
|
8
8
|
import '../icon/icon.component.js';
|
|
9
9
|
import '../button/index.js';
|
|
10
|
-
declare const NrToastElement_base: (new (...args: any[]) => import("
|
|
10
|
+
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
11
|
/**
|
|
12
12
|
* Toast notification component for displaying temporary messages.
|
|
13
13
|
*
|
package/toast.component.js
CHANGED
|
@@ -14,7 +14,7 @@ import { customElement, property, state } from 'lit/decorators.js';
|
|
|
14
14
|
import { repeat } from 'lit/directives/repeat.js';
|
|
15
15
|
import { classMap } from 'lit/directives/class-map.js';
|
|
16
16
|
import { styles } from './toast.style.js';
|
|
17
|
-
import { NuralyUIBaseMixin } from '
|
|
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
20
|
import '../icon/icon.component.js';
|
package/toast.component.js.map
CHANGED
|
@@ -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,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAQL,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,6BAA6B;AAC7B,OAAO,2BAA2B,CAAC;AACnC,OAAO,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;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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 '../../shared/base-mixin.js';\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;AAC7B,OAAO,2BAA2B,CAAC;AACnC,OAAO,oBAAoB,CAAC;AAE5B;;;;;;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AE,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"]}
|