@gisce/ooui 2.38.0-alpha.1 → 2.38.0-alpha.2

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.38.0-alpha.1",
3
+ "version": "2.38.0-alpha.2",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Card.ts ADDED
@@ -0,0 +1,35 @@
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
+ constructor(props: any) {
23
+ super(props);
24
+ if (props) {
25
+ if (props.title) {
26
+ this._title = props.title;
27
+ }
28
+ if (props.icon) {
29
+ this._icon = props.icon;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ export default Card;
@@ -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,71 @@
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
+ describe("working as a spinner", () => {
53
+ it("should be loading false as default", () => {
54
+ const widgetFactory = new WidgetFactory();
55
+ const props = {
56
+ title: "A card",
57
+ };
58
+ const widget = widgetFactory.createWidget("card", props);
59
+ expect(widget.loading).toBe(false);
60
+ });
61
+ it("should be loading true if set", () => {
62
+ const widgetFactory = new WidgetFactory();
63
+ const props = {
64
+ title: "A card",
65
+ loading: true,
66
+ };
67
+ const widget = widgetFactory.createWidget("card", props);
68
+ expect(widget.loading).toBe(true);
69
+ });
70
+ });
71
+ });