function SearchForm({
uid = DOM.uid("autosuggestion").id,
placeholder = "",
description = "",
value = "",
format = (d) => d,
suggestion = () => []
} = {}) {
const input = htl.html`<input
type="text"
placeholder="${placeholder}"
list="${uid}"
autocomplete="off"
value=${format(value)}
>`;
const tag = htl.html`<div style="font-size: 0.85rem; font-style: italic; margin-top: 3px;">${description}</div>`;
const datalist = htl.html`<datalist id="${uid}">`;
const form = htl.html`<div>${input}${tag}${datalist}`;
let results = [];
form.value = value;
form.onsubmit = (event) => event.preventDefault();
form.onchange = (event) => {
const value = event.target.value;
form.value = results.find((d) => format(d) == value) || "";
input.blur();
form.dispatchEvent(new CustomEvent("input"));
};
const options = new Map();
const getOption = async (text) =>
options.get(text) ||
(text ? options.set(text, await suggestion(text)) : options.set(text, []),
options.get(text));
input.oninput = async (event) => {
let value = event.target.value;
results = await getOption(value);
d3.select(`#${uid}`)
.selectAll("option")
.data(results)
.join("option")
.attr("value", format);
};
return form;
}