@cedx/base 0.15.3 → 0.17.0

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.
Files changed (36) hide show
  1. package/ReadMe.md +4 -4
  2. package/lib/UI/Alignment.d.ts +22 -0
  3. package/lib/UI/Alignment.d.ts.map +1 -0
  4. package/lib/UI/Alignment.js +17 -0
  5. package/lib/UI/Components/DialogButton.d.ts +82 -0
  6. package/lib/UI/Components/DialogButton.d.ts.map +1 -0
  7. package/lib/UI/Components/DialogButton.js +142 -0
  8. package/lib/UI/Components/KeyboardAccelerator.js +1 -1
  9. package/lib/UI/Components/ThemeDropdown.d.ts +3 -3
  10. package/lib/UI/Components/ThemeDropdown.d.ts.map +1 -1
  11. package/lib/UI/Components/ThemeDropdown.js +4 -8
  12. package/lib/UI/Components/Toast.d.ts +47 -10
  13. package/lib/UI/Components/Toast.d.ts.map +1 -1
  14. package/lib/UI/Components/Toast.js +37 -41
  15. package/lib/UI/Components/Toaster.d.ts +5 -41
  16. package/lib/UI/Components/Toaster.d.ts.map +1 -1
  17. package/lib/UI/Components/Toaster.js +9 -14
  18. package/lib/UI/DialogResult.d.ts +42 -0
  19. package/lib/UI/DialogResult.d.ts.map +1 -0
  20. package/lib/UI/DialogResult.js +37 -0
  21. package/package.json +2 -3
  22. package/src/Client/UI/Alignment.ts +25 -0
  23. package/src/Client/UI/Components/DialogButton.ts +187 -0
  24. package/src/Client/UI/Components/KeyboardAccelerator.ts +1 -1
  25. package/src/Client/UI/Components/ThemeDropdown.ts +8 -10
  26. package/src/Client/UI/Components/Toast.ts +89 -50
  27. package/src/Client/UI/Components/Toaster.ts +12 -58
  28. package/src/Client/UI/DialogResult.ts +50 -0
  29. package/lib/UI/Components/ComponentBase.d.ts +0 -24
  30. package/lib/UI/Components/ComponentBase.d.ts.map +0 -1
  31. package/lib/UI/Components/ComponentBase.js +0 -29
  32. package/lib/UI/MenuAlignment.d.ts +0 -18
  33. package/lib/UI/MenuAlignment.d.ts.map +0 -1
  34. package/lib/UI/MenuAlignment.js +0 -13
  35. package/src/Client/UI/Components/ComponentBase.ts +0 -34
  36. package/src/Client/UI/MenuAlignment.ts +0 -20
package/ReadMe.md CHANGED
@@ -1,7 +1,7 @@
1
- # Belin.io Base
2
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.15.3/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
1
+ # Cédric Belin's Base
2
+ ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.17.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
3
3
 
