1- import { getGlobalStyleSheets } from "../../util/global-styles" ;
2-
31const ALERT_TYPE_CLASSES : Record < string , string > = {
42 "success" : "alert-success" ,
53 "info" : "alert-info" ,
@@ -23,17 +21,17 @@ const TOAST_SWIPE_VELOCITY_THRESHOLD = window.screen.availWidth / 2; // px / s
2321class Toast extends HTMLElement {
2422 constructor ( ) {
2523 super ( ) ;
26- this . attachShadow ( { mode : "open" } ) ;
27- this . shadowRoot ! . adoptedStyleSheets . push ( ...getGlobalStyleSheets ( ) ) ;
24+ this . #children = Array . from ( this . children ) . map ( el => el . cloneNode ( true ) ) ;
2825 }
2926
3027 #progressAnimation: Animation | undefined ;
3128 #lastTouchEvent: TouchEvent | undefined ;
3229 // [px, timestamp]
3330 #lastTouchChanges: number [ ] [ ] = [ ] ;
31+ #children: Node [ ] ;
3432
3533 #getAlertElement = ( ) : HTMLElement => {
36- return < HTMLElement > this . shadowRoot ! . children [ 0 ] ;
34+ return < HTMLElement > this . children [ 0 ] ;
3735 }
3836
3937 #parseLeft = ( ) : number => {
@@ -53,7 +51,7 @@ class Toast extends HTMLElement {
5351 toastDuration = DEFAULT_TOAST_DURATION ;
5452 }
5553
56- this . #progressAnimation = this . shadowRoot ! . querySelector ( ".toast-alert-progress" ) ! . animate ( [
54+ this . #progressAnimation = this . querySelector ( ".toast-alert-progress" ) ! . animate ( [
5755 {
5856 width : "0%"
5957 } ,
@@ -189,15 +187,15 @@ class Toast extends HTMLElement {
189187
190188 render ( ) {
191189 const alertType = this . getAttribute ( 'type' ) || "" ;
192- this . shadowRoot ! . innerHTML = `
190+ this . innerHTML = `
193191 <div class="toast-alert ${ ! ! ALERT_TYPE_CLASSES [ alertType ] ? ALERT_TYPE_CLASSES [ alertType ] : '' } ">
194- <slot></slot>
195192 <div class="toast-alert-progress"></div>
196193 </div>
197194 ` ;
195+ this . #getAlertElement( ) . prepend ( ...this . #children) ;
198196 }
199197}
200198
201199export default function initToastComponent ( ) {
202200 customElements . define ( "toast-element" , Toast ) ;
203- }
201+ }
0 commit comments