drop.chapril.org-firefoxsend/app/ui/selectbox.js
2022-05-02 13:38:16 +02:00

36 lines
884 B
JavaScript

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);
}
}
return html`
<select
id="${htmlId}"
class="appearance-none cursor-pointer border rounded bg-grey-10 hover:border-primary focus:border-primary pl-1 pr-8 py-1 my-1 h-8 dark:bg-grey-80"
data-selected="${selected}"
onchange="${choose}"
>
${options.map(
value =>
html`
<option value="${value}" ${value == selected ? 'selected' : ''}>
${translate(value)}
</option>
`
)}
</select>
`;
};