@cedx/base 0.12.0 → 0.13.1

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  # Belin.io Base
2
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.12.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
2
+ ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.13.1/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
3
3
 
4
4
  Base library by [Cédric Belin](https://belin.io), full stack developer,
5
5
  implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
@@ -1,6 +1,6 @@
1
1
  import { Context } from "@cedx/base/UI/Context.js";
2
2
  /**
3
- * Manages the notification messages.
3
+ * Represents a notification.
4
4
  */
5
5
  export declare class Toast extends HTMLElement {
6
6
  #private;
@@ -14,7 +14,7 @@ export declare class Toast extends HTMLElement {
14
14
  get animation(): boolean;
15
15
  set animation(value: boolean);
16
16
  /**
17
- * Value indicating whether to automatically hide the notification.
17
+ * Value indicating whether to automatically hide the toast.
18
18
  */
19
19
  get autoHide(): boolean;
20
20
  set autoHide(value: boolean);
@@ -34,7 +34,7 @@ export declare class Toast extends HTMLElement {
34
34
  get culture(): Intl.Locale;
35
35
  set culture(value: Intl.Locale);
36
36
  /**
37
- * The delay, in milliseconds, to hide the notification.
37
+ * The delay, in milliseconds, to hide the toast.
38
38
  */
39
39
  get delay(): number;
40
40
  set delay(value: number);
@@ -71,4 +71,15 @@ export declare class Toast extends HTMLElement {
71
71
  */
72
72
  show(): void;
73
73
  }
74
+ /**
75
+ * Declaration merging.
76
+ */
77
+ declare global {
78
+ /**
79
+ * The map of HTML tag names.
80
+ */
81
+ interface HTMLElementTagNameMap {
82
+ "toaster-item": Toast;
83
+ }
84
+ }
74
85
  //# sourceMappingURL=Toast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toast.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAU,MAAM,0BAA0B,CAAC;AAG1D;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;;IAErC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAA6C;IAuC/E;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAG3B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAG1B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAExB;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,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAGjB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAkB/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IASzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CA+DZ"}
1
+ {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toast.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAiB,MAAM,0BAA0B,CAAC;AAGjE;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;;IAErC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAA6C;IAuC/E;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAG3B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAG1B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAExB;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,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAGjB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAU/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IASzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CA+DZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,cAAc,EAAE,KAAK,CAAC;KACtB;CACD"}
@@ -1,8 +1,8 @@
1
1
  import { Duration } from "@cedx/base/Duration.js";
2
- import { Context, getIcon } from "@cedx/base/UI/Context.js";
2
+ import { Context, getIcon, toCss } from "@cedx/base/UI/Context.js";
3
3
  import { Toast as BootstrapToast } from "bootstrap";
4
4
  /**
5
- * Manages the notification messages.
5
+ * Represents a notification.
6
6
  */
7
7
  export class Toast extends HTMLElement {
8
8
  /**
@@ -52,7 +52,7 @@ export class Toast extends HTMLElement {
52
52
  this.removeAttribute("animation");
53
53
  }
54
54
  /**
55
- * Value indicating whether to automatically hide the notification.
55
+ * Value indicating whether to automatically hide the toast.
56
56
  */
57
57
  get autoHide() {
58
58
  return this.hasAttribute("autohide");
@@ -93,7 +93,7 @@ export class Toast extends HTMLElement {
93
93
  this.setAttribute("culture", value.toString());
94
94
  }
95
95
  /**
96
- * The delay, in milliseconds, to hide the notification.
96
+ * The delay, in milliseconds, to hide the toast.
97
97
  */
98
98
  get delay() {
99
99
  const value = Number(this.getAttribute("delay"));
@@ -202,10 +202,10 @@ export class Toast extends HTMLElement {
202
202
  #updateContext(value) {
203
203
  const contexts = Object.values(Context);
204
204
  let { classList } = this.#header;
205
- classList.remove(...contexts.map(context => `toast-header-${context}`));
205
+ classList.remove(...contexts.map(context => `toast-header-${toCss(context)}`));
206
206
  classList.add(`toast-header-${value}`);
207
207
  ({ classList } = this.#header.querySelector(".icon"));
208
- classList.remove(...contexts.map(context => `text-${context}`));
208
+ classList.remove(...contexts.map(context => `text-${toCss(context)}`));
209
209
  classList.add(`text-${value}`);
210
210
  }
211
211
  /**
@@ -5,19 +5,19 @@ export declare const Context: Readonly<{
5
5
  /**
6
6
  * A danger.
7
7
  */
8
- Danger: "danger";
8
+ Danger: "Danger";
9
9
  /**
10
10
  * A warning.
11
11
  */
12
- Warning: "warning";
12
+ Warning: "Warning";
13
13
  /**
14
14
  * An information.
15
15
  */
16
- Info: "info";
16
+ Info: "Info";
17
17
  /**
18
18
  * A success.
19
19
  */
20
- Success: "success";
20
+ Success: "Success";
21
21
  }>;
22
22
  /**
23
23
  * Defines contextual modifiers.
@@ -29,4 +29,10 @@ export type Context = typeof Context[keyof typeof Context];
29
29
  * @returns The icon corresponding to the specified context.
30
30
  */
31
31
  export declare function getIcon(context: Context): string;
32
+ /**
33
+ * Returns the CSS representation of the specified context.
34
+ * @param context The context.
35
+ * @returns The CSS representation of the specified context.
36
+ */
37
+ export declare function toCss(context: Context): string;
32
38
  //# sourceMappingURL=Context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOhD"}
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOhD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAE9C"}
package/lib/UI/Context.js CHANGED
@@ -5,19 +5,19 @@ export const Context = Object.freeze({
5
5
  /**
6
6
  * A danger.
7
7
  */
8
- Danger: "danger",
8
+ Danger: "Danger",
9
9
  /**
10
10
  * A warning.
11
11
  */
12
- Warning: "warning",
12
+ Warning: "Warning",
13
13
  /**
14
14
  * An information.
15
15
  */
16
- Info: "info",
16
+ Info: "Info",
17
17
  /**
18
18
  * A success.
19
19
  */
20
- Success: "success"
20
+ Success: "Success"
21
21
  });
22
22
  /**
23
23
  * Gets the icon corresponding to the specified context.
@@ -32,3 +32,11 @@ export function getIcon(context) {
32
32
  default: return "info";
33
33
  }
34
34
  }
35
+ /**
36
+ * Returns the CSS representation of the specified context.
37
+ * @param context The context.
38
+ * @returns The CSS representation of the specified context.
39
+ */
40
+ export function toCss(context) {
41
+ return context.toLowerCase();
42
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Defines the placement of an element.
2
+ * Defines the position of an element.
3
3
  */
4
4
  export declare const Position: Readonly<{
5
5
  /**
6
6
  * Top left.
7
7
  */
8
- TopLeft: "TopLeft";
8
+ TopStart: "TopStart";
9
9
  /**
10
10
  * Top center.
11
11
  */
@@ -13,11 +13,11 @@ export declare const Position: Readonly<{
13
13
  /**
14
14
  * Top right.
15
15
  */
16
- TopRight: "TopRight";
16
+ TopEnd: "TopEnd";
17
17
  /**
18
18
  * Middle left.
19
19
  */
20
- MiddleLeft: "MiddleLeft";
20
+ MiddleStart: "MiddleStart";
21
21
  /**
22
22
  * Middle center.
23
23
  */
@@ -25,11 +25,11 @@ export declare const Position: Readonly<{
25
25
  /**
26
26
  * Middle right.
27
27
  */
28
- MiddleRight: "MiddleRight";
28
+ MiddleEnd: "MiddleEnd";
29
29
  /**
30
30
  * Bottom left.
31
31
  */
32
- BottomLeft: "BottomLeft";
32
+ BottomStart: "BottomStart";
33
33
  /**
34
34
  * Bottom center.
35
35
  */
@@ -37,10 +37,16 @@ export declare const Position: Readonly<{
37
37
  /**
38
38
  * Bottom right.
39
39
  */
40
- BottomRight: "BottomRight";
40
+ BottomEnd: "BottomEnd";
41
41
  }>;
42
42
  /**
43
43
  * Defines the placement of an element.
44
44
  */
45
45
  export type Position = typeof Position[keyof typeof Position];
46
+ /**
47
+ * Returns the CSS representation of the specified position.
48
+ * @param position The position.
49
+ * @returns The CSS representation of the specified position.
50
+ */
51
+ export declare function toCss(position: Position): string;
46
52
  //# sourceMappingURL=Position.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Position.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Position.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
1
+ {"version":3,"file":"Position.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Position.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAYhD"}
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Defines the placement of an element.
2
+ * Defines the position of an element.
3
3
  */
4
4
  export const Position = Object.freeze({
5
5
  /**
6
6
  * Top left.
7
7
  */
8
- TopLeft: "TopLeft",
8
+ TopStart: "TopStart",
9
9
  /**
10
10
  * Top center.
11
11
  */
@@ -13,11 +13,11 @@ export const Position = Object.freeze({
13
13
  /**
14
14
  * Top right.
15
15
  */
16
- TopRight: "TopRight",
16
+ TopEnd: "TopEnd",
17
17
  /**
18
18
  * Middle left.
19
19
  */
20
- MiddleLeft: "MiddleLeft",
20
+ MiddleStart: "MiddleStart",
21
21
  /**
22
22
  * Middle center.
23
23
  */
@@ -25,11 +25,11 @@ export const Position = Object.freeze({
25
25
  /**
26
26
  * Middle right.
27
27
  */
28
- MiddleRight: "MiddleRight",
28
+ MiddleEnd: "MiddleEnd",
29
29
  /**
30
30
  * Bottom left.
31
31
  */
32
- BottomLeft: "BottomLeft",
32
+ BottomStart: "BottomStart",
33
33
  /**
34
34
  * Bottom center.
35
35
  */
@@ -37,5 +37,23 @@ export const Position = Object.freeze({
37
37
  /**
38
38
  * Bottom right.
39
39
  */
40
- BottomRight: "BottomRight"
40
+ BottomEnd: "BottomEnd"
41
41
  });
42
+ /**
43
+ * Returns the CSS representation of the specified position.
44
+ * @param position The position.
45
+ * @returns The CSS representation of the specified position.
46
+ */
47
+ export function toCss(position) {
48
+ switch (position) {
49
+ case Position.TopCenter: return "top-0 start-50 translate-middle-x";
50
+ case Position.TopEnd: return "top-0 end-0";
51
+ case Position.MiddleStart: return "top-50 start-0 translate-middle-y";
52
+ case Position.MiddleCenter: return "top-50 start-50 translate-middle";
53
+ case Position.MiddleEnd: return "top-50 end-0 translate-middle-y";
54
+ case Position.BottomStart: return "bottom-0 start-0";
55
+ case Position.BottomCenter: return "bottom-0 start-50 translate-middle-x";
56
+ case Position.BottomEnd: return "bottom-0 end-0";
57
+ default: return "top-0 start-0";
58
+ }
59
+ }
package/lib/UI/Size.d.ts CHANGED
@@ -1,34 +1,40 @@
1
1
  /**
2
- * Defines the size of a component.
2
+ * Defines the size of an element.
3
3
  */
4
4
  export declare const Size: Readonly<{
5
5
  /**
6
6
  * An extra small size.
7
7
  */
8
- ExtraSmall: "xs";
8
+ ExtraSmall: "ExtraSmall";
9
9
  /**
10
10
  * A small size.
11
11
  */
12
- Small: "sm";
12
+ Small: "Small";
13
13
  /**
14
14
  * A medium size.
15
15
  */
16
- Medium: "md";
16
+ Medium: "Medium";
17
17
  /**
18
18
  * A large size.
19
19
  */
20
- Large: "lg";
20
+ Large: "Large";
21
21
  /**
22
22
  * An extra large size.
23
23
  */
24
- ExtraLarge: "xl";
24
+ ExtraLarge: "ExtraLarge";
25
25
  /**
26
26
  * An extra extra large size.
27
27
  */
28
- ExtraExtraLarge: "xxl";
28
+ ExtraExtraLarge: "ExtraExtraLarge";
29
29
  }>;
30
30
  /**
31
- * Defines the size of a component.
31
+ * Defines the size of an element.
32
32
  */
33
33
  export type Size = typeof Size[keyof typeof Size];
34
+ /**
35
+ * Returns the CSS representation of the specified size.
36
+ * @param size The size.
37
+ * @returns The CSS representation of the specified size.
38
+ */
39
+ export declare function toCss(size: Size): string;
34
40
  //# sourceMappingURL=Size.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Size.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Size.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,IAAI;IAEhB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"Size.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Size.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,IAAI;IAEhB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CASxC"}
package/lib/UI/Size.js CHANGED
@@ -1,29 +1,44 @@
1
1
  /**
2
- * Defines the size of a component.
2
+ * Defines the size of an element.
3
3
  */
4
4
  export const Size = Object.freeze({
5
5
  /**
6
6
  * An extra small size.
7
7
  */
8
- ExtraSmall: "xs",
8
+ ExtraSmall: "ExtraSmall",
9
9
  /**
10
10
  * A small size.
11
11
  */
12
- Small: "sm",
12
+ Small: "Small",
13
13
  /**
14
14
  * A medium size.
15
15
  */
16
- Medium: "md",
16
+ Medium: "Medium",
17
17
  /**
18
18
  * A large size.
19
19
  */
20
- Large: "lg",
20
+ Large: "Large",
21
21
  /**
22
22
  * An extra large size.
23
23
  */
24
- ExtraLarge: "xl",
24
+ ExtraLarge: "ExtraLarge",
25
25
  /**
26
26
  * An extra extra large size.
27
27
  */
28
- ExtraExtraLarge: "xxl"
28
+ ExtraExtraLarge: "ExtraExtraLarge"
29
29
  });
30
+ /**
31
+ * Returns the CSS representation of the specified size.
32
+ * @param size The size.
33
+ * @returns The CSS representation of the specified size.
34
+ */
35
+ export function toCss(size) {
36
+ switch (size) {
37
+ case Size.ExtraSmall: return "xs";
38
+ case Size.Small: return "sm";
39
+ case Size.Large: return "lg";
40
+ case Size.ExtraLarge: return "xl";
41
+ case Size.ExtraExtraLarge: return "xxl";
42
+ default: return "md";
43
+ }
44
+ }
@@ -5,22 +5,28 @@ export declare const Variant: Readonly<{
5
5
  /**
6
6
  * A dark variant.
7
7
  */
8
- Dark: "dark";
8
+ Dark: "Dark";
9
9
  /**
10
10
  * A light variant.
11
11
  */
12
- Light: "light";
12
+ Light: "Light";
13
13
  /**
14
14
  * A primary variant.
15
15
  */
16
- Primary: "primary";
16
+ Primary: "Primary";
17
17
  /**
18
18
  * A secondary variant.
19
19
  */
20
- Secondary: "secondary";
20
+ Secondary: "Secondary";
21
21
  }>;
22
22
  /**
23
23
  * Defines tone variants.
24
24
  */
25
25
  export type Variant = typeof Variant[keyof typeof Variant];
26
+ /**
27
+ * Returns the CSS representation of the specified variant.
28
+ * @param variant The variant.
29
+ * @returns The CSS representation of the specified variant.
30
+ */
31
+ export declare function toCss(variant: Variant): string;
26
32
  //# sourceMappingURL=Variant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Variant.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Variant.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"Variant.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Variant.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAE9C"}
package/lib/UI/Variant.js CHANGED
@@ -5,17 +5,25 @@ export const Variant = Object.freeze({
5
5
  /**
6
6
  * A dark variant.
7
7
  */
8
- Dark: "dark",
8
+ Dark: "Dark",
9
9
  /**
10
10
  * A light variant.
11
11
  */
12
- Light: "light",
12
+ Light: "Light",
13
13
  /**
14
14
  * A primary variant.
15
15
  */
16
- Primary: "primary",
16
+ Primary: "Primary",
17
17
  /**
18
18
  * A secondary variant.
19
19
  */
20
- Secondary: "secondary"
20
+ Secondary: "Secondary"
21
21
  });
22
+ /**
23
+ * Returns the CSS representation of the specified variant.
24
+ * @param variant The variant.
25
+ * @returns The CSS representation of the specified variant.
26
+ */
27
+ export function toCss(variant) {
28
+ return variant.toLowerCase();
29
+ }
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.12.0",
10
+ "version": "0.13.1",
11
11
  "devDependencies": {
12
12
  "@playwright/browser-chromium": "^1.55.0",
13
13
  "@types/bootstrap": "^5.2.10",
@@ -1,9 +1,9 @@
1
1
  import {Duration} from "@cedx/base/Duration.js";
2
- import {Context, getIcon} from "@cedx/base/UI/Context.js";
2
+ import {Context, getIcon, toCss} from "@cedx/base/UI/Context.js";
3
3
  import {Toast as BootstrapToast} from "bootstrap";
4
4
 
5
5
  /**
6
- * Manages the notification messages.
6
+ * Represents a notification.
7
7
  */
8
8
  export class Toast extends HTMLElement {
9
9
 
@@ -61,7 +61,7 @@ export class Toast extends HTMLElement {
61
61
  }
62
62
 
63
63
  /**
64
- * Value indicating whether to automatically hide the notification.
64
+ * Value indicating whether to automatically hide the toast.
65
65
  */
66
66
  get autoHide(): boolean {
67
67
  return this.hasAttribute("autohide");
@@ -104,7 +104,7 @@ export class Toast extends HTMLElement {
104
104
  }
105
105
 
106
106
  /**
107
- * The delay, in milliseconds, to hide the notification.
107
+ * The delay, in milliseconds, to hide the toast.
108
108
  */
109
109
  get delay(): number {
110
110
  const value = Number(this.getAttribute("delay"));
@@ -140,18 +140,10 @@ export class Toast extends HTMLElement {
140
140
  */
141
141
  attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
142
142
  if (newValue != oldValue) switch (attribute) {
143
- case "caption":
144
- this.#updateCaption(newValue ?? "");
145
- break;
146
- case "context":
147
- this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : Context.Info);
148
- break;
149
- case "culture":
150
- this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, {style: "long"});
151
- break;
152
- case "icon":
153
- this.#updateIcon(newValue ?? "")
154
- break;
143
+ case "caption": this.#updateCaption(newValue ?? ""); break;
144
+ case "context": this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : Context.Info); break;
145
+ case "culture": this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, {style: "long"}); break;
146
+ case "icon": this.#updateIcon(newValue ?? ""); break;
155
147
  // No default
156
148
  }
157
149
  }
@@ -226,11 +218,11 @@ export class Toast extends HTMLElement {
226
218
  const contexts = Object.values(Context);
227
219
 
228
220
  let {classList} = this.#header;
229
- classList.remove(...contexts.map(context => `toast-header-${context}`));
221
+ classList.remove(...contexts.map(context => `toast-header-${toCss(context)}`));
230
222
  classList.add(`toast-header-${value}`);
231
223
 
232
224
  ({classList} = this.#header.querySelector(".icon")!);
233
- classList.remove(...contexts.map(context => `text-${context}`));
225
+ classList.remove(...contexts.map(context => `text-${toCss(context)}`));
234
226
  classList.add(`text-${value}`);
235
227
  }
236
228
 
@@ -250,3 +242,16 @@ export class Toast extends HTMLElement {
250
242
  this.#header.querySelector(".icon")!.textContent = value.trim() || getIcon(Context.Info);
251
243
  }
252
244
  }
245
+
246
+ /**
247
+ * Declaration merging.
248
+ */
249
+ declare global {
250
+
251
+ /**
252
+ * The map of HTML tag names.
253
+ */
254
+ interface HTMLElementTagNameMap {
255
+ "toaster-item": Toast;
256
+ }
257
+ }
@@ -6,22 +6,22 @@ export const Context = Object.freeze({
6
6
  /**
7
7
  * A danger.
8
8
  */
9
- Danger: "danger",
9
+ Danger: "Danger",
10
10
 
11
11
  /**
12
12
  * A warning.
13
13
  */
14
- Warning: "warning",
14
+ Warning: "Warning",
15
15
 
16
16
  /**
17
17
  * An information.
18
18
  */
19
- Info: "info",
19
+ Info: "Info",
20
20
 
21
21
  /**
22
22
  * A success.
23
23
  */
24
- Success: "success"
24
+ Success: "Success"
25
25
  });
26
26
 
27
27
  /**
@@ -42,3 +42,12 @@ export function getIcon(context: Context): string {
42
42
  default: return "info";
43
43
  }
44
44
  }
45
+
46
+ /**
47
+ * Returns the CSS representation of the specified context.
48
+ * @param context The context.
49
+ * @returns The CSS representation of the specified context.
50
+ */
51
+ export function toCss(context: Context): string {
52
+ return context.toLowerCase();
53
+ }
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Defines the placement of an element.
2
+ * Defines the position of an element.
3
3
  */
4
4
  export const Position = Object.freeze({
5
5
 
6
6
  /**
7
7
  * Top left.
8
8
  */
9
- TopLeft: "TopLeft",
9
+ TopStart: "TopStart",
10
10
 
11
11
  /**
12
12
  * Top center.
@@ -16,12 +16,12 @@ export const Position = Object.freeze({
16
16
  /**
17
17
  * Top right.
18
18
  */
19
- TopRight: "TopRight",
19
+ TopEnd: "TopEnd",
20
20
 
21
21
  /**
22
22
  * Middle left.
23
23
  */
24
- MiddleLeft: "MiddleLeft",
24
+ MiddleStart: "MiddleStart",
25
25
 
26
26
  /**
27
27
  * Middle center.
@@ -31,12 +31,12 @@ export const Position = Object.freeze({
31
31
  /**
32
32
  * Middle right.
33
33
  */
34
- MiddleRight: "MiddleRight",
34
+ MiddleEnd: "MiddleEnd",
35
35
 
36
36
  /**
37
37
  * Bottom left.
38
38
  */
39
- BottomLeft: "BottomLeft",
39
+ BottomStart: "BottomStart",
40
40
 
41
41
  /**
42
42
  * Bottom center.
@@ -46,10 +46,29 @@ export const Position = Object.freeze({
46
46
  /**
47
47
  * Bottom right.
48
48
  */
49
- BottomRight: "BottomRight"
49
+ BottomEnd: "BottomEnd"
50
50
  });
51
51
 
52
52
  /**
53
53
  * Defines the placement of an element.
54
54
  */
55
55
  export type Position = typeof Position[keyof typeof Position];
56
+
57
+ /**
58
+ * Returns the CSS representation of the specified position.
59
+ * @param position The position.
60
+ * @returns The CSS representation of the specified position.
61
+ */
62
+ export function toCss(position: Position): string {
63
+ switch (position) {
64
+ case Position.TopCenter: return "top-0 start-50 translate-middle-x";
65
+ case Position.TopEnd: return "top-0 end-0";
66
+ case Position.MiddleStart: return "top-50 start-0 translate-middle-y";
67
+ case Position.MiddleCenter: return "top-50 start-50 translate-middle";
68
+ case Position.MiddleEnd: return "top-50 end-0 translate-middle-y";
69
+ case Position.BottomStart: return "bottom-0 start-0";
70
+ case Position.BottomCenter: return "bottom-0 start-50 translate-middle-x";
71
+ case Position.BottomEnd: return "bottom-0 end-0";
72
+ default: return "top-0 start-0";
73
+ }
74
+ }
@@ -1,40 +1,56 @@
1
1
  /**
2
- * Defines the size of a component.
2
+ * Defines the size of an element.
3
3
  */
4
4
  export const Size = Object.freeze({
5
5
 
6
6
  /**
7
7
  * An extra small size.
8
8
  */
9
- ExtraSmall: "xs",
9
+ ExtraSmall: "ExtraSmall",
10
10
 
11
11
  /**
12
12
  * A small size.
13
13
  */
14
- Small: "sm",
14
+ Small: "Small",
15
15
 
16
16
  /**
17
17
  * A medium size.
18
18
  */
19
- Medium: "md",
19
+ Medium: "Medium",
20
20
 
21
21
  /**
22
22
  * A large size.
23
23
  */
24
- Large: "lg",
24
+ Large: "Large",
25
25
 
26
26
  /**
27
27
  * An extra large size.
28
28
  */
29
- ExtraLarge: "xl",
29
+ ExtraLarge: "ExtraLarge",
30
30
 
31
31
  /**
32
32
  * An extra extra large size.
33
33
  */
34
- ExtraExtraLarge: "xxl"
34
+ ExtraExtraLarge: "ExtraExtraLarge"
35
35
  });
36
36
 
37
37
  /**
38
- * Defines the size of a component.
38
+ * Defines the size of an element.
39
39
  */
40
40
  export type Size = typeof Size[keyof typeof Size];
41
+
42
+ /**
43
+ * Returns the CSS representation of the specified size.
44
+ * @param size The size.
45
+ * @returns The CSS representation of the specified size.
46
+ */
47
+ export function toCss(size: Size): string {
48
+ switch (size) {
49
+ case Size.ExtraSmall: return "xs";
50
+ case Size.Small: return "sm";
51
+ case Size.Large: return "lg";
52
+ case Size.ExtraLarge: return "xl";
53
+ case Size.ExtraExtraLarge: return "xxl";
54
+ default: return "md";
55
+ }
56
+ }
@@ -6,25 +6,34 @@ export const Variant = Object.freeze({
6
6
  /**
7
7
  * A dark variant.
8
8
  */
9
- Dark: "dark",
9
+ Dark: "Dark",
10
10
 
11
11
  /**
12
12
  * A light variant.
13
13
  */
14
- Light: "light",
14
+ Light: "Light",
15
15
 
16
16
  /**
17
17
  * A primary variant.
18
18
  */
19
- Primary: "primary",
19
+ Primary: "Primary",
20
20
 
21
21
  /**
22
22
  * A secondary variant.
23
23
  */
24
- Secondary: "secondary"
24
+ Secondary: "Secondary"
25
25
  });
26
26
 
27
27
  /**
28
28
  * Defines tone variants.
29
29
  */
30
30
  export type Variant = typeof Variant[keyof typeof Variant];
31
+
32
+ /**
33
+ * Returns the CSS representation of the specified variant.
34
+ * @param variant The variant.
35
+ * @returns The CSS representation of the specified variant.
36
+ */
37
+ export function toCss(variant: Variant): string {
38
+ return variant.toLowerCase();
39
+ }
@@ -1,242 +0,0 @@
1
- import {Context, getIcon} from "../Context.js";
2
- import {Variant} from "../Variant.js";
3
-
4
- /**
5
- * Specifies the return value of a message box.
6
- */
7
- export const MessageBoxResult = Object.freeze({
8
-
9
- /**
10
- * The message box does not return any value.
11
- */
12
- None: "",
13
-
14
- /**
15
- * The return value of the message box is "OK".
16
- */
17
- OK: "OK",
18
-
19
- /**
20
- * The return value of the message box is "Cancel".
21
- */
22
- Cancel: "Cancel"
23
- });
24
-
25
- /**
26
- * Specifies the return value of a message box.
27
- */
28
- export type MessageBoxResult = typeof MessageBoxResult[keyof typeof MessageBoxResult];
29
-
30
- /**
31
- * Displays a message window, also known as dialog box, which presents a message to the user.
32
- */
33
- export class MessageBox extends HTMLElement {
34
-
35
- /**
36
- * Value indicating whether to vertically center this message box.
37
- */
38
- @property({type: Boolean}) centered = false;
39
-
40
- /**
41
- * The buttons displayed in the footer.
42
- */
43
- @state() private buttons: MessageBoxButton[] = [];
44
-
45
- /**
46
- * The title displayed in the header.
47
- */
48
- @state() private caption = "";
49
-
50
- /**
51
- * The message displayed in the body.
52
- */
53
- @state() private content: TemplateResult = html``;
54
-
55
- /**
56
- * A contextual modifier.
57
- */
58
- @state() private context: Context|null = null;
59
-
60
- /**
61
- * The icon displayed next to the body.
62
- */
63
- @state() private icon = "";
64
-
65
- /**
66
- * The root element.
67
- */
68
- @query("dialog", true) private readonly root!: HTMLDialogElement;
69
-
70
- /**
71
- * The function invoked to return the dialog box result.
72
- */
73
- #resolve: (value: string) => void = () => { /* Noop */ };
74
-
75
- /**
76
- * Opens an alert dialog with the specified message and an "OK" button.
77
- * @param caption The title displayed in the header.
78
- * @param message The message to show.
79
- * @param options The message box options.
80
- * @returns Resolves with the value of the clicked button.
81
- */
82
- alert(caption: string, message: TemplateResult, options: MessageBoxOptions = {}): Promise<string> {
83
- const context = options.context ?? Context.Warning;
84
- return this.show(message, {
85
- buttons: options.buttons ?? [{label: "OK", value: MessageBoxResult.OK}],
86
- caption,
87
- context,
88
- icon: options.icon ?? getIcon(context)
89
- });
90
- }
91
-
92
- /**
93
- * Closes the message box.
94
- * @param result The message box result.
95
- */
96
- close(result: MessageBoxResult = MessageBoxResult.None): void {
97
- this.root.close(result);
98
- }
99
-
100
- /**
101
- * Opens a confirmation dialog with the specified message and two buttons, "OK" and "Cancel".
102
- * @param caption The title displayed in the header.
103
- * @param message The message to show.
104
- * @param options The message box options.
105
- * @returns Resolves with the value of the clicked button.
106
- */
107
- confirm(caption: string, message: TemplateResult, options: MessageBoxOptions = {}): Promise<string> {
108
- const context = options.context ?? Context.Warning;
109
- return this.show(message, {
110
- caption,
111
- context,
112
- icon: options.icon ?? getIcon(context),
113
- buttons: options.buttons ?? [
114
- {label: "OK", value: MessageBoxResult.OK},
115
- {label: "Annuler", value: MessageBoxResult.Cancel, variant: Variant.Secondary}
116
- ]
117
- });
118
- }
119
-
120
- /**
121
- * Opens a modal dialog with the specified message and options.
122
- * @param message The message to show.
123
- * @param options The message box options.
124
- * @returns Resolves with the value of the clicked button.
125
- */
126
- show(message: TemplateResult, options: MessageBoxOptions = {}): Promise<string> {
127
- this.buttons = options.buttons ?? [];
128
- this.caption = options.caption ?? "";
129
- this.content = message;
130
- this.context = options.context ?? null;
131
- this.icon = options.icon ?? "";
132
-
133
- this.root.returnValue = MessageBoxResult.None;
134
- this.root.showModal();
135
- this.root.querySelector<HTMLButtonElement>(".btn-close")?.blur();
136
-
137
- const {promise, resolve} = Promise.withResolvers<string>();
138
- this.#resolve = resolve;
139
- return promise;
140
- }
141
-
142
- /**
143
- * Renders this component.
144
- * @returns The view template.
145
- */
146
- protected override render(): TemplateResult {
147
- const centered = classMap({"modal-dialog-centered": this.centered});
148
- return html`
149
- <dialog class="modal modal-dialog modal-dialog-scrollable ${centered}" @click=${this.#onDialogClick} @close=${this.#onDialogClose}>
150
- <form class="modal-content" method="dialog">
151
- <div class="modal-header user-select-none">
152
- ${when(this.caption, () => html`<h1 class="modal-title fs-5">${this.caption}</h1>`)}
153
- <button class="btn-close"></button>
154
- </div>
155
- <div class="modal-body d-flex">
156
- ${when(this.icon, () => html`
157
- <i class="icon icon-fill fs-1 fw-semibold me-2 ${classMap({[`text-${this.context}`]: this.context ?? ""})}">${this.icon}</i>
158
- `)}
159
- <div class="flex-grow-1">${this.content}</div>
160
- </div>
161
- ${when(this.buttons.length, () => html`
162
- <div class="modal-footer user-select-none">
163
- ${this.buttons.map(button => html`
164
- <button class="btn btn-${button.variant ?? Variant.Primary}" value=${button.value ?? MessageBoxResult.None}>
165
- ${when(button.icon, () => html`<i class="icon icon-fill ${classMap({"me-1": button.label ?? ""})}">${button.icon}</i>`)}
166
- ${button.label}
167
- </button>
168
- `)}
169
- </div>
170
- `)}
171
- </form>
172
- </dialog>
173
- `;
174
- }
175
-
176
- /**
177
- * Handles the `click` event.
178
- * @param event The dispatched event.
179
- */
180
- #onDialogClick(event: Event): void {
181
- if (event.target == this.root) this.close();
182
- }
183
-
184
- /**
185
- * Handles the `close` event.
186
- */
187
- #onDialogClose(): void {
188
- this.#resolve(this.root.returnValue);
189
- }
190
- }
191
-
192
- /**
193
- * A message box button.
194
- */
195
- export type MessageBoxButton = Partial<{
196
-
197
- /**
198
- * The button icon.
199
- */
200
- icon: string;
201
-
202
- /**
203
- * The button label.
204
- */
205
- label: string;
206
-
207
- /**
208
- * The button value.
209
- */
210
- value: string;
211
-
212
- /**
213
- * A tone variant.
214
- */
215
- variant: Context|Variant;
216
- }>;
217
-
218
- /**
219
- * Defines the options of a {@link MessageBox} instance.
220
- */
221
- export type MessageBoxOptions = Partial<{
222
-
223
- /**
224
- * The buttons displayed in the footer.
225
- */
226
- buttons: MessageBoxButton[];
227
-
228
- /**
229
- * The title displayed in the header.
230
- */
231
- caption: string;
232
-
233
- /**
234
- * A contextual modifier.
235
- */
236
- context: Context;
237
-
238
- /**
239
- * The icon displayed next to the body.
240
- */
241
- icon: string;
242
- }>;
File without changes