@gisce/ooui 2.5.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Alert.ts ADDED
@@ -0,0 +1,65 @@
1
+ import Field from "./Field";
2
+
3
+ type AlertType = "success" | "warning" | "info" | "error" | undefined;
4
+
5
+ class Alert extends Field {
6
+ /**
7
+ * Alert type
8
+ */
9
+ _alertType: AlertType = "info";
10
+ get alertType(): AlertType {
11
+ return this._alertType;
12
+ }
13
+
14
+ set alertType(value: AlertType) {
15
+ this._alertType = value;
16
+ }
17
+
18
+ _title: string = "";
19
+ get title(): string {
20
+ return this._title;
21
+ }
22
+
23
+ set title(value: string) {
24
+ this._title = value;
25
+ }
26
+
27
+ _text: string = "";
28
+ get text(): string {
29
+ return this._text;
30
+ }
31
+
32
+ set text(value: string) {
33
+ this._text = value;
34
+ }
35
+
36
+ _icon: string | null = null;
37
+ get icon(): string | null {
38
+ return this._icon;
39
+ }
40
+
41
+ set icon(value: string | null) {
42
+ this._icon = value;
43
+ }
44
+
45
+ constructor(props: any) {
46
+ super(props);
47
+ if (props) {
48
+ this._nolabel = true;
49
+ if (props.alert_type) {
50
+ this._alertType = props.alert_type;
51
+ }
52
+ if (props.title) {
53
+ this._title = props.title;
54
+ }
55
+ if (props.text) {
56
+ this._text = props.text;
57
+ }
58
+ if (props.icon) {
59
+ this._icon = props.icon;
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ export default Alert;
@@ -37,6 +37,7 @@ import Steps from "./Steps";
37
37
  import CodeEditor from "./CodeEditor";
38
38
  import Avatar from "./Avatar";
39
39
  import Time from "./Time";
40
+ import Alert from "./Alert";
40
41
 
41
42
  class WidgetFactory {
42
43
  /**
@@ -167,6 +168,9 @@ class WidgetFactory {
167
168
  case "html_preview":
168
169
  this._widgetClass = HTMLPreview;
169
170
  break;
171
+ case "alert":
172
+ this._widgetClass = Alert;
173
+ break;
170
174
 
171
175
  default:
172
176
  break;
package/src/index.ts CHANGED
@@ -49,6 +49,7 @@ import Steps from "./Steps";
49
49
  import CodeEditor from "./CodeEditor";
50
50
  import Time from "./Time";
51
51
  import HTMLPreview from "./HTMLPreview";
52
+ import Alert from "./Alert";
52
53
 
53
54
  import {
54
55
  Graph,
@@ -130,4 +131,5 @@ export {
130
131
  CodeEditor,
131
132
  SearchFieldTypes,
132
133
  Time,
134
+ Alert,
133
135
  };
@@ -0,0 +1,50 @@
1
+ import { it, expect, describe, beforeEach } from "vitest";
2
+ import WidgetFactory from "../WidgetFactory";
3
+
4
+ describe("A Alert", () => {
5
+ let widgetFactory: WidgetFactory;
6
+
7
+ beforeEach(() => {
8
+ widgetFactory = new WidgetFactory();
9
+ });
10
+
11
+ it("should set alertType when provided in props", () => {
12
+ const widget = widgetFactory.createWidget("alert", { alert_type: "error" });
13
+ expect(widget.alertType).toBe("error");
14
+ });
15
+
16
+ it("should default to 'info' alertType when not provided in props", () => {
17
+ const widget = widgetFactory.createWidget("alert", {});
18
+ expect(widget.alertType).toBe("info");
19
+ });
20
+
21
+ it("should set title when provided in props", () => {
22
+ const widget = widgetFactory.createWidget("alert", { title: "Test Title" });
23
+ expect(widget.title).toBe("Test Title");
24
+ });
25
+
26
+ it("should default to empty string for title when not provided in props", () => {
27
+ const widget = widgetFactory.createWidget("alert", {});
28
+ expect(widget.title).toBe("");
29
+ });
30
+
31
+ it("should set text when provided in props", () => {
32
+ const widget = widgetFactory.createWidget("alert", { text: "Test Text" });
33
+ expect(widget.text).toBe("Test Text");
34
+ });
35
+
36
+ it("should default to empty string for text when not provided in props", () => {
37
+ const widget = widgetFactory.createWidget("alert", {});
38
+ expect(widget.text).toBe("");
39
+ });
40
+
41
+ it("should set icon when provided in props", () => {
42
+ const widget = widgetFactory.createWidget("alert", { icon: "Test Icon" });
43
+ expect(widget.icon).toBe("Test Icon");
44
+ });
45
+
46
+ it("should default to null for icon when not provided in props", () => {
47
+ const widget = widgetFactory.createWidget("alert", {});
48
+ expect(widget.icon).toBeNull();
49
+ });
50
+ });