import { ReactNode, useCallback } from 'react'; import { Box, Flex, Text } from 'gestalt'; import LegendIcon from './LegendIcon'; type ReferenceAreaSummaryItem = { label: string; style?: 'default'; }; export default function useDefaultLegend({ isHorizontalBiaxialLayout, isVerticalBiaxialLayout, isRtl, height, labelMap, setLegendHeight, referenceAreaSummary, }: { isHorizontalBiaxialLayout: boolean; isVerticalBiaxialLayout: boolean; isRtl: boolean; height: number; labelMap: | { [key: string]: string; } | null | undefined; setLegendHeight: (arg1: number) => void; referenceAreaSummary: null | ReadonlyArray; }): (arg1: { payload: ReadonlyArray<{ payload: { color: string | null | undefined; dataKey: string; fill: string | null | undefined; name: string; stroke: string | null | undefined; strokeDasharray: string | number | null | undefined; value: number; }; }>; }) => ReactNode { return useCallback( ({ payload }) => { const series = payload.map( ({ payload: payloadData, }: { payload: { color: string | null | undefined; dataKey: string; fill: string | null | undefined; name: string; stroke: string | null | undefined; strokeDasharray: string | number | null | undefined; value: number; }; }) => ( {labelMap?.[payloadData.dataKey] || payloadData.dataKey} ), ); const referenceAreas = referenceAreaSummary?.map(({ label }: ReferenceAreaSummaryItem) => ( {label} )) || []; const legendItemsArray = [...series, ...referenceAreas]; if (isHorizontalBiaxialLayout) { return (
{legendItemsArray.slice(0, 2)}
); } if (isVerticalBiaxialLayout) { return (
{legendItemsArray.slice(0, 2)}
); } return (
{ if (ref) setLegendHeight(ref.getBoundingClientRect().height); }} color="transparent" width="100%" > {legendItemsArray}
); }, [ isHorizontalBiaxialLayout, isVerticalBiaxialLayout, isRtl, height, labelMap, setLegendHeight, referenceAreaSummary, ], ); }