Skip to content

Commit d9d8bbe

Browse files
authored
Merge pull request #163 from gisce/66704/color-picker
Add new component colorPicker
2 parents e4ab1e5 + 67cd630 commit d9d8bbe

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

src/ColorPicker.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Char from "./Char";
2+
3+
class ColorPicker extends Char {
4+
get showText(): boolean {
5+
return this.parsedWidgetProps.show_text ?? true;
6+
}
7+
}
8+
9+
export default ColorPicker;

src/WidgetFactory.ts

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import JSONField from "./JSONField";
4242
import Email from "./Email";
4343
import Spinner from "./Spinner";
4444
import Carousel from "./Carousel";
45+
import ColorPicker from "./ColorPicker";
4546

4647
class WidgetFactory {
4748
/**
@@ -188,6 +189,9 @@ class WidgetFactory {
188189
case "carousel":
189190
this._widgetClass = Carousel;
190191
break;
192+
case "colorPicker":
193+
this._widgetClass = ColorPicker;
194+
break;
191195
default:
192196
break;
193197
}

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import Comments from "./Comments";
5454
import Email from "./Email";
5555
import Spinner from "./Spinner";
5656
import Carousel from "./Carousel";
57+
import ColorPicker from "./ColorPicker";
5758

5859
import {
5960
Graph,
@@ -144,4 +145,5 @@ export {
144145
Email,
145146
Spinner,
146147
Carousel,
148+
ColorPicker,
147149
};

src/spec/ColorPicker.spec.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// src/spec/ColorPicker.spec.ts
2+
import WidgetFactory from "../WidgetFactory";
3+
import ColorPicker from "../ColorPicker";
4+
import { it, expect, describe } from "vitest";
5+
6+
describe("A ColorPicker", () => {
7+
it("should have an id corresponding to field name", () => {
8+
const widgetFactory = new WidgetFactory();
9+
const props = {
10+
name: "colorPicker",
11+
};
12+
13+
const widget = widgetFactory.createWidget("colorPicker", props);
14+
expect(widget).toBeInstanceOf(ColorPicker);
15+
});
16+
17+
it("should properly set label", () => {
18+
const widgetFactory = new WidgetFactory();
19+
const props = {
20+
name: "colorPicker",
21+
string: "colorPicker caption",
22+
};
23+
const widget = widgetFactory.createWidget("colorPicker", props);
24+
25+
expect(widget.label).toBe("colorPicker caption");
26+
});
27+
28+
describe("showText property", () => {
29+
it("should show text by default", () => {
30+
const widgetFactory = new WidgetFactory();
31+
const props = {
32+
name: "colorPicker",
33+
};
34+
const widget = widgetFactory.createWidget("colorPicker", props);
35+
36+
expect(widget.showText).toBe(true);
37+
});
38+
it("should show text when widget_props.showText is true", () => {
39+
const widgetFactory = new WidgetFactory();
40+
const props = {
41+
name: "colorPicker",
42+
widget_props: {
43+
show_text: true,
44+
},
45+
};
46+
const widget = widgetFactory.createWidget("colorPicker", props);
47+
48+
expect(widget.showText).toBe(true);
49+
});
50+
51+
it("should not show text when widget_props.showText is false", () => {
52+
const widgetFactory = new WidgetFactory();
53+
const props = {
54+
name: "colorPicker",
55+
widget_props: {
56+
show_text: false,
57+
},
58+
};
59+
const widget = widgetFactory.createWidget("colorPicker", props);
60+
61+
expect(widget.showText).toBe(false);
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)