dropdown: make values dynamic, drop unreleased support for sendKey and receiving key (issue #140)
This commit is contained in:
parent
52f33892a1
commit
6c34c71975
4 changed files with 59 additions and 48 deletions
|
|
@ -9,7 +9,7 @@
|
|||
- prevent client to load multiple sessions simultaneously
|
||||
- widgets
|
||||
- switch: wrap non-array `values` property in an array
|
||||
- dropdown: wrap non-array `values` property in an array; allow setting value by its key/index; add `sendKey` option;
|
||||
- dropdown: wrap non-array `values` property in an array; always add a default empty value
|
||||
- property inheritance: added shorthand default to `_value` when no property is specified (`@{widgetId}`); some properties can now be dynamically changed without recreating the widget entirely
|
||||
- property maths: added support for math expressions everywhere via `#{}`
|
||||
- input: add glass effect when `editable` is `false`
|
||||
|
|
|
|||
|
|
@ -100,14 +100,10 @@ Setting the `push`'s value externally (via osc) will toggle it's inner light.
|
|||
}
|
||||
```
|
||||
|
||||
### `values`
|
||||
### `values`<i class="md-icon" title="dynamic">flash_on</i>
|
||||
- type: `array|object`
|
||||
- default: `{"Value 1":1,"Value 2":2}`
|
||||
- usage:
|
||||
- `array` of possible values to switch between : `[1,2,3]`
|
||||
- `object` of `"label":value` pairs
|
||||
|
||||
### `sendKey`
|
||||
- type: `boolean`
|
||||
- default: `false`
|
||||
- usage: set to `true` to make the dropdown send its selected value's key/index as value. Either way, the dropdown's value can be set using it's value or the associated key/index.
|
||||
- an empty option will always be prepended to `values` (sends an osc message without any value)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var Widget = require('../common/widget'),
|
||||
{iconify} = require('../../ui/utils')
|
||||
|
||||
module.exports = class Dropdown extends Widget {
|
||||
class Dropdown extends Widget {
|
||||
|
||||
static defaults() {
|
||||
|
||||
|
|
@ -26,7 +26,6 @@ module.exports = class Dropdown extends Widget {
|
|||
_dropdown:'dropdown',
|
||||
|
||||
values:{"Value 1":1,"Value 2":2},
|
||||
sendKey: false,
|
||||
value:'',
|
||||
|
||||
_osc:'osc',
|
||||
|
|
@ -48,22 +47,10 @@ module.exports = class Dropdown extends Widget {
|
|||
this.values = []
|
||||
this.keys = []
|
||||
|
||||
var i = 0,
|
||||
values = this.getProp('values')
|
||||
|
||||
if (!Array.isArray(values) && !(typeof values === 'object' && values !== null)) {
|
||||
values = [values]
|
||||
}
|
||||
|
||||
for (var k in values) {
|
||||
this.values.push(values[k])
|
||||
this.keys.push(k)
|
||||
this.select.innerHTML += `<option value="${i}">${iconify(parseFloat(k) != k ? k : values[k])}</option>`
|
||||
i++
|
||||
}
|
||||
this.parseValues()
|
||||
|
||||
this.select.addEventListener('change', ()=>{
|
||||
this.setValue(this.values[this.select.selectedIndex], {sync:true, send:true, fromLocal:true})
|
||||
this.setValue(this.values[this.select.selectedIndex - 1], {sync:true, send:true, fromLocal:true})
|
||||
})
|
||||
|
||||
this.value = undefined
|
||||
|
|
@ -72,25 +59,64 @@ module.exports = class Dropdown extends Widget {
|
|||
|
||||
}
|
||||
|
||||
parseValues() {
|
||||
|
||||
var i = 0,
|
||||
values = this.getProp('values'),
|
||||
html = ''
|
||||
|
||||
if (!Array.isArray(values) && !(typeof values === 'object' && values !== null)) {
|
||||
values = values !== '' ? [values] : []
|
||||
}
|
||||
|
||||
html += `<option value=""></option>`
|
||||
|
||||
this.values = []
|
||||
|
||||
for (var k in values) {
|
||||
this.values.push(values[k])
|
||||
html += `<option value="${i}">${iconify(parseFloat(k) != k ? k : values[k])}</option>`
|
||||
i++
|
||||
}
|
||||
|
||||
this.select.innerHTML = html
|
||||
|
||||
}
|
||||
|
||||
setValue(v,options={}) {
|
||||
|
||||
var i = this.values.indexOf(v)
|
||||
|
||||
if (i == -1) i = this.keys.indexOf(v)
|
||||
this.value = this.values[i]
|
||||
|
||||
if (i == -1 && typeof v == 'number' && v >= 0 && v < this.values.length) i = v
|
||||
if (!options.fromLocal) this.select.selectedIndex = i + 1
|
||||
|
||||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
|
||||
}
|
||||
|
||||
onPropChanged(propName, options) {
|
||||
|
||||
var ret = super.onPropChanged(...arguments)
|
||||
|
||||
switch (propName) {
|
||||
|
||||
case 'values':
|
||||
this.parseValues()
|
||||
return
|
||||
|
||||
if (i != -1) {
|
||||
this.value = this.getProp('sendKey') ? this.keys[i] : this.values[i]
|
||||
if (!options.fromLocal) this.select.selectedIndex = i
|
||||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
this.container.classList.remove('noselect')
|
||||
} else {
|
||||
this.value = undefined
|
||||
this.select.selectedIndex = -1
|
||||
if (options.sync) this.changed(options)
|
||||
this.container.classList.add('noselect')
|
||||
}
|
||||
|
||||
}}
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Dropdown.dynamicProps = Dropdown.prototype.constructor.dynamicProps.concat(
|
||||
'values'
|
||||
)
|
||||
|
||||
|
||||
module.exports = Dropdown
|
||||
|
|
|
|||
|
|
@ -151,17 +151,6 @@
|
|||
width:100rem;
|
||||
height: 60rem;
|
||||
padding:1rem;
|
||||
&.noselect .select:before {
|
||||
content:"...";
|
||||
position: absolute;
|
||||
padding-left:10rem;
|
||||
left:0;
|
||||
top:50%;
|
||||
margin-top:-12rem;
|
||||
height: 20rem;
|
||||
line-height: 20rem;
|
||||
pointer-events: none;
|
||||
}
|
||||
&.nolabel {
|
||||
--color-border:var(--color-bg);
|
||||
padding: 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue