Skip to content

Commit e07661c

Browse files
fix(chart): support recharts 3
- use permissive payload/label props for Tooltip (recharts 3 omits PropertiesReadFromContext from TooltipProps) - fix Legend payload/verticalAlign Pick (LegendProps no longer exposes payload) - add explicit any for payload items to satisfy noImplicitAny (eslint disabled for this file due to recharts 3 any payload) Closes #43 Validated: pnpm type-check, 16 tests, pnpm audit clean
1 parent e387592 commit e07661c

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/components/ui/chart.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
'use client';
23

34
import * as React from 'react';
@@ -93,13 +94,20 @@ const ChartTooltip = RechartsPrimitive.Tooltip;
9394

9495
const ChartTooltipContent = React.forwardRef<
9596
HTMLDivElement,
96-
React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
97+
Omit<React.ComponentProps<typeof RechartsPrimitive.Tooltip>, 'content'> &
9798
React.ComponentProps<'div'> & {
9899
hideLabel?: boolean;
99100
hideIndicator?: boolean;
100101
indicator?: 'line' | 'dot' | 'dashed';
101102
nameKey?: string;
102103
labelKey?: string;
104+
payload?: any;
105+
label?: any;
106+
active?: boolean;
107+
labelFormatter?: any;
108+
formatter?: any;
109+
color?: string;
110+
labelClassName?: string;
103111
}
104112
>(
105113
(
@@ -162,7 +170,7 @@ const ChartTooltipContent = React.forwardRef<
162170
>
163171
{!nestLabel ? tooltipLabel : null}
164172
<div className="grid gap-1.5">
165-
{payload.map((item, index) => {
173+
{payload.map((item: any, index: number) => {
166174
const key = `${nameKey || item.name || item.dataKey || 'value'}`;
167175
const itemConfig = getPayloadConfigFromPayload(config, item, key);
168176
const indicatorColor = color || item.payload.fill || item.color;
@@ -231,11 +239,12 @@ const ChartLegend = RechartsPrimitive.Legend;
231239

232240
const ChartLegendContent = React.forwardRef<
233241
HTMLDivElement,
234-
React.ComponentProps<'div'> &
235-
Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
236-
hideIcon?: boolean;
237-
nameKey?: string;
238-
}
242+
React.ComponentProps<'div'> & {
243+
payload?: any[];
244+
verticalAlign?: 'top' | 'bottom' | 'middle';
245+
hideIcon?: boolean;
246+
nameKey?: string;
247+
}
239248
>(({ className, hideIcon = false, payload, verticalAlign = 'bottom', nameKey }, ref) => {
240249
const { config } = useChart();
241250

@@ -248,7 +257,7 @@ const ChartLegendContent = React.forwardRef<
248257
ref={ref}
249258
className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}
250259
>
251-
{payload.map((item) => {
260+
{payload.map((item: any) => {
252261
const key = `${nameKey || item.dataKey || 'value'}`;
253262
const itemConfig = getPayloadConfigFromPayload(config, item, key);
254263

0 commit comments

Comments
 (0)