Show indicator for current preset

This commit is contained in:
redphx
2024-12-09 19:59:30 +07:00
parent 3230b99a05
commit d0a8b894b9
7 changed files with 26 additions and 25 deletions

View File

@@ -263,10 +263,10 @@ export function clearDataSet($elm: HTMLElement) {
});
}
export function renderPresetsList<T extends PresetRecord>($select: HTMLSelectElement, allPresets: AllPresets<T>, selectedValue: number | null, addOffValue=false) {
export function renderPresetsList<T extends PresetRecord>($select: HTMLSelectElement, allPresets: AllPresets<T>, selectedValue: number | null, options: { addOffValue?: boolean, selectedIndicator?: boolean }={}) {
removeChildElements($select);
if (addOffValue) {
if (options.addOffValue) {
const $option = CE<HTMLOptionElement>('option', { value: 0 }, t('off'));
$option.selected = selectedValue === 0;
@@ -284,8 +284,13 @@ export function renderPresetsList<T extends PresetRecord>($select: HTMLSelectEle
const $optGroup = CE('optgroup', { label: groups[key] });
for (const id of allPresets[key]) {
const record = allPresets.data[id];
const $option = CE<HTMLOptionElement>('option', { value: record.id }, record.name);
$option.selected = selectedValue === record.id;
const selected = selectedValue === record.id;
const name = options.selectedIndicator && selected ? '✅ ' + record.name : record.name;
const $option = CE<HTMLOptionElement>('option', { value: record.id }, name);
if (selected) {
$option.selected = true;
}
$optGroup.appendChild($option);
}