@gisce/ooui 2.37.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.37.1",
3
+ "version": "2.38.0-alpha.2",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
@@ -0,0 +1,5 @@
1
+ import Field from "./Field";
2
+
3
+ class ActionButtons extends Field {}
4
+
5
+ export default ActionButtons;
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;
@@ -3,6 +3,7 @@ import Page from "./Page";
3
3
  import Group from "./Group";
4
4
  import Button from "./Button";
5
5
  import ButtonGroup from "./ButtonGroup";
6
+ import ActionButtons from "./ActionButtons";
6
7
  import Label from "./Label";
7
8
  import Char from "./Char";
8
9
  import Text from "./Text";
@@ -44,6 +45,7 @@ import Spinner from "./Spinner";
44
45
  import Carousel from "./Carousel";
45
46
  import ColorPicker from "./ColorPicker";
46
47
  import QRCode from "./QRCode";
48
+ import Card from "./Card";
47
49
 
48
50
  class WidgetFactory {
49
51
  /**
@@ -62,6 +64,9 @@ class WidgetFactory {
62
64
  case "group":
63
65
  this._widgetClass = Group;
64
66
  break;
67
+ case "card":
68
+ this._widgetClass = Card;
69
+ break;
65
70
  case "label":
66
71
  this._widgetClass = Label;
67
72
  break;
@@ -77,6 +82,9 @@ class WidgetFactory {
77
82
  case "buttonGroup":
78
83
  this._widgetClass = ButtonGroup;
79
84
  break;
85
+ case "action_buttons":
86
+ this._widgetClass = ActionButtons;
87
+ break;
80
88
  case "selection":
81
89
  this._widgetClass = Selection;
82
90
  break;
@@ -223,6 +231,7 @@ class WidgetFactory {
223
231
  case "notebook":
224
232
  case "page":
225
233
  case "group":
234
+ case "card":
226
235
  return new this._widgetClass({ ...props, type: finalType });
227
236
  case "button":
228
237
  return new this._widgetClass({
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ import Page from "./Page";
27
27
  import Separator from "./Separator";
28
28
  import Button from "./Button";
29
29
  import ButtonGroup from "./ButtonGroup";
30
+ import ActionButtons from "./ActionButtons";
30
31
  import Reference from "./Reference";
31
32
  import Binary from "./Binary";
32
33
  import Image from "./Image";
@@ -56,6 +57,7 @@ import Spinner from "./Spinner";
56
57
  import Carousel from "./Carousel";
57
58
  import ColorPicker from "./ColorPicker";
58
59
  import QRCode from "./QRCode";
60
+ import Card from "./Card";
59
61
 
60
62
  import {
61
63
  Graph,
@@ -105,6 +107,7 @@ export {
105
107
  Separator,
106
108
  Button,
107
109
  ButtonGroup,
110
+ ActionButtons,
108
111
  Reference,
109
112
  Binary,
110
113
  Image,
@@ -148,4 +151,5 @@ export {
148
151
  Carousel,
149
152
  ColorPicker,
150
153
  QRCode,
154
+ Card,
151
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
+ });