import { formatValue } from '../../lib/format'; import { FEATURE_GRADIENT, DENSITY_GRADIENT, DENSITY_GRADIENT_DARK, ENUM_PALETTE, } from '../../lib/consts'; import { gradientToCss } from '../../lib/utils'; import { CloseIcon } from '../ui/icons/CloseIcon'; import { TickerValue } from '../ui/TickerValue'; function EnumSwatches({ values }: { values: string[] }) { return (
{values.map((label, i) => { const color = ENUM_PALETTE[i % ENUM_PALETTE.length]; return (
{label}
); })}
); } function InlineEnumSwatches({ values }: { values: string[] }) { return (
{values.map((label, i) => { const color = ENUM_PALETTE[i % ENUM_PALETTE.length]; return (
{label}
); })}
); } export default function MapLegend({ featureLabel, range, showCancel, onCancel, mode, enumValues, theme = 'light', inline = false, suffix, raw, }: { featureLabel: string; range: [number, number]; showCancel: boolean; onCancel: () => void; mode: 'feature' | 'density'; enumValues?: string[]; theme?: 'light' | 'dark'; inline?: boolean; suffix?: string; raw?: boolean; }) { const isEnum = enumValues && enumValues.length > 0; const densityGradient = theme === 'dark' ? DENSITY_GRADIENT_DARK : DENSITY_GRADIENT; const gradientStyle = mode === 'density' ? gradientToCss(densityGradient) : gradientToCss(FEATURE_GRADIENT); const fmt = raw ? { raw: true } : undefined; const rangeMin = mode === 'density' ? ( ) : isEnum ? null : ( ); const rangeMax = mode === 'density' ? ( ) : isEnum ? null : ( ); if (inline) { return (
{featureLabel} {showCancel && ( )} {isEnum ? ( ) : (
{rangeMin}
{rangeMax}
)}
); } return (
{featureLabel} {showCancel && ( )}
{isEnum ? ( ) : ( <>
{rangeMin} {rangeMax}
)}
); }