From 0d94292bde920aa8d54bffd86c0036e1b9129a81 Mon Sep 17 00:00:00 2001 From: Hong Seungwoo Date: Thu, 4 Jan 2024 06:15:41 +0900 Subject: [PATCH] feat: Add the dataKey type to legend props (#4035) ## Description ## Related Issue #2909 ## Motivation and Context ## How Has This Been Tested? ## Screenshots (if appropriate): ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] I have added a storybook story or extended an existing story to show my changes - [x] All new and existing tests passed. --- src/component/DefaultLegendContent.tsx | 9 +++++---- src/util/ChartUtils.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/component/DefaultLegendContent.tsx b/src/component/DefaultLegendContent.tsx index 8a5b977f63..4c1bae2326 100644 --- a/src/component/DefaultLegendContent.tsx +++ b/src/component/DefaultLegendContent.tsx @@ -49,6 +49,7 @@ export interface Payload { formatter?: Formatter; inactive?: boolean; legendIcon?: ReactElement; + dataKey?: DataKey; } interface InternalProps { content?: ContentType; @@ -60,12 +61,12 @@ interface InternalProps { payload?: Array; inactiveColor?: string; formatter?: Formatter; - onMouseEnter?: (data: Payload & { dataKey?: DataKey }, index: number, event: MouseEvent) => void; - onMouseLeave?: (data: Payload & { dataKey?: DataKey }, index: number, event: MouseEvent) => void; - onClick?: (data: Payload & { dataKey?: DataKey }, index: number, event: MouseEvent) => void; + onMouseEnter?: (data: Payload, index: number, event: MouseEvent) => void; + onMouseLeave?: (data: Payload, index: number, event: MouseEvent) => void; + onClick?: (data: Payload, index: number, event: MouseEvent) => void; } -export type Props = InternalProps & PresentationAttributesAdaptChildEvent; +export type Props = InternalProps & Omit, keyof InternalProps>; export class DefaultLegendContent extends PureComponent { static displayName = 'Legend'; diff --git a/src/util/ChartUtils.ts b/src/util/ChartUtils.ts index eb9575391b..9ff6ae2494 100644 --- a/src/util/ChartUtils.ts +++ b/src/util/ChartUtils.ts @@ -205,7 +205,7 @@ export interface FormattedGraphicalItem { data?: ReadonlyArray; }; childIndex: number; - item: ReactElement<{ legendType?: LegendType; hide: boolean; name?: string; dataKey: unknown }>; + item: ReactElement<{ legendType?: LegendType; hide: boolean; name?: string; dataKey: DataKey }>; } export type BarSetup = {