Skip to content

Commit

Permalink
Merge pull request #172 from gisce/69649/tag-field-color
Browse files Browse the repository at this point in the history
Tag: allow colorField to define color for tag
  • Loading branch information
ecarreras authored Feb 6, 2025
2 parents 04be77f + 2fffce3 commit 14ff888
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,19 @@ class Field extends Widget {
super.readOnly = value;
}

_raw_props: any;
get raw_props(): any {
return this._raw_props;
}

constructor(props: any) {
super(props);

// Activated by default
this._activated = true;

if (props) {
this._raw_props = props;
if (props.name) {
this._id = props.name;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Tag extends Selection {
get colors(): any | "auto" {
return this._parsedWidgetProps.colors || {};
}

get colorField(): string | null {
return this._parsedWidgetProps?.colorField || null;
}
}

export default Tag;
22 changes: 22 additions & 0 deletions src/spec/Tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,26 @@ describe("A Tag widget", () => {
expect(widget.colors).toStrictEqual("auto");
});
});

describe("colorField property", () => {
it("should have default colorField to null", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
};
const widget = widgetFactory.createWidget("tag", props);

expect(widget.colorField).toBeNull();
});
it("should parse colorField property", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
widget_props: '{"colorField": "color"}',
};
const widget = widgetFactory.createWidget("tag", props);

expect(widget.colorField).toBe("color");
});
});
});

0 comments on commit 14ff888

Please sign in to comment.