Skip to content

Commit 3ab1ecc

Browse files
author
Joe Pavitt
committed
Add icon & colour customisation
1 parent 050195e commit 3ab1ecc

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

nodes/widgets/ui_switch.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
2323
topicType: {value: 'msg'},
2424
style: {value: ''},
25+
className: {value: ''},
26+
// on state
2527
onvalue: {value: true, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('onvalueType'):function(v) { return true})},
2628
onvalueType: {value: 'bool'},
2729
onicon: {value: '' },
2830
oncolor: {value: ''},
31+
// off state
2932
offvalue: {value: false, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('offvalueType'):function(v) { return true})},
3033
offvalueType: {value: 'bool'},
3134
officon: {value: ''},
32-
offcolor: {value: ''},
33-
animate: {value: false},
34-
className: {value: ''}
35+
offcolor: {value: ''}
3536
},
3637
inputs:1,
3738
outputs:1,
@@ -124,14 +125,12 @@
124125
<label for="node-input-tooltip"><i class="fa fa-info-circle"></i> Tooltip</label>
125126
<input type="text" id="node-input-tooltip" placeholder="optional tooltip">
126127
</div>-->
127-
<!--<div class="form-row">
128+
<div class="form-row">
128129
<label for="node-input-custom-icons"><i class="fa fa-picture-o"></i> Icon</label>
129130
<select id="node-input-custom-icons" style="width:35%">
130131
<option value="default">Default</option>
131132
<option value="custom">Custom</option>
132133
</select>
133-
<span style="width:auto; padding-left:20px" class="form-row-custom-icons" for="node-input-animate"> Animate
134-
<input type="checkbox" checked id="node-input-animate" style="display:inline-block; width:auto; vertical-align:baseline;"></span>
135134
</div>
136135
<div class="form-row form-row-custom-icons">
137136
<label for="node-input-onicon" style="text-align:right;"><i class="fa fa-toggle-on"></i> On Icon</label>
@@ -144,7 +143,7 @@
144143
<input type="text" id="node-input-officon" style="width:120px">
145144
<label for="node-input-offcolor" style="width:50px; text-align:right;">Colour</label>
146145
<input type="text" id="node-input-offcolor" style="width:120px">
147-
</div>-->
146+
</div>
148147
<div class="form-row">
149148
<label style="width:auto" for="node-input-onvalue"><i class="fa fa-envelope-o"></i> When clicked, send:</label>
150149
</div>

ui/src/widgets/ui-switch/UISwitch.vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
22
<div class="nrdb-switch" :class="{'nrdb-nolabel': !props.label}">
33
<label v-if="props.label" class="v-label">{{ props.label }}</label>
4-
<v-switch @click="onChange" v-model="state" class="nrdb-ui-widget" :class="{'active': state}" hide-details="auto" color="primary"></v-switch>
5-
</div>
4+
<v-switch v-if="!icon" @click="onChange" v-model="state" class="nrdb-ui-widget" :class="{'active': state}" hide-details="auto" color="primary"></v-switch>
5+
<v-btn v-else @click="toggle" class="ma-2" variant="text" :icon="icon" :color="color"></v-btn>
6+
</div>
67
</template>
78

89
<script>
@@ -18,13 +19,26 @@
1819
},
1920
computed: {
2021
...mapState('data', ['values']),
22+
icon: function () {
23+
if (this.props.onicon && this.props.officon) {
24+
const icon = this.state ? this.props.onicon : this.props.officon
25+
return 'mdi-' + icon
26+
} else {
27+
return null
28+
}
29+
},
30+
color: function () {
31+
if (this.props.oncolor || this.props.offcolor) {
32+
return this.state ? this.props.oncolor : this.props.offcolor
33+
}
34+
return null
35+
},
2136
value: function () {
2237
return this.values[this.id]
2338
},
2439
state: {
2540
get () {
2641
const val = this.values[this.id]
27-
console.log(this.props.evaluated, val)
2842
if (typeof(val) === 'boolean') {
2943
return val
3044
} else if (this.props.evaluated) {
@@ -45,6 +59,10 @@
4559
// only runs when clicked/changed in UI.
4660
// inverted as the store doesn't quite update quick enough, but this is reliable method
4761
this.$socket.emit(`widget-change:${this.id}`, !this.values[this.id])
62+
},
63+
toggle () {
64+
this.state = !this.state
65+
this.$socket.emit(`widget-change:${this.id}`, this.state)
4866
}
4967
}
5068
}

0 commit comments

Comments
 (0)