-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathselect.js
More file actions
29 lines (25 loc) · 721 Bytes
/
select.js
File metadata and controls
29 lines (25 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import toArray from 'src/utils/toArray.js';
import { translateText } from 'src/utils/translate.js';
import Setting from './text.js';
export default class Select extends Setting {
constructor(name = 'select') {
super(name);
}
default([data] = []) {
const [l, v = l] = toArray(data);
return `${v}`;
}
element(value, update, {
data = [],
}) {
return $('<select>')
.append(options(data, value))
.on('change.script', (e) => update(e.target.value));
}
}
function options(data = [], current = '') {
return data.map((o) => {
const [l, v = l] = toArray(o);
return `<option value="${v}"${`${current}` === `${v}` ? ' selected' : ''}>${translateText(l)}</option>`;
});
}