Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinner component #143

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});