2017-11-30 22:41:09 +01:00
|
|
|
const html = require('choo/html');
|
|
|
|
|
|
|
|
module.exports = function(selected, options, translate, changed) {
|
|
|
|
const id = `select-${Math.random()}`;
|
|
|
|
let x = selected;
|
|
|
|
|
2018-02-16 21:56:53 +01:00
|
|
|
return html`
|
2018-03-28 08:19:07 +02:00
|
|
|
<div class="select">
|
2018-03-13 14:13:07 +01:00
|
|
|
<select id="${id}" onchange=${choose}>
|
2018-02-16 21:56:53 +01:00
|
|
|
${options.map(
|
2018-03-13 14:13:07 +01:00
|
|
|
i =>
|
|
|
|
html`<option value="${i}" ${
|
|
|
|
i === selected ? 'selected' : ''
|
|
|
|
}>${translate(i)}</option>`
|
2018-02-16 21:56:53 +01:00
|
|
|
)}
|
2018-03-13 14:13:07 +01:00
|
|
|
</select>
|
2018-03-28 08:19:07 +02:00
|
|
|
</div>`;
|
2017-11-30 22:41:09 +01:00
|
|
|
|
|
|
|
function choose(event) {
|
|
|
|
const target = event.target;
|
2018-03-13 14:13:07 +01:00
|
|
|
const value = +target.value;
|
|
|
|
|
2017-11-30 22:41:09 +01:00
|
|
|
if (x !== value) {
|
|
|
|
x = value;
|
|
|
|
changed(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|