Skip to content

Commit 14ff888

Browse files
authored
Merge pull request #172 from gisce/69649/tag-field-color
Tag: allow colorField to define color for tag
2 parents 04be77f + 2fffce3 commit 14ff888

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Field.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,19 @@ class Field extends Widget {
147147
super.readOnly = value;
148148
}
149149

150+
_raw_props: any;
151+
get raw_props(): any {
152+
return this._raw_props;
153+
}
154+
150155
constructor(props: any) {
151156
super(props);
152157

153158
// Activated by default
154159
this._activated = true;
155160

156161
if (props) {
162+
this._raw_props = props;
157163
if (props.name) {
158164
this._id = props.name;
159165
}

src/Tag.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class Tag extends Selection {
77
get colors(): any | "auto" {
88
return this._parsedWidgetProps.colors || {};
99
}
10+
11+
get colorField(): string | null {
12+
return this._parsedWidgetProps?.colorField || null;
13+
}
1014
}
1115

1216
export default Tag;

src/spec/Tag.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,26 @@ describe("A Tag widget", () => {
4444
expect(widget.colors).toStrictEqual("auto");
4545
});
4646
});
47+
48+
describe("colorField property", () => {
49+
it("should have default colorField to null", () => {
50+
const widgetFactory = new WidgetFactory();
51+
const props = {
52+
name: "status",
53+
};
54+
const widget = widgetFactory.createWidget("tag", props);
55+
56+
expect(widget.colorField).toBeNull();
57+
});
58+
it("should parse colorField property", () => {
59+
const widgetFactory = new WidgetFactory();
60+
const props = {
61+
name: "status",
62+
widget_props: '{"colorField": "color"}',
63+
};
64+
const widget = widgetFactory.createWidget("tag", props);
65+
66+
expect(widget.colorField).toBe("color");
67+
});
68+
});
4769
});

0 commit comments

Comments
 (0)