From f96de62a3d45908b32ea5ac4eac95565366f17b5 Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Fri, 22 Nov 2024 18:49:23 +0100 Subject: [PATCH] feat(image): allow to hide controls --- src/Image.ts | 6 +++++- src/spec/Image.spec.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/spec/Image.spec.ts diff --git a/src/Image.ts b/src/Image.ts index 4479a1f..9da21a4 100644 --- a/src/Image.ts +++ b/src/Image.ts @@ -3,6 +3,10 @@ import Field from "./Field"; /** * Image base64 field */ -class Image extends Field {} +class Image extends Field { + get showControls(): boolean { + return this.parsedWidgetProps?.showControls ?? true; + } +} export default Image; diff --git a/src/spec/Image.spec.ts b/src/spec/Image.spec.ts new file mode 100644 index 0000000..d800228 --- /dev/null +++ b/src/spec/Image.spec.ts @@ -0,0 +1,19 @@ +import { describe, it, expect } from "vitest"; +import Image from "../Image"; + +describe("Image", () => { + it("should have showControls property to true as default", () => { + const props = {}; + const image = new Image(props); + expect(image.showControls).toBe(true); + }); + it("should have showControls property to false", () => { + const props = { + widget_props: { + showControls: false, + }, + }; + const image = new Image(props); + expect(image.showControls).toBe(false); + }); +});