From 22a71ad3061538bcbce4dc24b84f7e58ce2503cc Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 27 Nov 2024 13:11:51 +0100 Subject: [PATCH] feat(Spinner): add spinner component --- src/Spinner.ts | 23 +++++++++++++++++++++++ src/WidgetFactory.ts | 4 ++++ src/index.ts | 2 ++ src/spec/Spinner.spec.ts | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 src/Spinner.ts create mode 100644 src/spec/Spinner.spec.ts diff --git a/src/Spinner.ts b/src/Spinner.ts new file mode 100644 index 0000000..83fc018 --- /dev/null +++ b/src/Spinner.ts @@ -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; diff --git a/src/WidgetFactory.ts b/src/WidgetFactory.ts index bf535cd..10ac0c8 100644 --- a/src/WidgetFactory.ts +++ b/src/WidgetFactory.ts @@ -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 { /** @@ -180,6 +181,9 @@ class WidgetFactory { case "arrow_steps": this._widgetClass = JSONField; break; + case "spinner": + this._widgetClass = Spinner; + break; default: break; } diff --git a/src/index.ts b/src/index.ts index 430083d..b92d49b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, @@ -140,4 +141,5 @@ export { Comments, JSONField, Email, + Spinner, }; diff --git a/src/spec/Spinner.spec.ts b/src/spec/Spinner.spec.ts new file mode 100644 index 0000000..c6b4eb2 --- /dev/null +++ b/src/spec/Spinner.spec.ts @@ -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); + }); +});