Skip to content

Commit cdedda8

Browse files
committed
feat(Indicator): allow dynamic icon and color
1 parent 41f2c3d commit cdedda8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Indicator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Selection from "./Selection";
2+
import { replaceEntities } from "./helpers/attributeParser";
23

34
class Indicator extends Selection {
45
_nolabel: boolean = true;
@@ -30,6 +31,11 @@ class Indicator extends Selection {
3031
this._suffix = value;
3132
}
3233

34+
_color: string | undefined = undefined;
35+
get color(): string | undefined {
36+
return this._color;
37+
}
38+
3339
/**
3440
* Action id
3541
*/
@@ -58,8 +64,9 @@ class Indicator extends Selection {
5864
this._suffix = "";
5965
if (this._parsedWidgetProps) {
6066
this._card = this._parsedWidgetProps.card || false;
61-
this._icon = this._parsedWidgetProps.icon || "";
67+
this._icon = replaceEntities(this._parsedWidgetProps.icon) || "";
6268
this._suffix = this._parsedWidgetProps.suffix || "";
69+
this._color = replaceEntities(this._parsedWidgetProps.color) || "";
6370
}
6471
if (props) {
6572
if (props.action_id) {

src/spec/Indicator.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ describe("An Indicator", () => {
4343
const widget = widgetFactory.createWidget("indicator", props);
4444
expect(widget.card).toBe(false);
4545
});
46+
it("should allow conditions in icon widget props", () => {
47+
const widgetFactory = new WidgetFactory();
48+
const props = {
49+
widget_props: "{'icon': 'alert-triange:value>10;wallet:value==0'}",
50+
};
51+
const widget = widgetFactory.createWidget("indicator", props);
52+
expect(widget.icon).toBe("alert-triange:value>10;wallet:value==0");
53+
});
54+
it("should allow color in widget props", () => {
55+
const widgetFactory = new WidgetFactory();
56+
const props = {
57+
widget_props: "{'color': 'red'}",
58+
};
59+
const widget = widgetFactory.createWidget("indicator", props);
60+
expect(widget.color).toBe("red");
61+
});
4662
});

0 commit comments

Comments
 (0)