@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.
- package/ReadMe.md +4 -4
- package/lib/UI/Alignment.d.ts +22 -0
- package/lib/UI/Alignment.d.ts.map +1 -0
- package/lib/UI/Alignment.js +17 -0
- package/lib/UI/Components/DialogButton.d.ts +82 -0
- package/lib/UI/Components/DialogButton.d.ts.map +1 -0
- package/lib/UI/Components/DialogButton.js +142 -0
- package/lib/UI/Components/KeyboardAccelerator.js +1 -1
- package/lib/UI/Components/ThemeDropdown.d.ts +3 -3
- package/lib/UI/Components/ThemeDropdown.d.ts.map +1 -1
- package/lib/UI/Components/ThemeDropdown.js +4 -8
- package/lib/UI/Components/Toast.d.ts +47 -10
- package/lib/UI/Components/Toast.d.ts.map +1 -1
- package/lib/UI/Components/Toast.js +37 -41
- package/lib/UI/Components/Toaster.d.ts +5 -41
- package/lib/UI/Components/Toaster.d.ts.map +1 -1
- package/lib/UI/Components/Toaster.js +9 -14
- package/lib/UI/DialogResult.d.ts +42 -0
- package/lib/UI/DialogResult.d.ts.map +1 -0
- package/lib/UI/DialogResult.js +37 -0
- package/package.json +2 -3
- package/src/Client/UI/Alignment.ts +25 -0
- package/src/Client/UI/Components/DialogButton.ts +187 -0
- package/src/Client/UI/Components/KeyboardAccelerator.ts +1 -1
- package/src/Client/UI/Components/ThemeDropdown.ts +8 -10
- package/src/Client/UI/Components/Toast.ts +89 -50
- package/src/Client/UI/Components/Toaster.ts +12 -58
- package/src/Client/UI/DialogResult.ts +50 -0
- package/lib/UI/Components/ComponentBase.d.ts +0 -24
- package/lib/UI/Components/ComponentBase.d.ts.map +0 -1
- package/lib/UI/Components/ComponentBase.js +0 -29
- package/lib/UI/MenuAlignment.d.ts +0 -18
- package/lib/UI/MenuAlignment.d.ts.map +0 -1
- package/lib/UI/MenuAlignment.js +0 -13
- package/src/Client/UI/Components/ComponentBase.ts +0 -34
- package/src/Client/UI/MenuAlignment.ts +0 -20
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
import { Context } from "../Context.js";
|
|
2
2
|
import { Position } from "../Position.js";
|
|
3
|
-
|
|
4
|
-
* Represents a notification.
|
|
5
|
-
*/
|
|
6
|
-
export interface IToast {
|
|
7
|
-
/**
|
|
8
|
-
* Value indicating whether to apply a fade transition.
|
|
9
|
-
*/
|
|
10
|
-
animation?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Value indicating whether to automatically hide the toast.
|
|
13
|
-
*/
|
|
14
|
-
autoHide?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* The title displayed in the header.
|
|
17
|
-
*/
|
|
18
|
-
caption: string;
|
|
19
|
-
/**
|
|
20
|
-
* The child content displayed in the body.
|
|
21
|
-
*/
|
|
22
|
-
childContent: DocumentFragment | string;
|
|
23
|
-
/**
|
|
24
|
-
* The default contextual modifier.
|
|
25
|
-
*/
|
|
26
|
-
context?: Context;
|
|
27
|
-
/**
|
|
28
|
-
* The culture used to format the relative time.
|
|
29
|
-
*/
|
|
30
|
-
culture?: Intl.Locale;
|
|
31
|
-
/**
|
|
32
|
-
* The delay, in milliseconds, to hide the toast.
|
|
33
|
-
*/
|
|
34
|
-
delay?: number;
|
|
35
|
-
/**
|
|
36
|
-
* The icon displayed next to the caption.
|
|
37
|
-
*/
|
|
38
|
-
icon?: string;
|
|
39
|
-
}
|
|
3
|
+
import type { IToast } from "./Toast.js";
|
|
40
4
|
/**
|
|
41
5
|
* Manages the notifications.
|
|
42
6
|
*/
|
|
@@ -74,8 +38,8 @@ export declare class Toaster extends HTMLElement {
|
|
|
74
38
|
/**
|
|
75
39
|
* The default icon displayed next to the captions.
|
|
76
40
|
*/
|
|
77
|
-
get icon(): string;
|
|
78
|
-
set icon(value: string);
|
|
41
|
+
get icon(): string | null;
|
|
42
|
+
set icon(value: string | null);
|
|
79
43
|
/**
|
|
80
44
|
* The toaster placement.
|
|
81
45
|
*/
|
|
@@ -92,9 +56,9 @@ export declare class Toaster extends HTMLElement {
|
|
|
92
56
|
* Shows a toast.
|
|
93
57
|
* @param context The contextual modifier.
|
|
94
58
|
* @param caption The title displayed in the toast header.
|
|
95
|
-
* @param
|
|
59
|
+
* @param body The child content displayed in the toast body.
|
|
96
60
|
*/
|
|
97
|
-
notify(context: Context, caption: string,
|
|
61
|
+
notify(context: Context, caption: string, body: DocumentFragment | string): void;
|
|
98
62
|
/**
|
|
99
63
|
* Shows the specified toast.
|
|
100
64
|
* @param toast The toast to show.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toaster.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAC,QAAQ,EAAQ,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Toaster.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAC,QAAQ,EAAQ,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,WAAW;;IAEvC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAgB;IAclD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAE3B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAE1B;IAED;;OAEG;IACH,IAAI,OAAO,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,IAAI,IAAI,MAAM,GAAC,IAAI,CAGtB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAC,IAAI,EAE1B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAS/F;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAC,MAAM,GAAG,IAAI;IAI9E;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CA2BzB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,OAAO,CAAC;KAC7B;CACD"}
|
|
@@ -26,10 +26,7 @@ export class Toaster extends HTMLElement {
|
|
|
26
26
|
return this.hasAttribute("animation");
|
|
27
27
|
}
|
|
28
28
|
set animation(value) {
|
|
29
|
-
|
|
30
|
-
this.setAttribute("animation", "");
|
|
31
|
-
else
|
|
32
|
-
this.removeAttribute("animation");
|
|
29
|
+
this.toggleAttribute("animation", value);
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* Value indicating whether to automatically hide the toasts.
|
|
@@ -38,10 +35,7 @@ export class Toaster extends HTMLElement {
|
|
|
38
35
|
return this.hasAttribute("autohide");
|
|
39
36
|
}
|
|
40
37
|
set autoHide(value) {
|
|
41
|
-
|
|
42
|
-
this.setAttribute("autohide", "");
|
|
43
|
-
else
|
|
44
|
-
this.removeAttribute("autohide");
|
|
38
|
+
this.toggleAttribute("autohide", value);
|
|
45
39
|
}
|
|
46
40
|
/**
|
|
47
41
|
* The default contextual modifier.
|
|
@@ -77,10 +71,11 @@ export class Toaster extends HTMLElement {
|
|
|
77
71
|
* The default icon displayed next to the captions.
|
|
78
72
|
*/
|
|
79
73
|
get icon() {
|
|
80
|
-
|
|
74
|
+
const value = this.getAttribute("icon") ?? "";
|
|
75
|
+
return value.trim() || null;
|
|
81
76
|
}
|
|
82
77
|
set icon(value) {
|
|
83
|
-
this.
|
|
78
|
+
this.toggleAttribute("icon", Boolean(value));
|
|
84
79
|
}
|
|
85
80
|
/**
|
|
86
81
|
* The toaster placement.
|
|
@@ -111,10 +106,10 @@ export class Toaster extends HTMLElement {
|
|
|
111
106
|
* Shows a toast.
|
|
112
107
|
* @param context The contextual modifier.
|
|
113
108
|
* @param caption The title displayed in the toast header.
|
|
114
|
-
* @param
|
|
109
|
+
* @param body The child content displayed in the toast body.
|
|
115
110
|
*/
|
|
116
|
-
notify(context, caption,
|
|
117
|
-
this.show({ context, caption,
|
|
111
|
+
notify(context, caption, body) {
|
|
112
|
+
this.show({ context, caption, body });
|
|
118
113
|
}
|
|
119
114
|
/**
|
|
120
115
|
* Shows the specified toast.
|
|
@@ -126,8 +121,8 @@ export class Toaster extends HTMLElement {
|
|
|
126
121
|
item.appendChild(this.#toastTemplate.cloneNode(true).querySelector(".toast"));
|
|
127
122
|
item.animation = toast.animation ?? this.animation;
|
|
128
123
|
item.autoHide = toast.autoHide ?? this.autoHide;
|
|
124
|
+
item.body = typeof toast.body == "string" ? createDocumentFragment(toast.body) : toast.body;
|
|
129
125
|
item.caption = toast.caption;
|
|
130
|
-
item.childContent = typeof toast.childContent == "string" ? createDocumentFragment(toast.childContent) : toast.childContent;
|
|
131
126
|
item.context = toast.context ?? this.context;
|
|
132
127
|
item.culture = toast.culture ?? this.culture;
|
|
133
128
|
item.delay = toast.delay ?? this.delay;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specifies the return value of a dialog box.
|
|
3
|
+
*/
|
|
4
|
+
export declare const DialogResult: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* The dialog box does not return any value.
|
|
7
|
+
*/
|
|
8
|
+
None: "None";
|
|
9
|
+
/**
|
|
10
|
+
* The return value of the dialog box is "OK".
|
|
11
|
+
*/
|
|
12
|
+
OK: "OK";
|
|
13
|
+
/**
|
|
14
|
+
* The return value of the dialog box is "Cancel".
|
|
15
|
+
*/
|
|
16
|
+
Cancel: "Cancel";
|
|
17
|
+
/**
|
|
18
|
+
* The return value of the dialog box is "Abort".
|
|
19
|
+
*/
|
|
20
|
+
Abort: "Abort";
|
|
21
|
+
/**
|
|
22
|
+
* The return value of the dialog box is "Retry".
|
|
23
|
+
*/
|
|
24
|
+
Retry: "Retry";
|
|
25
|
+
/**
|
|
26
|
+
* The return value of the dialog box is "Ignore".
|
|
27
|
+
*/
|
|
28
|
+
Ignore: "Ignore";
|
|
29
|
+
/**
|
|
30
|
+
* The return value of the dialog box is "Yes".
|
|
31
|
+
*/
|
|
32
|
+
Yes: "Yes";
|
|
33
|
+
/**
|
|
34
|
+
* The return value of the dialog box is "No".
|
|
35
|
+
*/
|
|
36
|
+
No: "No";
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies the return value of a dialog box.
|
|
40
|
+
*/
|
|
41
|
+
export type DialogResult = typeof DialogResult[keyof typeof DialogResult];
|
|
42
|
+
//# sourceMappingURL=DialogResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogResult.d.ts","sourceRoot":"","sources":["../../src/Client/UI/DialogResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,YAAY;IAExB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specifies the return value of a dialog box.
|
|
3
|
+
*/
|
|
4
|
+
export const DialogResult = Object.freeze({
|
|
5
|
+
/**
|
|
6
|
+
* The dialog box does not return any value.
|
|
7
|
+
*/
|
|
8
|
+
None: "None",
|
|
9
|
+
/**
|
|
10
|
+
* The return value of the dialog box is "OK".
|
|
11
|
+
*/
|
|
12
|
+
OK: "OK",
|
|
13
|
+
/**
|
|
14
|
+
* The return value of the dialog box is "Cancel".
|
|
15
|
+
*/
|
|
16
|
+
Cancel: "Cancel",
|
|
17
|
+
/**
|
|
18
|
+
* The return value of the dialog box is "Abort".
|
|
19
|
+
*/
|
|
20
|
+
Abort: "Abort",
|
|
21
|
+
/**
|
|
22
|
+
* The return value of the dialog box is "Retry".
|
|
23
|
+
*/
|
|
24
|
+
Retry: "Retry",
|
|
25
|
+
/**
|
|
26
|
+
* The return value of the dialog box is "Ignore".
|
|
27
|
+
*/
|
|
28
|
+
Ignore: "Ignore",
|
|
29
|
+
/**
|
|
30
|
+
* The return value of the dialog box is "Yes".
|
|
31
|
+
*/
|
|
32
|
+
Yes: "Yes",
|
|
33
|
+
/**
|
|
34
|
+
* The return value of the dialog box is "No".
|
|
35
|
+
*/
|
|
36
|
+
No: "No"
|
|
37
|
+
});
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "@cedx/base",
|
|
8
8
|
"repository": "cedx/base",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.17.0",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@playwright/browser-chromium": "^1.55.0",
|
|
13
13
|
"@types/bootstrap": "^5.2.10",
|
|
@@ -45,8 +45,7 @@
|
|
|
45
45
|
"library"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"bootstrap": ">=5.3.0"
|
|
49
|
-
"lit": ">=3.3.0"
|
|
48
|
+
"bootstrap": ">=5.3.0"
|
|
50
49
|
},
|
|
51
50
|
"publishConfig": {
|
|
52
51
|
"access": "public"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the alignment of a component.
|
|
3
|
+
*/
|
|
4
|
+
export const Alignment = Object.freeze({
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The element is aligned at the start.
|
|
8
|
+
*/
|
|
9
|
+
Start: "Start",
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The element is aligned in the center.
|
|
13
|
+
*/
|
|
14
|
+
Center: "Center",
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The element is aligned at the end.
|
|
18
|
+
*/
|
|
19
|
+
End: "End"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Defines the alignment of a component.
|
|
24
|
+
*/
|
|
25
|
+
export type Alignment = typeof Alignment[keyof typeof Alignment];
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Represents a dialog box button.
|
|
7
|
+
*/
|
|
8
|
+
export interface IDialogButton {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A contextual modifier.
|
|
12
|
+
*/
|
|
13
|
+
context?: Context|null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The button icon.
|
|
17
|
+
*/
|
|
18
|
+
icon?: string|null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The button label.
|
|
22
|
+
*/
|
|
23
|
+
label?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The button value.
|
|
27
|
+
*/
|
|
28
|
+
value?: DialogResult;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A tone variant.
|
|
32
|
+
*/
|
|
33
|
+
variant?: Variant|null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents a dialog box button.
|
|
38
|
+
*/
|
|
39
|
+
export class DialogButton extends HTMLElement {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The list of observed attributes.
|
|
43
|
+
*/
|
|
44
|
+
static readonly observedAttributes = ["context", "icon", "label", "value", "variant"];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Registers the component.
|
|
48
|
+
*/
|
|
49
|
+
static {
|
|
50
|
+
customElements.define("dialog-button", this);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A contextual modifier.
|
|
55
|
+
*/
|
|
56
|
+
get context(): Context|null {
|
|
57
|
+
const value = this.getAttribute("context") as Context;
|
|
58
|
+
return Object.values(Context).includes(value) ? value : null;
|
|
59
|
+
}
|
|
60
|
+
set context(value: Context|null) {
|
|
61
|
+
this.toggleAttribute("context", Boolean(value));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The button icon.
|
|
66
|
+
*/
|
|
67
|
+
get icon(): string|null {
|
|
68
|
+
const value = this.getAttribute("icon") ?? "";
|
|
69
|
+
return value.trim() || null;
|
|
70
|
+
}
|
|
71
|
+
set icon(value: string|null) {
|
|
72
|
+
this.toggleAttribute("icon", Boolean(value));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The button label.
|
|
77
|
+
*/
|
|
78
|
+
get label(): string {
|
|
79
|
+
return (this.getAttribute("label") ?? "").trim();
|
|
80
|
+
}
|
|
81
|
+
set label(value: string) {
|
|
82
|
+
this.setAttribute("label", value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The button value.
|
|
87
|
+
*/
|
|
88
|
+
get value(): DialogResult {
|
|
89
|
+
const value = this.getAttribute("value") as DialogResult;
|
|
90
|
+
return Object.values(DialogResult).includes(value) ? value : DialogResult.None;
|
|
91
|
+
}
|
|
92
|
+
set value(value: DialogResult) {
|
|
93
|
+
this.setAttribute("value", value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A tone variant.
|
|
98
|
+
*/
|
|
99
|
+
get variant(): Variant|null {
|
|
100
|
+
const value = this.getAttribute("variant") as Variant;
|
|
101
|
+
return Object.values(Variant).includes(value) ? value : null;
|
|
102
|
+
}
|
|
103
|
+
set variant(value: Variant|null) {
|
|
104
|
+
this.toggleAttribute("context", Boolean(value));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Method invoked when an attribute has been changed.
|
|
109
|
+
* @param attribute The attribute name.
|
|
110
|
+
* @param oldValue The previous attribute value.
|
|
111
|
+
* @param newValue The new attribute value.
|
|
112
|
+
*/
|
|
113
|
+
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
114
|
+
if (newValue != oldValue) switch (attribute) {
|
|
115
|
+
case "context": this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : null); break;
|
|
116
|
+
case "icon": this.#updateIcon(newValue); break;
|
|
117
|
+
case "label": this.#updateLabel(newValue ?? ""); break;
|
|
118
|
+
case "value": this.#updateValue(Object.values(DialogResult).includes(newValue as DialogResult) ? newValue as DialogResult : DialogResult.None); break;
|
|
119
|
+
case "variant": this.#updateVariant(Object.values(Variant).includes(newValue as Variant) ? newValue as Variant : null); break;
|
|
120
|
+
// No default
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Updates the contextual modifier.
|
|
126
|
+
* @param value The new value.
|
|
127
|
+
*/
|
|
128
|
+
#updateContext(value: Context|null): void {
|
|
129
|
+
const {classList} = this.querySelector("button")!;
|
|
130
|
+
classList.remove(...Object.values(Context).map(context => `btn-${contextCss(context)}`));
|
|
131
|
+
if (value) classList.add(`btn-${contextCss(value)}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Updates the button icon.
|
|
136
|
+
* @param value The new value.
|
|
137
|
+
*/
|
|
138
|
+
#updateIcon(value: string|null): void {
|
|
139
|
+
const element = this.querySelector<HTMLElement>(".icon")!;
|
|
140
|
+
const icon = (value ?? "").trim();
|
|
141
|
+
element.textContent = icon;
|
|
142
|
+
element.hidden = !icon;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Updates the button label.
|
|
147
|
+
* @param value The new value.
|
|
148
|
+
*/
|
|
149
|
+
#updateLabel(value: string): void {
|
|
150
|
+
const element = this.querySelector("span")!;
|
|
151
|
+
const label = value.trim();
|
|
152
|
+
element.textContent = label;
|
|
153
|
+
element.hidden = !label;
|
|
154
|
+
this.querySelector(".icon")!.classList.toggle("me-1", !element.hidden);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Updates the button value.
|
|
159
|
+
* @param value The new value.
|
|
160
|
+
*/
|
|
161
|
+
#updateValue(value: DialogResult): void {
|
|
162
|
+
this.querySelector("button")!.value = value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Updates the tone variant.
|
|
167
|
+
* @param value The new value.
|
|
168
|
+
*/
|
|
169
|
+
#updateVariant(value: Variant|null): void {
|
|
170
|
+
const {classList} = this.querySelector("button")!;
|
|
171
|
+
classList.remove(...Object.values(Variant).map(variant => `btn-${variantCss(variant)}`));
|
|
172
|
+
if (value) classList.add(`btn-${variantCss(value)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Declaration merging.
|
|
178
|
+
*/
|
|
179
|
+
declare global {
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The map of HTML tag names.
|
|
183
|
+
*/
|
|
184
|
+
interface HTMLElementTagNameMap {
|
|
185
|
+
"dialog-button": DialogButton;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -36,7 +36,7 @@ export class KeyboardAccelerator extends HTMLElement {
|
|
|
36
36
|
.reduce<number>((modifiers, value) => modifiers | (KeyboardAccelerator.#modifiers.get(value) ?? 0), KeyboardModifiers.None);
|
|
37
37
|
}
|
|
38
38
|
set modifiers(value: number) {
|
|
39
|
-
this.setAttribute("modifiers", KeyboardAccelerator.#modifiers.entries()
|
|
39
|
+
this.setAttribute("modifiers", !value ? "None" : KeyboardAccelerator.#modifiers.entries()
|
|
40
40
|
.filter(([, flag]) => (value & flag) != 0)
|
|
41
41
|
.map(([key]) => key)
|
|
42
42
|
.toArray().join(", "));
|
|
@@ -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
|
/**
|
|
6
6
|
* A dropdown menu for switching the application theme.
|
|
@@ -40,11 +40,11 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
40
40
|
/**
|
|
41
41
|
* The alignment of the dropdown menu.
|
|
42
42
|
*/
|
|
43
|
-
get alignment():
|
|
44
|
-
const value = this.getAttribute("alignment") as
|
|
45
|
-
return Object.values(
|
|
43
|
+
get alignment(): Alignment {
|
|
44
|
+
const value = this.getAttribute("alignment") as Alignment;
|
|
45
|
+
return Object.values(Alignment).includes(value) ? value : Alignment.End;
|
|
46
46
|
}
|
|
47
|
-
set alignment(value:
|
|
47
|
+
set alignment(value: Alignment) {
|
|
48
48
|
this.setAttribute("alignment", value);
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -90,7 +90,7 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
90
90
|
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
91
91
|
if (newValue != oldValue) switch (attribute) {
|
|
92
92
|
case "alignment":
|
|
93
|
-
this.#updateAlignment(Object.values(
|
|
93
|
+
this.#updateAlignment(Object.values(Alignment).includes(newValue as Alignment) ? newValue as Alignment : Alignment.End);
|
|
94
94
|
break;
|
|
95
95
|
case "apptheme":
|
|
96
96
|
this.#updateAppTheme(Object.values(AppTheme).includes(newValue as AppTheme) ? newValue as AppTheme : AppTheme.System);
|
|
@@ -165,10 +165,8 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
165
165
|
* Updates the alignment of the dropdown menu.
|
|
166
166
|
* @param value The new value.
|
|
167
167
|
*/
|
|
168
|
-
#updateAlignment(value:
|
|
169
|
-
|
|
170
|
-
if (value == MenuAlignment.End) classList.add("dropdown-menu-end");
|
|
171
|
-
else classList.remove("dropdown-menu-end");
|
|
168
|
+
#updateAlignment(value: Alignment): void {
|
|
169
|
+
this.querySelector(".dropdown-menu")!.classList.toggle("dropdown-menu-end", value == Alignment.End);
|
|
172
170
|
}
|
|
173
171
|
|
|
174
172
|
/**
|