ctucx.git: mqtt-webui

webui for mqtt, can be used to control/display data in mqtt-topics

commit 7ef67e5b910e7dc3dd5f56d5d63b63973695fa61
parent d1f85fa145fca59cf091480e847ec6c976e29804
Author: Leah (ctucx) <git@ctu.cx>
Date: Mon, 12 Dec 2022 16:47:57 +0100

add button css
3 files changed, 37 insertions(+), 15 deletions(-)
M
src/webui.css
|
42
+++++++++++++++++++++++++++++++-----------
M
src/webui.js
|
8
+++++---
M
www/sw.js
|
2
+-
diff --git a/src/webui.css b/src/webui.css
@@ -16,6 +16,8 @@
 		--switch-knob-active-color:        #693;
 		--slider-background-color:         #ccc;
 		--slider-knob-color:               #6c757d;
+		--button-background-color:         #ccc;
+		--button-active-background-color:  #693;
 	}
 }
 

@@ -37,6 +39,8 @@
 		--switch-knob-active-color:        #693;
 		--slider-background-color:         #ebebf52e;
 		--slider-knob-color:               #9b9aa3;
+		--button-background-color:         #ebebf52e;
+		--button-active-background-color:  #693;
 	}
 
 	section img {

@@ -254,6 +258,29 @@ section > div .title{
 }
 
 
+/* Button Styling*/
+
+.buttons > button:first-child {
+	border-top-left-radius: .5em;
+	border-bottom-left-radius: .5em;
+}
+
+.buttons > button:last-child {
+	border-top-right-radius: .5em;
+	border-bottom-right-radius: .5em;
+}
+
+.buttons > button {
+	background-color: var(--button-background-color);
+	color: var(--secondary-text-color);
+	padding: .5em .7em;
+}
+
+.buttons > .active {
+	background-color: var(--button-active-background-color);
+}
+
+
 .loader {
 	border: 4px solid #ccc;
 	border-top: 4px solid #6c757d;

@@ -267,27 +294,20 @@ section > div .title{
 
 
 .working {
-	background-color: lightgray;
 	animation-name: color;
 	animation-duration: 1.5s;
 	animation-iteration-count: infinite;
 }
 
 @keyframes spin {
-	0% { transform: rotate(0deg); }
+	0% {   transform: rotate(0deg);   }
 	100% { transform: rotate(360deg); }
 }
 
 @keyframes color {
-  0% {
-	background-color: lightgray;
-  }
-  50% {
-	background-color: darkgray;
-  }
-  100% {
-	background-color: lightgray;
-  }
+	0% {   filter: brightness(85%); }
+	50% {  filter: brightness(50%); }
+	100% { filter: brightness(85%); }
 }
 
 @media screen and (max-width: 700px) {
diff --git a/src/webui.js b/src/webui.js
@@ -85,10 +85,11 @@ const onMessage = (topic, message) => {
 				document.getElementById(element.id + '_loader').classList.remove('loader');
 				break;
 
-			// untested
 			case 'button':
 				if (typeof value === 'object') return;
 
+				element.classList.remove('working');
+
 				if (element.dataset.mqttValue === value) {
 					element.classList.add('active');
 				} else {

@@ -221,19 +222,20 @@ const renderItem = (itemData) => {
 				`;
 				break;
 
-			// untested
 			case 'button':
 				const buttonClickHandler = (event) => {
 					if (!client.connected)           return false;
 					if (itemData.topic.set === null) return false;
 
+					event.target.classList.add('working');
+
 					client.publish(itemData.topic.set, transformMessage(event.target.dataset.mqttValue, itemData), itemData.mqtt);
 					return false;
 				}
 
 				const buttonElement = (button) => html`<button class="button" type="button" @click="${buttonClickHandler}" data-type="${itemData.type}" data-mqtt-value="${button.value}" data-mqtt-topic="${itemData.topic.get}" data-transform="${ifDefined(transform)}">${button.label}</button>`;
 
-				element = html`<div class="btn-group" role="group">${map(itemData.buttons, buttonElement)}</div>`;
+				element = html`<div class="buttons">${map(itemData.buttons, buttonElement)}</div>`;
 				break;
 
 			// untested
diff --git a/www/sw.js b/www/sw.js
@@ -50,7 +50,7 @@ let preCache = [
 	'./icons/weather.png'
 ];
 
-const CACHE = 'cache-v5';
+const CACHE = 'cache-v7';
 
 self.addEventListener('install', function (evt) {
 	self.skipWaiting();