import { Box, Typography } from '@mui/material' import { styles } from './styles' import { LegendSwatch, DEFAULT_SWATCH_SIZE, } from '../legend-swatch/legend-swatch' import type { LegendCategoryVariable } from '../../stores' export interface LegendCategoryUIProps { data: LegendCategoryVariable } const MIN_GUTTER = 16 /** * Categorical legend — a list of swatches with labels (and optional trailing * values, compact-formatted). The variable-level shape / fill pattern / * stroke style / `isStrokeColor` act as defaults; each item may override any * of them, so one list can mix patterns (or shapes) across entries. * * @experimental This API is new and may change in a future release. */ export function LegendCategoryUI({ data }: LegendCategoryUIProps) { const { items, shape = 'circle', isStrokeColor = false, fillPattern = 'solid', strokeStyle = 'solid', orientation = 'vertical', } = data const horizontal = orientation === 'horizontal' // Fixed gutter wide enough for the largest swatch so labels align — only // meaningful in the vertical list; horizontal chips size to content. const maxSize = items.reduce( (m, it) => Math.max(m, it.size ?? DEFAULT_SWATCH_SIZE), 0, ) const gutter = Math.max(MIN_GUTTER, maxSize) return ( {items.map((item, index) => ( {item.label} {item.value != null && ( {item.value} )} ))} ) }