This is a bit of a continuation of my CSS
thread.
This one.
Given that we have the button design understood now, we not add a but of code so when the button is pressed an output is generated.
This is the code from which we will be building.
[{"id":"bded269f.23a12","type":"ui_template","z":"1781e581.31721a","group":"6ab22327.a2f71c","name":"THIS IS THE TEMPLATE","order":7,"width":0,"height":0,"format":"<style id=\"remote-buttons\">\n :root {\n --dashboard-unit-width: 48px;\n --dashboard-unit-height: 48px;\n }\n .nr-dashboard-template {\n padding: 0px;\n }\n .remote-button:not([disabled]):hover{\n background-color: #232323 !important;\n }\n\n /* This is the normal button definition */\n .remote-button{\n background-color: black !important;\n color: #cccccc !important;\n height: var(--dashboard-unit-height);\n width: 100%;\n border-radius: 10px;\n font-size:1.0em;\n font-weight:normal;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n /* This is a sub-set which is invoked by */\n /* <md-button class=\"md-button remote-button bigger\"> */\n /* note the (space) \"bigger\" at the end. */\n .remote-button.bigger{\n font-weight:bold;\n font-size:1.5em;\n }\n /* This is for buttons with a lot of text. `font-size:0.7em` */\n /* makes the font 70% normal size */\n .remote-button.small{\n font-size:0.7em;\n }\n /* This is for buttons with just icons, to upsize the size */\n /* of the icon with the line: */\n /* <i class=\"fa fa-fw fa-plus remote-icon\"> in the other node */\n .remote-icon{\n font-size:2.0em;\n }\n /* This is the same as the other one, but it makes the icon smaller */\n .remote-iconS{\n font-size:0.5em;\n }\n\n .remote-button.black{\n background-color: black !important;\n color: #cccccc !important;\n }\n\n .remote-button.red{\n background-color: red !important;\n color: #cccccc !important;\n }\n .remote-button.red:not([disabled]):hover{\n background-color: orange !important;\n }\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","x":530,"y":1410,"wires":[[]]},{"id":"797fdca7.e44f6c","type":"ui_template","z":"1781e581.31721a","group":"eabe7d43.b23f48","name":"1","order":1,"width":1,"height":1,"format":"<div id=\"regular_1\">\n <md-button class=\"md-button remote-button bigger\">1\n </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n\n$('#regular_1').on('click', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"momentary_regular\",\"payload\": 1});\n});\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":250,"y":1550,"wires":[["1cf586b3.c22e71"]]},{"id":"45e5a406.7764d4","type":"ui_template","z":"1781e581.31721a","group":"eabe7d43.b23f48","name":"vol + *","order":13,"width":1,"height":1,"format":"<div id=\"regular_plus\">\n <md-button class=\"md-button remote-button\">\n <span style=\"color:{{msg.colour}}\" class=\"fa fa-plus remote-icon\"> </span>\n </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n \n$('#regular_plus').on('click', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"regular_plus\",\"payload\": \"vol-up\"});\n});\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":250,"y":1750,"wires":[["69848a07.c10464"]],"info":"<div id=\"regular_plus\">\n <md-button class=\"md-button remote-button\">\n <i class=\"fa fa-plus remote-icon\"></i>\n </md-button>\n</div>"},{"id":"bc978fd4.0ec948","type":"ui_template","z":"1781e581.31721a","group":"eabe7d43.b23f48","name":"mute","order":14,"width":1,"height":1,"format":"<div>\n <md-button id=\"mute-button\" class=\"md-button remote-button\" \n data-state=\"on\" ng-click=\"toggleMute()\" >\n <i class=\"material-icons md-48\">volume_off</i>\n </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n\n var btnSelector = \"#mute-button\";//Set the selector to match the button ID above\n var topic = \"mute\"; //edit me to suit - this is sent to your flow as msg.topic\n var icon1 = \"volume_up\";//on icon\n var icon2 = \"volume_off\";//muted icon\n \n //create a function to call in ng-click (see the md-button attributes above)\n scope.toggleMute = function(){\n debugger\n var $btn = $(btnSelector);\n var currentState = $btn.data(\"state\");\n //if currently on, change to off state & send new payload\n if(currentState == \"on\"){\n mute($btn);\n $scope.send({\"topic\":topic,\"payload\": \"off\"});\n } else {\n unmute($btn);\n $scope.send({\"topic\":topic,\"payload\": \"on\"});\n }\n } \n //watch for node-red msgs\n scope.$watch('msg', function(msg) {\n var $btn = $(btnSelector);\n if (msg) {\n if(msg.payload == \"on\"){\n unmute($btn);\n } else if(msg.payload == \"off\"){\n mute($btn);\n }\n \n }\n }); \n //helper function to set the correct icon & update the \"data-state\" memory\n function mute($btn){\n var $ico = $btn.find(\"i\");\n $btn.data(\"state\",\"off\");//set data-state to off (remember state)\n // $ico.removeClass(\"fa-volume_mute\")\n // $ico.addClass(\"fa-volume_off\")\n $ico.text(icon2);\n }\n //helper function to set the correct icon & update the \"data-state\" memory\n function unmute($btn){\n var $ico = $btn.find(\"i\");\n $btn.data(\"state\",\"on\");//set data-state to on (remember state)\n // ico.removeClass(\"fa-volume_off\");\n // ico.addClass(\"fa-volume_mute\");\n $ico.text(icon1);\n }\n\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":490,"y":1750,"wires":[["9d7f3cad.d7b8f"]],"info":" class=\"material-icons\"> volume_off"},{"id":"6ab22327.a2f71c","type":"ui_group","z":"","name":"HOME","tab":"6d306f92.ccc54","order":1,"disp":true,"width":3,"collapse":false},{"id":"eabe7d43.b23f48","type":"ui_group","z":"","name":"Full_Remote2","tab":"b128eb09.9f681","order":3,"disp":false,"width":"3","collapse":false},{"id":"6d306f92.ccc54","type":"ui_tab","z":"","name":"TEST","icon":"dashboard","order":3,"disabled":false,"hidden":false},{"id":"b128eb09.9f681","type":"ui_tab","z":"","name":"HDMI_TV_control","icon":"dashboard","order":7,"disabled":false,"hidden":false}]
Three types of buttons.
1 - Basic button. You press it and it sends a message.
2 - Two message button. One sent when pressed, and one sent when released.
This button also accepts input to set the colour of the icon.
3 - Another button which also accepts input to determine which icon is shown.
(The mute button)