send/app/templates/selectbox/index.js

33 lines
725 B
JavaScript
Raw Normal View History

2017-11-30 21:41:09 +00:00
const html = require('choo/html');
module.exports = function(selected, options, translate, changed) {
const id = `select-${Math.random()}`;
let x = selected;
2018-02-16 20:56:53 +00:00
return html`
<span class="select">
<select id="${id}" onchange=${choose}>
2018-02-16 20:56:53 +00:00
${options.map(
i =>
html`<option value="${i}" ${
i === selected ? 'selected' : ''
}>${translate(i)}</option>`
2018-02-16 20:56:53 +00:00
)}
</select>
<svg id="arrow" width="32" height="32">
<polygon points="8 18 17 28 26 18" fill="#0094fb"/>
</svg>
</span>`;
2017-11-30 21:41:09 +00:00
function choose(event) {
const target = event.target;
const value = +target.value;
2017-11-30 21:41:09 +00:00
if (x !== value) {
x = value;
changed(value);
}
}
};