fetchButton = function(onSubmit, options = {}) {
let {
title = "Click Me",
style = {},
initialValue = undefined,
className = "",
button = `<button class="${className}" style="${formatStyle(style)}">
${title}
</button>`,
fetchingValue = "Working...",
alterWhileFetching = true
} = options;
const form = html`<form>${button}</form>`;
form.value = initialValue;
form.addEventListener("submit", event => {
if (alterWhileFetching) {
form.value = fetchingValue;
form.dispatchEvent(new CustomEvent("input"));
}
form.value = onSubmit();
form.dispatchEvent(new CustomEvent("input"));
event.preventDefault();
});
return form;
}