diff --git a/src/components/text-elements/Legend/Legend.tsx b/src/components/text-elements/Legend/Legend.tsx
index 1b933669b..121f3b534 100644
--- a/src/components/text-elements/Legend/Legend.tsx
+++ b/src/components/text-elements/Legend/Legend.tsx
@@ -6,15 +6,53 @@ import { ChevronLeftFill, ChevronRightFill } from "assets";
const makeLegendClassName = makeClassName("Legend");
+export interface ColorCircleProps {
+ name: string;
+ color: string;
+ activeLegend?: string;
+}
+
+const ColorCircle = ({ name, color, activeLegend }: ColorCircleProps) => {
+ return (
+
+ );
+};
+
export interface LegendItemProps {
name: string;
color: Color | string;
onClick?: (name: string, color: Color | string) => void;
activeLegend?: string;
+ index: number;
+ customRender:
+ | ((params: {
+ name: string;
+ index: number;
+ Circle: () => React.JSX.Element;
+ }) => React.ReactNode | undefined)
+ | undefined;
}
-const LegendItem = ({ name, color, onClick, activeLegend }: LegendItemProps) => {
+const LegendItem = ({
+ name,
+ color,
+ onClick,
+ activeLegend,
+ customRender,
+ index,
+}: LegendItemProps) => {
const hasOnValueChange = !!onClick;
+
return (
onClick?.(name, color);
}}
>
-
-
- {name}
-
+ {customRender ? (
+ customRender({
+ name,
+ index,
+ Circle: () => ,
+ })
+ ) : (
+ <>
+
+
+ {name}
+
+ >
+ )}
);
};
@@ -135,6 +173,11 @@ export interface LegendProps extends React.OlHTMLAttributes {
onClickLegendItem?: (category: string, color: Color | string) => void;
activeLegend?: string;
enableLegendSlider?: boolean;
+ renderItem?: (params: {
+ name: string;
+ index: number;
+ Circle: () => React.JSX.Element;
+ }) => React.ReactNode | undefined;
}
type HasScrollProps = {
@@ -150,6 +193,7 @@ const Legend = React.forwardRef((props, ref) => {
onClickLegendItem,
activeLegend,
enableLegendSlider = false,
+ renderItem = undefined,
...other
} = props;
const scrollableRef = React.useRef(null);
@@ -259,6 +303,8 @@ const Legend = React.forwardRef((props, ref) => {
color={colors[idx]}
onClick={onClickLegendItem}
activeLegend={activeLegend}
+ customRender={renderItem}
+ index={idx}
/>
))}
diff --git a/src/stories/text-elements/Legend.stories.tsx b/src/stories/text-elements/Legend.stories.tsx
index aa87324c5..789fc6a92 100644
--- a/src/stories/text-elements/Legend.stories.tsx
+++ b/src/stories/text-elements/Legend.stories.tsx
@@ -101,3 +101,20 @@ export const CustomColorsConClick: Story = {
},
},
};
+
+export const CustomItem: Story = {
+ ...LegendTemplate,
+ args: {
+ categories: ["Category A", "Category B", "Category C"],
+ renderItem: ({ name, index, Circle }) => {
+ return (
+ <>
+
+
+ {index} - {name}
+
+ >
+ );
+ },
+ },
+};