1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-10 13:13:00 +01:00
send/app/ui/selectbox.js
2019-10-03 23:10:11 -07:00

33 lines
748 B
JavaScript

const html = require('choo/html');
module.exports = function(selected, options, translate, changed, htmlId) {
let x = selected;
return html`
<select
id="${htmlId}"
class="appearance-none cursor-pointer border rounded bg-grey-10 hover:border-blue-50 focus:border-blue-50 pl-1 pr-8 py-1 my-1 h-8 dark:bg-grey-80"
onchange="${choose}"
>
${options.map(
i =>
html`
<option value="${i}" ${i === selected ? 'selected' : ''}
>${translate(i)}</option
>
`
)}
</select>
`;
function choose(event) {
const target = event.target;
const value = +target.value;
if (x !== value) {
x = value;
changed(value);
}
}
};