fox-send/app/ui/selectbox.js

35 lines
760 B
JavaScript
Raw Normal View History

2018-10-25 02:07:10 +00:00
const html = require('choo/html');
module.exports = function(selected, options, translate, changed, htmlId) {
2018-10-25 02:07:10 +00:00
let x = selected;
return html`
2018-11-16 20:39:36 +00:00
<select
id="${htmlId}"
2018-11-16 20:39:36 +00:00
class="appearance-none cursor-pointer border rounded-sm bg-blue-lightest hover:border-blue focus:border-blue px-2 py-1 my-2 h-8"
onchange="${choose}"
>
${
options.map(
i =>
html`
<option value="${i}" ${i === selected ? 'selected' : ''}
>${translate(i)}</option
>
`
)
}
</select>
`;
2018-10-25 02:07:10 +00:00
function choose(event) {
const target = event.target;
const value = +target.value;
if (x !== value) {
x = value;
changed(value);
}
}
};