fox-send/app/ui/selectbox.js

29 lines
829 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) {
function choose(event) {
if (event.target.value != selected) {
console.log('Selected new value from dropdown', htmlId, ':', selected, '->', event.target.value)
changed(event.target.value);
}
}
2018-10-25 02:07:10 +00:00
return html`
2018-11-16 20:39:36 +00:00
<select
id="${htmlId}"
2019-09-09 17:34:55 +00:00
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"
data-selected="${selected}"
2018-11-16 20:39:36 +00:00
onchange="${choose}"
>
2019-01-24 20:31:20 +00:00
${options.map(
value =>
2019-01-24 20:31:20 +00:00
html`
<option value="${value}" ${value == selected ? 'selected' : ''}>
${translate(value)}
</option>
2019-01-24 20:31:20 +00:00
`
)}
2018-11-16 20:39:36 +00:00
</select>
`;
2018-10-25 02:07:10 +00:00
};