function questionSelector(sheet, {
startIndex = 1,
filter = null
} = {}) {
let questions = Object.values(sheet.questions)
if(filter) questions = questions.filter(filter)
const startValue = questions[startIndex];
const type = (x) => {
if(x.type == "choice") return "🔘"
if(x.type == "multi") return "✅"
if(x.type == "free") return "🖋"
return "🔘"
}
const radio = Inputs.radio(questions, {format: x => html`<div style="display:flex; justify-content:space-between;width: 100%;line-height:2em">
<div style="">${x.question}</div>
<div style="opacity: 0.3;filter:grayscale(100%)" title="${prettyType(x.type)}">${type(x)} </div>
</div>`, value: startValue});
const parent = radio.getElementsByTagName("div")[0];
parent.style = "max-height: 250px; overflow-y: scroll";
const labels = radio.getElementsByTagName("label");
for (let label of labels) {
label.style = "display:flex; justify-content:space-between; margin-bottom: 5px; min-height:2em;"
}
const filterRows = (filterQuery) => {
const query = filterQuery.toUpperCase();
const labels = radio.getElementsByTagName("label");
for (let label of labels) {
label.textContent.toUpperCase().indexOf(query) > -1
? label.style.display = "flex"
: label.style.display = "none";
}
};
const filterer = html`
<input
autocomplete="off"
type="search"
style="position: sticky"
placeholder="Filter questions..."
oninput=${(e) => filterRows(e.target.value)}
>
`;
const selector = html`
${filterer}
<div style="margin-top: 10px" class="radios">${radio}</div>
<style>
.radios label {
border-bottom: 1px solid #fff;
}
.radios label:hover {
cursor: pointer;
border-bottom: 1px solid #eee;
/*background-color: #efefef;/*
}
</style>
`;
selector.value = radio.value;
selector.addEventListener("input", e => {
selector.value = radio.value;
});
return selector;
}