UX: make working with ranges and units easier for theme developers, show ranges in selected unit by converting them

This commit is contained in:
Pieter Vander Vennet 2025-09-11 02:13:07 +02:00
parent d64ad9b643
commit e157a84710
5 changed files with 25 additions and 15 deletions

View file

@ -14,6 +14,7 @@
import type { ValueRange } from "../../Models/ThemeConfig/TagRenderingConfig"
import Translations from "../i18n/Translations"
import BaseUIElement from "../BaseUIElement"
import { Denomination } from "../../Models/Denomination"
export let type: ValidatorType
export let feedback: UIEventSource<Translation> | undefined = undefined
@ -91,6 +92,7 @@
if (!range) {
return true
}
const currentUnit: Denomination = unit.denominations.find(d => d.canonical === selectedUnit?.data)
if (typeof canonicalValue === "string") {
canonicalValue = Number(canonicalValue)
}
@ -103,7 +105,11 @@
if (canonicalValue > range.max) {
let max: number | string | BaseUIElement = range.max
if (unit) {
max = unit.asHumanLongValue(max, getCountry)
if (currentUnit?.factorToCanonical !== undefined) {
max = unit.asHumanLongValue(Math.round(max / currentUnit.factorToCanonical) + currentUnit.canonical, getCountry)
} else {
max = unit.asHumanLongValue(max, getCountry)
}
}
feedback.set(t.tooHigh.Subs({ max }))
return false
@ -111,7 +117,11 @@
if (canonicalValue < range.min) {
let min: number | string | BaseUIElement = range.min
if (unit) {
if (currentUnit?.factorToCanonical !== undefined) {
min = unit.asHumanLongValue(Math.round(min / currentUnit.factorToCanonical) + currentUnit.canonical, getCountry)
} else {
min = unit.asHumanLongValue(min, getCountry)
}
}
feedback.set(t.tooLow.Subs({ min }))
return false