More FE changes

This commit is contained in:
Andras Schmelczer 2026-05-09 09:43:41 +01:00
parent f114ada255
commit a48eb945e0
48 changed files with 4127 additions and 1751 deletions

View file

@ -28,6 +28,22 @@ function ResetScaleIcon({ className = 'w-4 h-4' }: { className?: string }) {
);
}
function requireFeatureName(featureName: string | undefined): string {
if (!featureName) {
throw new Error('Enum legend requested without a feature name');
}
return featureName;
}
function requireEnumPalette(
palette: [number, number, number][] | null
): [number, number, number][] {
if (!palette) {
throw new Error('Enum legend requested without a palette');
}
return palette;
}
function EnumSwatches({
values,
palette,
@ -114,7 +130,9 @@ export default function MapLegend({
const { t } = useTranslation();
const isEnum = enumValues && enumValues.length > 0;
const showResetScale = Boolean(onResetScale) && !isEnum;
const enumPalette = getEnumPaletteForFeature(featureName ?? null, enumValues);
const enumPalette = isEnum
? getEnumPaletteForFeature(requireFeatureName(featureName), enumValues)
: null;
const densityGradient = theme === 'dark' ? DENSITY_GRADIENT_DARK : DENSITY_GRADIENT;
const gradientStyle =
mode === 'density'
@ -165,7 +183,7 @@ export default function MapLegend({
</button>
)}
{isEnum ? (
<InlineEnumSwatches values={enumValues} palette={enumPalette} />
<InlineEnumSwatches values={enumValues} palette={requireEnumPalette(enumPalette)} />
) : (
<div className="flex items-center gap-1.5 flex-1 min-w-[40%] text-warm-500 dark:text-warm-400">
{rangeMin}
@ -213,7 +231,7 @@ export default function MapLegend({
)}
</div>
{isEnum ? (
<EnumSwatches values={enumValues} palette={enumPalette} />
<EnumSwatches values={enumValues} palette={requireEnumPalette(enumPalette)} />
) : (
<>
<div className="h-3 rounded" style={{ background: gradientStyle }} />