Skip to content

Commit

Permalink
Merge pull request #143 from gisce/feature/spinner-component
Browse files Browse the repository at this point in the history
Spinner component
  • Loading branch information
ecarreras authored Nov 28, 2024
2 parents 7c7c334 + 22a71ad commit 6b8fe21
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Spinner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ContainerWidget from "./ContainerWidget";

class Spinner extends ContainerWidget {
_loading = false;
get loading(): boolean {
return this._loading;
}

set loading(value: boolean) {
this._loading = value;
}

constructor(props?: any) {
super(props);
if (props) {
if (props.loading) {
this._loading = props.loading;
}
}
}
}

export default Spinner;
4 changes: 4 additions & 0 deletions src/WidgetFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Alert from "./Alert";
import Comments from "./Comments";
import JSONField from "./JSONField";
import Email from "./Email";
import Spinner from "./Spinner";

class WidgetFactory {
/**
Expand Down Expand Up @@ -180,6 +181,9 @@ class WidgetFactory {
case "arrow_steps":
this._widgetClass = JSONField;
break;
case "spinner":
this._widgetClass = Spinner;
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Alert from "./Alert";
import JSONField from "./JSONField";
import Comments from "./Comments";
import Email from "./Email";
import Spinner from "./Spinner";

import {
Graph,
Expand Down Expand Up @@ -140,4 +141,5 @@ export {
Comments,
JSONField,
Email,
Spinner,
};
35 changes: 35 additions & 0 deletions src/spec/Spinner.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import WidgetFactory from "../WidgetFactory";
import Spinner from "../Spinner";
import { it, expect, describe } from "vitest";

describe("A Spinner", () => {
it("should have an id corresponding to field name", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "spinner",
};

const widget = widgetFactory.createWidget("spinner", props);
expect(widget).toBeInstanceOf(Spinner);
});

it("should properly set label", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "spinner",
string: "spinner caption",
};
const widget = widgetFactory.createWidget("spinner", props);

expect(widget.label).toBe("spinner caption");
});

it("should have loading as false by default", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "spinner",
};
const widget = widgetFactory.createWidget("spinner", props);
expect(widget.loading).toBe(false);
});
});

0 comments on commit 6b8fe21

Please sign in to comment.