feat(settings): improve currency preferences UI (#1483)

* feat(settings): improve currency preferences UI

* fix: remove redundant keydown action from currency search input

* fix(settings): localize currency count pluralization in dialog

* feat: update selected count handling with pluralization support
This commit is contained in:
Ang Wei Feng (Ted)
2026-04-18 06:06:08 +08:00
committed by GitHub
parent f46554e4b1
commit c46aa09607
3 changed files with 132 additions and 59 deletions

View File

@@ -1,12 +1,19 @@
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ["dialog", "checkbox"];
static targets = ["dialog", "checkbox", "selectedCount"];
static values = {
baseCurrency: String,
locale: String,
selectedCountTranslations: Object,
};
connect() {
this.updateSelectedCount();
}
open() {
this.updateSelectedCount();
this.dialogTarget.showModal();
}
@@ -14,12 +21,31 @@ export default class extends Controller {
this.checkboxTargets.forEach((checkbox) => {
checkbox.checked = true;
});
this.updateSelectedCount();
}
selectBaseOnly() {
this.checkboxTargets.forEach((checkbox) => {
checkbox.checked = checkbox.value === this.baseCurrencyValue;
});
this.updateSelectedCount();
}
updateSelectedCount() {
if (!this.hasSelectedCountTarget) return;
const selectedCount = this.checkboxTargets.filter((checkbox) => checkbox.checked).length;
const pluralRules = new Intl.PluralRules(this.localeValue || undefined);
const pluralCategory = pluralRules.select(selectedCount);
const labelTemplate =
this.selectedCountTranslationsValue[pluralCategory] ||
this.selectedCountTranslationsValue.other ||
"%{count}";
const label = labelTemplate.replace("%{count}", selectedCount);
this.selectedCountTarget.textContent = label;
}
handleSubmitEnd(event) {