Skip to content

Commit 4d427e7

Browse files
committed
refactor: migrate toast-notification HTML template to separate JS file and update styles for icons
1 parent 2c28c32 commit 4d427e7

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

components/toast-notification/toast-notification.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@
4242
.close {
4343
cursor: pointer;
4444
align-self: flex-start;
45+
}
46+
47+
.info {
48+
fill: var(--cl-progress);
49+
}
50+
51+
.error {
52+
fill: var(--cl-invalid);
53+
}
54+
55+
.success {
56+
fill: var(--cl-valid);
57+
}
58+
59+
.warning {
60+
fill: var(--cl-danger);
4561
}

components/toast-notification/toast-notification.html renamed to components/toast-notification/toast-notification.html.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export const HTML = `
2+
<link rel="stylesheet" href="__css__" />
13
<svg class="hidden">
24
<symbol id="icon-info" viewBox="0 0 24 24">
35
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
@@ -18,34 +20,35 @@
1820
1921
<template id="info-toast">
2022
<div class="toast">
21-
<svg class="icon info"><use xlink:href="#icon-info"></use></svg>
23+
<material-icon icon="info" class="info"></material-icon>
2224
<p class="message">This is an info toast.</p>
2325
<svg class="icon close"><use xlink:href="#icon-close"></use></svg>
2426
</div>
2527
</template>
2628
2729
<template id="error-toast">
2830
<div class="toast toast-error">
29-
<svg class="icon error"><use xlink:href="#icon-error"></use></svg>
31+
<material-icon icon="error_outline" class="error"></material-icon>
3032
<p class="message">This is an error toast.</p>
3133
<svg class="icon close"><use xlink:href="#icon-close"></use></svg>
3234
</div>
3335
</template>
3436
3537
<template id="success-toast">
3638
<div class="toast">
37-
<svg class="icon success"><use xlink:href="#icon-success"></use></svg>
39+
<material-icon icon="check" class="success"></material-icon>
3840
<p class="message">This is a success toast.</p>
3941
<svg class="icon close"><use xlink:href="#icon-close"></use></svg>
4042
</div>
4143
</template>
4244
4345
<template id="warning-toast">
4446
<div class="toast">
45-
<svg class="icon warning"><use xlink:href="#icon-warning"></use></svg>
47+
<material-icon icon="warning" class="warning"></material-icon>
4648
<p class="message">This is a warning toast.</p>
4749
<svg class="icon close"><use xlink:href="#icon-close"></use></svg>
4850
</div>
4951
</template>
5052
51-
<div class="toast-container"></div>
53+
<div class="toast-container"></div>
54+
`.replace("__css__", import.meta.url.replace(".html.js", ".css"));

components/toast-notification/toast-notification.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// This component handles the creation and display of toast notifications.
2-
import {ComponentModule} from "../../src/modules/component.js";
1+
import { HTML } from "./toast-notification.html.js";
32

43
/**
54
* The ToastNotification web component handles creating and displaying toasts.
@@ -19,16 +18,13 @@ export class ToastNotification extends HTMLElement {
1918
constructor() {
2019
super();
2120
this.attachShadow({ mode: "open" });
21+
this.shadowRoot.innerHTML = HTML;
2222
}
2323

2424
/**
2525
* Loads HTML content and attaches click handler.
2626
*/
2727
async connectedCallback() {
28-
this.shadowRoot.innerHTML = await ComponentModule.load_html({
29-
url: import.meta.url,
30-
});
31-
3228
this.addEventListener("click", this.#clickHandler);
3329
}
3430

0 commit comments

Comments
 (0)