@gisce/ooui 2.38.0 → 2.39.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/dist/Card.d.ts +18 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/WidgetFactory.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ooui.es.js +143 -105
- package/dist/ooui.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Card.ts +52 -0
- package/src/WidgetFactory.ts +5 -0
- package/src/index.ts +2 -0
- package/src/spec/Card.spec.ts +89 -0
package/package.json
CHANGED
package/src/Card.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Spinner from "./Spinner";
|
|
2
|
+
|
|
3
|
+
class Card extends Spinner {
|
|
4
|
+
_title: string | null = null;
|
|
5
|
+
get title(): string | null {
|
|
6
|
+
return this._title;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
set title(value: string | null) {
|
|
10
|
+
this._title = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_icon: string | null = null;
|
|
14
|
+
get icon(): string | null {
|
|
15
|
+
return this._icon;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
set icon(value: string | null) {
|
|
19
|
+
this._icon = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Height of the card component
|
|
24
|
+
*/
|
|
25
|
+
_height: number | undefined = undefined;
|
|
26
|
+
|
|
27
|
+
get height(): number | undefined {
|
|
28
|
+
return this._height;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
set height(value: number | undefined) {
|
|
32
|
+
this._height = value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor(props: any) {
|
|
36
|
+
super(props);
|
|
37
|
+
if (props) {
|
|
38
|
+
if (props.title) {
|
|
39
|
+
this._title = props.title;
|
|
40
|
+
}
|
|
41
|
+
if (props.icon) {
|
|
42
|
+
this._icon = props.icon;
|
|
43
|
+
}
|
|
44
|
+
if (props.height) {
|
|
45
|
+
const parsedHeight = parseInt(props.height);
|
|
46
|
+
this._height = isNaN(parsedHeight) ? undefined : parsedHeight;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default Card;
|
package/src/WidgetFactory.ts
CHANGED
|
@@ -45,6 +45,7 @@ import Spinner from "./Spinner";
|
|
|
45
45
|
import Carousel from "./Carousel";
|
|
46
46
|
import ColorPicker from "./ColorPicker";
|
|
47
47
|
import QRCode from "./QRCode";
|
|
48
|
+
import Card from "./Card";
|
|
48
49
|
|
|
49
50
|
class WidgetFactory {
|
|
50
51
|
/**
|
|
@@ -63,6 +64,9 @@ class WidgetFactory {
|
|
|
63
64
|
case "group":
|
|
64
65
|
this._widgetClass = Group;
|
|
65
66
|
break;
|
|
67
|
+
case "card":
|
|
68
|
+
this._widgetClass = Card;
|
|
69
|
+
break;
|
|
66
70
|
case "label":
|
|
67
71
|
this._widgetClass = Label;
|
|
68
72
|
break;
|
|
@@ -227,6 +231,7 @@ class WidgetFactory {
|
|
|
227
231
|
case "notebook":
|
|
228
232
|
case "page":
|
|
229
233
|
case "group":
|
|
234
|
+
case "card":
|
|
230
235
|
return new this._widgetClass({ ...props, type: finalType });
|
|
231
236
|
case "button":
|
|
232
237
|
return new this._widgetClass({
|
package/src/index.ts
CHANGED
|
@@ -57,6 +57,7 @@ import Spinner from "./Spinner";
|
|
|
57
57
|
import Carousel from "./Carousel";
|
|
58
58
|
import ColorPicker from "./ColorPicker";
|
|
59
59
|
import QRCode from "./QRCode";
|
|
60
|
+
import Card from "./Card";
|
|
60
61
|
|
|
61
62
|
import {
|
|
62
63
|
Graph,
|
|
@@ -150,4 +151,5 @@ export {
|
|
|
150
151
|
Carousel,
|
|
151
152
|
ColorPicker,
|
|
152
153
|
QRCode,
|
|
154
|
+
Card,
|
|
153
155
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Card from "../Card";
|
|
2
|
+
import WidgetImpl from "./fixtures/WidgetImpl";
|
|
3
|
+
import WidgetFactory from "../WidgetFactory";
|
|
4
|
+
import { it, expect, describe } from "vitest";
|
|
5
|
+
|
|
6
|
+
describe("A Card", () => {
|
|
7
|
+
it("should be constructed with 4 columns and a colspan of 4", () => {
|
|
8
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
9
|
+
expect(card4.colspan).toBe(4);
|
|
10
|
+
expect(card4.container.columns).toBe(4);
|
|
11
|
+
});
|
|
12
|
+
it("should be constructed with 6 columns and a colspan of 2", () => {
|
|
13
|
+
const card4 = new Card({ col: 6, colspan: 2 });
|
|
14
|
+
expect(card4.colspan).toBe(2);
|
|
15
|
+
expect(card4.container.columns).toBe(6);
|
|
16
|
+
});
|
|
17
|
+
it("should have 1 rows if 4 items", () => {
|
|
18
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
19
|
+
card4.container.addWidget(new WidgetImpl({ name: "1" }));
|
|
20
|
+
card4.container.addWidget(new WidgetImpl({ name: "2" }));
|
|
21
|
+
card4.container.addWidget(new WidgetImpl({ name: "3" }));
|
|
22
|
+
card4.container.addWidget(new WidgetImpl({ name: "4" }));
|
|
23
|
+
expect(card4.container.rows.length).toBe(1);
|
|
24
|
+
});
|
|
25
|
+
it("should have 2 rows if 5 items", () => {
|
|
26
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
27
|
+
card4.container.addWidget(new WidgetImpl({ name: "1" }));
|
|
28
|
+
card4.container.addWidget(new WidgetImpl({ name: "2" }));
|
|
29
|
+
card4.container.addWidget(new WidgetImpl({ name: "3" }));
|
|
30
|
+
card4.container.addWidget(new WidgetImpl({ name: "4" }));
|
|
31
|
+
card4.container.addWidget(new WidgetImpl({ name: "5" }));
|
|
32
|
+
expect(card4.container.rows.length).toBe(2);
|
|
33
|
+
});
|
|
34
|
+
it("can have an icon property", () => {
|
|
35
|
+
const widgetFactory = new WidgetFactory();
|
|
36
|
+
const props = {
|
|
37
|
+
title: "General",
|
|
38
|
+
icon: "home",
|
|
39
|
+
};
|
|
40
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
41
|
+
expect(widget.icon).toEqual("home");
|
|
42
|
+
});
|
|
43
|
+
it("can have a title property", () => {
|
|
44
|
+
const widgetFactory = new WidgetFactory();
|
|
45
|
+
const props = {
|
|
46
|
+
title: "Card Title",
|
|
47
|
+
icon: "user",
|
|
48
|
+
};
|
|
49
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
50
|
+
expect(widget.title).toEqual("Card Title");
|
|
51
|
+
});
|
|
52
|
+
it("can have a height property", () => {
|
|
53
|
+
const widgetFactory = new WidgetFactory();
|
|
54
|
+
const props = {
|
|
55
|
+
title: "Card Title",
|
|
56
|
+
height: "200",
|
|
57
|
+
};
|
|
58
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
59
|
+
expect(widget.height).toEqual(200);
|
|
60
|
+
});
|
|
61
|
+
it("should handle invalid height values", () => {
|
|
62
|
+
const widgetFactory = new WidgetFactory();
|
|
63
|
+
const props = {
|
|
64
|
+
title: "Card Title",
|
|
65
|
+
height: "invalid",
|
|
66
|
+
};
|
|
67
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
68
|
+
expect(widget.height).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
describe("working as a spinner", () => {
|
|
71
|
+
it("should be loading false as default", () => {
|
|
72
|
+
const widgetFactory = new WidgetFactory();
|
|
73
|
+
const props = {
|
|
74
|
+
title: "A card",
|
|
75
|
+
};
|
|
76
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
77
|
+
expect(widget.loading).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
it("should be loading true if set", () => {
|
|
80
|
+
const widgetFactory = new WidgetFactory();
|
|
81
|
+
const props = {
|
|
82
|
+
title: "A card",
|
|
83
|
+
loading: true,
|
|
84
|
+
};
|
|
85
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
86
|
+
expect(widget.loading).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|