Skip to content

Commit cedca8f

Browse files
committed
don't use shadowroot
1 parent 7b9fbdd commit cedca8f

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

internal/ui/components/toast/toast.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {getGlobalStyleSheets} from "../../util/global-styles";
2-
31
const 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
2321
class 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

201199
export default function initToastComponent() {
202200
customElements.define("toast-element", Toast);
203-
}
201+
}

internal/ui/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
#toast-container{
3333
@apply toast sm:toast-top flex-col-reverse sm:flex-col toast-center z-50;
3434
}
35-
}
35+
}

internal/ui/util/global-styles.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)