CSS Styling ui-button Widgets on Dashboard 2

According to the help for the ui-button widget, there are several properties you can change by passing a valid msg.ui_update:

I have an example where the icon changes when the button is pressed - not sure if I included this in the demo.

let state = context.get("buttonstate") || "on" 
if (state === "on") {
    state = "off"
    msg.class = "redicon"
    msg.ui_update = {"icon": "pig"}
}
else {
    state = "on"
    msg.class = "greenicon"
    msg.ui_update = {"icon": "cat"}
}
context.set ("buttonstate", state)
return msg;

NB Looking at it after a couple of months, I would try and avoid using msg.class to change properties that are available via msg.ui_update. I don't know if class greenicon and redicon are really necessary. (It's possible that the node's dynamic styling has been improved since I started playing with it)

It is important to keep your dashboard button in sync with other sources of button actions.
One approach is by passing these actions through the button - there is a check box for this.


But this can very easily result in a runaway loop. I think you need to ensure that any message sent from the function node does not have a msg.payload.