4
- Base library by [Cédric Belin](https://belin.io), full stack developer,
4
+ Base library by [Cédric Belin](https://cedric-belin.fr), full stack developer,
5
5
  implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
6
6
 
7
7
  > This library is dedicated to personal/side projects.
@@ -17,4 +17,4 @@ implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeSc
17
17
  - [Submit an issue](https://github.com/cedx/base/issues)
18
18
 
19
19
  ## Licence
20
- [Belin.io Base](https://github.com/cedx/base) is distributed under the MIT License.
20
+ [Cédric Belin's Base](https://github.com/cedx/base) is distributed under the MIT License.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Defines the alignment of a component.
3
+ */
4
+ export declare const Alignment: Readonly<{
5
+ /**
6
+ * The element is aligned at the start.
7
+ */
8
+ Start: "Start";
9
+ /**
10
+ * The element is aligned in the center.
11
+ */
12
+ Center: "Center";
13
+ /**
14
+ * The element is aligned at the end.
15
+ */
16
+ End: "End";
17
+ }>;
18
+ /**
19
+ * Defines the alignment of a component.
20
+ */
21
+ export type Alignment = typeof Alignment[keyof typeof Alignment];
22
+ //# sourceMappingURL=Alignment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Alignment.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Alignment.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS;IAErB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Defines the alignment of a component.
3
+ */
4
+ export const Alignment = Object.freeze({
5
+ /**
6
+ * The element is aligned at the start.
7
+ */
8
+ Start: "Start",
9
+ /**
10
+ * The element is aligned in the center.
11
+ */
12
+ Center: "Center",
13
+ /**
14
+ * The element is aligned at the end.
15
+ */
16
+ End: "End"
17
+ });
@@ -0,0 +1,82 @@
1
+ import { Context } from "../Context.js";
2
+ import { DialogResult } from "../DialogResult.js";
3
+ import { Variant } from "../Variant.js";
4
+ /**
5
+ * Represents a dialog box button.
6
+ */
7
+ export interface IDialogButton {
8
+ /**
9
+ * A contextual modifier.
10
+ */
11
+ context?: Context | null;
12
+ /**
13
+ * The button icon.
14
+ */
15
+ icon?: string | null;
16
+ /**
17
+ * The button label.
18
+ */
19
+ label?: string;
20
+ /**
21
+ * The button value.
22
+ */
23
+ value?: DialogResult;
24
+ /**
25
+ * A tone variant.
26
+ */
27
+ variant?: Variant | null;
28
+ }
29
+ /**
30
+ * Represents a dialog box button.
31
+ */
32
+ export declare class DialogButton extends HTMLElement {
33
+ #private;
34
+ /**
35
+ * The list of observed attributes.
36
+ */
37
+ static readonly observedAttributes: string[];
38
+ /**
39
+ * A contextual modifier.
40
+ */
41
+ get context(): Context | null;
42
+ set context(value: Context | null);
43
+ /**
44
+ * The button icon.
45
+ */
46
+ get icon(): string | null;
47
+ set icon(value: string | null);
48
+ /**
49
+ * The button label.
50
+ */
51
+ get label(): string;
52
+ set label(value: string);
53
+ /**
54
+ * The button value.
55
+ */
56
+ get value(): DialogResult;
57
+ set value(value: DialogResult);
58
+ /**
59
+ * A tone variant.
60
+ */
61
+ get variant(): Variant | null;
62
+ set variant(value: Variant | null);
63
+ /**
64
+ * Method invoked when an attribute has been changed.
65
+ * @param attribute The attribute name.
66
+ * @param oldValue The previous attribute value.
67
+ * @param newValue The new attribute value.
68
+ */
69
+ attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
70
+ }
71
+ /**
72
+ * Declaration merging.
73
+ */
74
+ declare global {
75
+ /**
76
+ * The map of HTML tag names.
77
+ */
78
+ interface HTMLElementTagNameMap {
79
+ "dialog-button": DialogButton;
80
+ }
81
+ }
82
+ //# sourceMappingURL=DialogButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DialogButton.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/DialogButton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAsB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,OAAO,EAAsB,MAAM,eAAe,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,aAAa;IAE7B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW;;IAE5C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAoD;IAStF;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,GAAC,IAAI,CAG1B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAC,IAAI,EAE9B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,GAAC,IAAI,CAGtB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAC,IAAI,EAE1B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,YAAY,CAGxB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,YAAY,EAE5B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,GAAC,IAAI,CAG1B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAC,IAAI,EAE9B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;CA6D/F;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,eAAe,EAAE,YAAY,CAAC;KAC9B;CACD"}
@@ -0,0 +1,142 @@
1
+ import { Context, toCss as contextCss } from "../Context.js";
2
+ import { DialogResult } from "../DialogResult.js";
3
+ import { Variant, toCss as variantCss } from "../Variant.js";
4
+ /**
5
+ * Represents a dialog box button.
6
+ */
7
+ export class DialogButton extends HTMLElement {
8
+ /**
9
+ * The list of observed attributes.
10
+ */
11
+ static observedAttributes = ["context", "icon", "label", "value", "variant"];
12
+ /**
13
+ * Registers the component.
14
+ */
15
+ static {
16
+ customElements.define("dialog-button", this);
17
+ }
18
+ /**
19
+ * A contextual modifier.
20
+ */
21
+ get context() {
22
+ const value = this.getAttribute("context");
23
+ return Object.values(Context).includes(value) ? value : null;
24
+ }
25
+ set context(value) {
26
+ this.toggleAttribute("context", Boolean(value));
27
+ }
28
+ /**
29
+ * The button icon.
30
+ */
31
+ get icon() {
32
+ const value = this.getAttribute("icon") ?? "";
33
+ return value.trim() || null;
34
+ }
35
+ set icon(value) {
36
+ this.toggleAttribute("icon", Boolean(value));
37
+ }
38
+ /**
39
+ * The button label.
40
+ */
41
+ get label() {
42
+ return (this.getAttribute("label") ?? "").trim();
43
+ }
44
+ set label(value) {
45
+ this.setAttribute("label", value);
46
+ }
47
+ /**
48
+ * The button value.
49
+ */
50
+ get value() {
51
+ const value = this.getAttribute("value");
52
+ return Object.values(DialogResult).includes(value) ? value : DialogResult.None;
53
+ }
54
+ set value(value) {
55
+ this.setAttribute("value", value);
56
+ }
57
+ /**
58
+ * A tone variant.
59
+ */
60
+ get variant() {
61
+ const value = this.getAttribute("variant");
62
+ return Object.values(Variant).includes(value) ? value : null;
63
+ }
64
+ set variant(value) {
65
+ this.toggleAttribute("context", Boolean(value));
66
+ }
67
+ /**
68
+ * Method invoked when an attribute has been changed.
69
+ * @param attribute The attribute name.
70
+ * @param oldValue The previous attribute value.
71
+ * @param newValue The new attribute value.
72
+ */
73
+ attributeChangedCallback(attribute, oldValue, newValue) {
74
+ if (newValue != oldValue)
75
+ switch (attribute) {
76
+ case "context":
77
+ this.#updateContext(Object.values(Context).includes(newValue) ? newValue : null);
78
+ break;
79
+ case "icon":
80
+ this.#updateIcon(newValue);
81
+ break;
82
+ case "label":
83
+ this.#updateLabel(newValue ?? "");
84
+ break;
85
+ case "value":
86
+ this.#updateValue(Object.values(DialogResult).includes(newValue) ? newValue : DialogResult.None);
87
+ break;
88
+ case "variant":
89
+ this.#updateVariant(Object.values(Variant).includes(newValue) ? newValue : null);
90
+ break;
91
+ // No default
92
+ }
93
+ }
94
+ /**
95
+ * Updates the contextual modifier.
96
+ * @param value The new value.
97
+ */
98
+ #updateContext(value) {
99
+ const { classList } = this.querySelector("button");
100
+ classList.remove(...Object.values(Context).map(context => `btn-${contextCss(context)}`));
101
+ if (value)
102
+ classList.add(`btn-${contextCss(value)}`);
103
+ }
104
+ /**
105
+ * Updates the button icon.
106
+ * @param value The new value.
107
+ */
108
+ #updateIcon(value) {
109
+ const element = this.querySelector(".icon");
110
+ const icon = (value ?? "").trim();
111
+ element.textContent = icon;
112
+ element.hidden = !icon;
113
+ }
114
+ /**
115
+ * Updates the button label.
116
+ * @param value The new value.
117
+ */
118
+ #updateLabel(value) {
119
+ const element = this.querySelector("span");
120
+ const label = value.trim();
121
+ element.textContent = label;
122
+ element.hidden = !label;
123
+ this.querySelector(".icon").classList.toggle("me-1", !element.hidden);
124
+ }
125
+ /**
126
+ * Updates the button value.
127
+ * @param value The new value.
128
+ */
129
+ #updateValue(value) {
130
+ this.querySelector("button").value = value;
131
+ }
132
+ /**
133
+ * Updates the tone variant.
134
+ * @param value The new value.
135
+ */
136
+ #updateVariant(value) {
137
+ const { classList } = this.querySelector("button");
138
+ classList.remove(...Object.values(Variant).map(variant => `btn-${variantCss(variant)}`));
139
+ if (value)
140
+ classList.add(`btn-${variantCss(value)}`);
141
+ }
142
+ }
@@ -31,7 +31,7 @@ export class KeyboardAccelerator extends HTMLElement {
31
31
  .reduce((modifiers, value) => modifiers | (KeyboardAccelerator.#modifiers.get(value) ?? 0), KeyboardModifiers.None);
32
32
  }
33
33
  set modifiers(value) {
34
- this.setAttribute("modifiers", KeyboardAccelerator.#modifiers.entries()
34
+ this.setAttribute("modifiers", !value ? "None" : KeyboardAccelerator.#modifiers.entries()
35
35
  .filter(([, flag]) => (value & flag) != 0)
36
36
  .map(([key]) => key)
37
37
  .toArray().join(", "));
@@ -1,5 +1,5 @@
1
+ import { Alignment } from "../Alignment.js";
1
2
  import { AppTheme } from "../AppTheme.js";
2
- import { MenuAlignment } from "../MenuAlignment.js";
3
3
  /**
4
4
  * A dropdown menu for switching the application theme.
5
5
  */
@@ -16,8 +16,8 @@ export declare class ThemeDropdown extends HTMLElement {
16
16
  /**
17
17
  * The alignment of the dropdown menu.
18
18
  */
19
- get alignment(): MenuAlignment;
20
- set alignment(value: MenuAlignment);
19
+ get alignment(): Alignment;
20
+ set alignment(value: Alignment);
21
21
  /**
22
22
  * The current application theme.
23
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAE7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAsC;IAYxE;;OAEG;;IAaH;;OAEG;IACH,IAAI,SAAS,IAAI,aAAa,CAG7B;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,aAAa,EAEjC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAe/F;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAQzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CAkDZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
1
+ {"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAE7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAsC;IAYxE;;OAEG;;IAaH;;OAEG;IACH,IAAI,SAAS,IAAI,SAAS,CAGzB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,EAE7B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAe/F;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAQzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CAgDZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
@@ -1,6 +1,6 @@
1
1
  import { Dropdown } from "bootstrap";
2
+ import { Alignment } from "../Alignment.js";
2
3
  import { AppTheme, getIcon } from "../AppTheme.js";
3
- import { MenuAlignment } from "../MenuAlignment.js";
4
4
  /**
5
5
  * A dropdown menu for switching the application theme.
6
6
  */
@@ -36,7 +36,7 @@ export class ThemeDropdown extends HTMLElement {
36
36
  */
37
37
  get alignment() {
38
38
  const value = this.getAttribute("alignment");
39
- return Object.values(MenuAlignment).includes(value) ? value : MenuAlignment.End;
39
+ return Object.values(Alignment).includes(value) ? value : Alignment.End;
40
40
  }
41
41
  set alignment(value) {
42
42
  this.setAttribute("alignment", value);
@@ -81,7 +81,7 @@ export class ThemeDropdown extends HTMLElement {
81
81
  if (newValue != oldValue)
82
82
  switch (attribute) {
83
83
  case "alignment":
84
- this.#updateAlignment(Object.values(MenuAlignment).includes(newValue) ? newValue : MenuAlignment.End);
84
+ this.#updateAlignment(Object.values(Alignment).includes(newValue) ? newValue : Alignment.End);
85
85
  break;
86
86
  case "apptheme":
87
87
  this.#updateAppTheme(Object.values(AppTheme).includes(newValue) ? newValue : AppTheme.System);
@@ -149,11 +149,7 @@ export class ThemeDropdown extends HTMLElement {
149
149
  * @param value The new value.
150
150
  */
151
151
  #updateAlignment(value) {
152
- const { classList } = this.querySelector(".dropdown-menu");
153
- if (value == MenuAlignment.End)
154
- classList.add("dropdown-menu-end");
155
- else
156
- classList.remove("dropdown-menu-end");
152
+ this.querySelector(".dropdown-menu").classList.toggle("dropdown-menu-end", value == Alignment.End);
157
153
  }
158
154
  /**
159
155
  * Updates the application theme.
@@ -1,4 +1,41 @@
1
1
  import { Context } from "../Context.js";
2
+ /**
3
+ * Represents a notification.
4
+ */
5
+ export interface IToast {
6
+ /**
7
+ * Value indicating whether to apply a fade transition.
8
+ */
9
+ animation?: boolean;
10
+ /**
11
+ * Value indicating whether to automatically hide the toast.
12
+ */
13
+ autoHide?: boolean;
14
+ /**
15
+ * The child content displayed in the body.
16
+ */
17
+ body: DocumentFragment | string;
18
+ /**
19
+ * The title displayed in the header.
20
+ */
21
+ caption: string;
22
+ /**
23
+ * The default contextual modifier.
24
+ */
25
+ context?: Context;
26
+ /**
27
+ * The culture used to format the relative time.
28
+ */
29
+ culture?: Intl.Locale;
30
+ /**
31
+ * The delay, in milliseconds, to hide the toast.
32
+ */
33
+ delay?: number;
34
+ /**
35
+ * The icon displayed next to the caption.
36
+ */
37
+ icon?: string | null;
38
+ }
2
39
  /**
3
40
  * Represents a notification.
4
41
  */
@@ -18,15 +55,15 @@ export declare class Toast extends HTMLElement {
18
55
  */
19
56
  get autoHide(): boolean;
20
57
  set autoHide(value: boolean);
58
+ /**
59
+ * The child content displayed in the body.
60
+ */
61
+ set body(value: DocumentFragment);
21
62
  /**
22
63
  * The title displayed in the header.
23
64
  */
24
65
  get caption(): string;
25
66
  set caption(value: string);
26
- /**
27
- * The child content displayed in the body.
28
- */
29
- set childContent(value: DocumentFragment);
30
67
  /**
31
68
  * A contextual modifier.
32
69
  */
@@ -49,8 +86,8 @@ export declare class Toast extends HTMLElement {
49
86
  /**
50
87
  * The icon displayed next to the caption.
51
88
  */
52
- get icon(): string;
53
- set icon(value: string);
89
+ get icon(): string | null;
90
+ set icon(value: string | null);
54
91
  /**
55
92
  * Value indicating whether to initially show this toast.
56
93
  */
@@ -63,6 +100,10 @@ export declare class Toast extends HTMLElement {
63
100
  * @param newValue The new attribute value.
64
101
  */
65
102
  attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
103
+ /**
104
+ * Closes this toast.
105
+ */
106
+ close(): void;
66
107
  /**
67
108
  * Method invoked when this component is connected.
68
109
  */
@@ -71,10 +112,6 @@ export declare class Toast extends HTMLElement {
71
112
  * Method invoked when this component is disconnected.
72
113
  */
73
114
  disconnectedCallback(): void;
74
- /**
75
- * Hides this toast.
76
- */
77
- hide(): void;
78
115
  /**
79
116
  * Shows this toast.
80
117
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toast.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAiB,MAAM,eAAe,CAAC;AAEtD;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;;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AO,IAAI,OAAO,CAGrB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,IAAI,CAAC,MAAM,CAGzB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAE7B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,GAAC,IAAI,CAGtB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAC,IAAI,EAE1B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAY/F;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,iBAAiB,IAAI,IAAI;IASzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;CA+EZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,cAAc,EAAE,KAAK,CAAC;KACtB;CACD"}
@@ -7,7 +7,7 @@ export class Toast extends HTMLElement {
7
7
  /**
8
8
  * The list of observed attributes.
9
9
  */
10
- static observedAttributes = ["caption", "context", "culture", "icon", "open"];
10
+ static observedAttributes = ["animation", "caption", "context", "culture", "icon", "open"];
11
11
  /**
12
12
  * The time units.
13
13
  */
@@ -41,10 +41,7 @@ export class Toast extends HTMLElement {
41
41
  return this.hasAttribute("animation");
42
42
  }
43
43
  set animation(value) {
44
- if (value)
45
- this.setAttribute("animation", "");
46
- else
47
- this.removeAttribute("animation");
44
+ this.toggleAttribute("animation", value);
48
45
  }
49
46
  /**
50
47
  * Value indicating whether to automatically hide this toast.
@@ -53,10 +50,13 @@ export class Toast extends HTMLElement {
53
50
  return this.hasAttribute("autohide");
54
51
  }
55
52
  set autoHide(value) {
56
- if (value)
57
- this.setAttribute("autohide", "");
58
- else
59
- this.removeAttribute("autohide");
53
+ this.toggleAttribute("autohide", value);
54
+ }
55
+ /**
56
+ * The child content displayed in the body.
57
+ */
58
+ set body(value) {
59
+ this.querySelector(".toast-body").replaceChildren(...value.childNodes);
60
60
  }
61
61
  /**
62
62
  * The title displayed in the header.
@@ -67,12 +67,6 @@ export class Toast extends HTMLElement {
67
67
  set caption(value) {
68
68
  this.setAttribute("caption", value);
69
69
  }
70
- /**
71
- * The child content displayed in the body.
72
- */
73
- set childContent(value) {
74
- this.querySelector(".toast-body").replaceChildren(...value.childNodes);
75
- }
76
70
  /**
77
71
  * A contextual modifier.
78
72
  */
@@ -114,10 +108,10 @@ export class Toast extends HTMLElement {
114
108
  */
115
109
  get icon() {
116
110
  const value = this.getAttribute("icon") ?? "";
117
- return value.trim() || getIcon(this.context);
111
+ return value.trim() || null;
118
112
  }
119
113
  set icon(value) {
120
- this.setAttribute("icon", value);
114
+ this.toggleAttribute("icon", Boolean(value));
121
115
  }
122
116
  /**
123
117
  * Value indicating whether to initially show this toast.
@@ -126,10 +120,7 @@ export class Toast extends HTMLElement {
126
120
  return this.hasAttribute("open");
127
121
  }
128
122
  set open(value) {
129
- if (value)
130
- this.setAttribute("open", "");
131
- else
132
- this.removeAttribute("open");
123
+ this.toggleAttribute("open", value);
133
124
  }
134
125
  /**
135
126
  * Method invoked when an attribute has been changed.
@@ -140,6 +131,9 @@ export class Toast extends HTMLElement {
140
131
  attributeChangedCallback(attribute, oldValue, newValue) {
141
132
  if (newValue != oldValue)
142
133
  switch (attribute) {
134
+ case "animation":
135
+ this.#updateAnimation(newValue != null);
136
+ break;
143
137
  case "caption":
144
138
  this.#updateCaption(newValue ?? "");
145
139
  break;
@@ -150,18 +144,25 @@ export class Toast extends HTMLElement {
150
144
  this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, { style: "long" });
151
145
  break;
152
146
  case "icon":
153
- this.#updateIcon(newValue ?? "");
147
+ this.#updateIcon(newValue);
154
148
  break;
155
149
  case "open":
156
- this.#updateVisibility();
150
+ this.#updateVisibility(newValue != null);
151
+ break;
157
152
  // No default
158
153
  }
159
154
  }
155
+ /**
156
+ * Closes this toast.
157
+ */
158
+ close() {
159
+ this.#toast.hide();
160
+ }
160
161
  /**
161
162
  * Method invoked when this component is connected.
162
163
  */
163
164
  connectedCallback() {
164
- const toast = this.querySelector(".toast");
165
+ const toast = this.firstElementChild;
165
166
  toast.addEventListener("hidden.bs.toast", () => clearInterval(this.#timer));
166
167
  toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(this.#updateElapsedTime, 1_000));
167
168
  const { animation, autoHide: autohide, delay } = this;
@@ -174,12 +175,6 @@ export class Toast extends HTMLElement {
174
175
  clearInterval(this.#timer);
175
176
  this.#toast.dispose();
176
177
  }
177
- /**
178
- * Hides this toast.
179
- */
180
- hide() {
181
- this.#toast.hide();
182
- }
183
178
  /**
184
179
  * Shows this toast.
185
180
  */
@@ -203,6 +198,13 @@ export class Toast extends HTMLElement {
203
198
  }
204
199
  return this.#formatter.format(Math.ceil(-elapsed), Toast.#timeUnits[index]);
205
200
  }
201
+ /**
202
+ * Updates the toast animation.
203
+ * @param value The new value.
204
+ */
205
+ #updateAnimation(value) {
206
+ this.firstElementChild.classList.toggle("fade", value);
207
+ }
206
208
  /**
207
209
  * Updates the title displayed in the header.
208
210
  * @param value The new value.
@@ -211,7 +213,7 @@ export class Toast extends HTMLElement {
211
213
  this.querySelector(".toast-header b").textContent = value.trim();
212
214
  }
213
215
  /**
214
- * Updates the title displayed in the header.
216
+ * Updates the contextual modifier.
215
217
  * @param value The new value.
216
218
  */
217
219
  #updateContext(value) {
@@ -235,19 +237,13 @@ export class Toast extends HTMLElement {
235
237
  * @param value The new value.
236
238
  */
237
239
  #updateIcon(value) {
238
- this.querySelector(".toast-header .icon").textContent = value.trim() || getIcon(this.context);
240
+ this.querySelector(".toast-header .icon").textContent = (value ?? "").trim() || getIcon(this.context);
239
241
  }
240
242
  /**
241
243
  * Updates the toast visibility.
244
+ * @param value The new value.
242
245
  */
243
- #updateVisibility() {
244
- const { classList } = this.firstElementChild;
245
- if (!this.open)
246
- classList.remove("show");
247
- else {
248
- if (this.animation)
249
- classList.add("fade");
250
- classList.add("show");
251
- }
246
+ #updateVisibility(value) {
247
+ this.firstElementChild.classList.toggle("show", value);
252
248
  }
253
249
  }