Skip to content

Commit 9b9a7ba

Browse files
authored
fix(charts): defaultProps deprecation warning (#11019) (#11028)
1 parent 3c2e622 commit 9b9a7ba

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

packages/react-charts/src/components/ChartArea/examples/ChartArea.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class BottomAlignedLegend extends React.Component {
127127
themeColor={ChartThemeColor.cyan}
128128
width={650}
129129
>
130-
<ChartAxis label="Years"/>
130+
<ChartAxis label="Years" fixAxisLabelHeight />
131131
<ChartAxis dependentAxis showGrid/>
132132
<ChartGroup>
133133
<ChartArea

packages/react-charts/src/components/ChartCursorContainer/ChartCursorContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ export const ChartCursorContainer: React.FunctionComponent<ChartCursorContainerP
239239
);
240240
};
241241
ChartCursorContainer.displayName = 'ChartCursorContainer';
242-
ChartCursorContainer.defaultProps = (VictoryCursorContainer as any).defaultProps;
243242

244243
// Note: VictoryCursorContainer.defaultEvents & VictoryContainer.role must be hoisted
245244
hoistNonReactStatics(ChartCursorContainer, VictoryCursorContainer);

packages/react-charts/src/components/ChartCursorTooltip/ChartCursorFlyout.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ interface ChartCursorFlyoutProps extends VictoryCommonPrimitiveProps {
111111
}
112112

113113
const ChartCursorFlyout = (props: ChartCursorFlyoutProps) => {
114-
props = evaluateProps(props);
114+
props = evaluateProps({
115+
pathComponent: <Path />,
116+
role: 'presentation',
117+
shapeRendering: 'auto',
118+
...props
119+
});
115120

116121
return React.cloneElement(props.pathComponent, {
117122
...props.events,
@@ -125,10 +130,4 @@ const ChartCursorFlyout = (props: ChartCursorFlyoutProps) => {
125130
});
126131
};
127132

128-
ChartCursorFlyout.defaultProps = {
129-
pathComponent: <Path />,
130-
role: 'presentation',
131-
shapeRendering: 'auto'
132-
};
133-
134133
export { ChartCursorFlyout };

packages/react-charts/src/components/ChartUtils/chart-container.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,30 @@ import { LineSegment } from 'victory-core';
2626
* @public
2727
*/
2828
export const createContainer = (behaviorA: ContainerType, behaviorB: ContainerType) => {
29-
const container: any = victoryCreateContainer(behaviorA, behaviorB);
29+
const Container: any = victoryCreateContainer(behaviorA, behaviorB);
3030
const isCursor = behaviorA === 'cursor' || behaviorB === 'cursor';
3131
const isVoronoi = behaviorA === 'voronoi' || behaviorB === 'voronoi';
3232

33-
if (!container?.defaultProps) {
34-
container.defaultProps = {};
35-
}
36-
if (isCursor) {
37-
container.defaultProps.cursorLabelComponent = <ChartLabel textAnchor="start" />;
38-
container.defaultProps.cursorComponent = (
39-
<LineSegment
40-
style={{
41-
stroke: chart_container_cursor_line_Fill.var
42-
}}
43-
/>
44-
);
45-
}
46-
if (isVoronoi) {
47-
container.defaultProps.labelComponent = <ChartCursorTooltip />;
48-
}
49-
return container;
33+
const containerWrapper = (props: any) => {
34+
const containerProps = {
35+
...(isCursor && {
36+
cursorLabelComponent: <ChartLabel textAnchor="start" />,
37+
cursorComponent: (
38+
<LineSegment
39+
style={{
40+
stroke: chart_container_cursor_line_Fill.var
41+
}}
42+
/>
43+
)
44+
}),
45+
...(isVoronoi && { labelComponent: <ChartCursorTooltip /> }),
46+
...props
47+
};
48+
return <Container {...containerProps} />;
49+
};
50+
containerWrapper.defaultEvents = Container.defaultEvents;
51+
containerWrapper.displayName = Container.displayName;
52+
containerWrapper.role = Container.role;
53+
54+
return containerWrapper;
5055
};

packages/react-charts/src/components/ChartUtils/chart-tooltip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const getCursorTooltipPoniterOrientation = ({
9292
* Returns props associated with legend data
9393
* @private
9494
*/
95-
export const getLegendTooltipDataProps = (defaultProps: ChartLegendProps) =>
95+
export const getLegendTooltipDataProps = (props: ChartLegendProps) =>
9696
merge(
9797
{
9898
borderPadding: 0,
@@ -112,7 +112,7 @@ export const getLegendTooltipDataProps = (defaultProps: ChartLegendProps) =>
112112
}
113113
}
114114
},
115-
{ ...defaultProps }
115+
{ ...props }
116116
);
117117

118118
/**

packages/react-charts/src/components/ChartVoronoiContainer/ChartVoronoiContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ export const ChartVoronoiContainer: React.FunctionComponent<ChartVoronoiContaine
249249
);
250250
};
251251
ChartVoronoiContainer.displayName = 'ChartVoronoiContainer';
252-
ChartVoronoiContainer.defaultProps = (VictoryVoronoiContainer as any).defaultProps;
253252

254253
// Note: VictoryVoronoiContainer.defaultEvents & VictoryContainer.role must be hoisted
255254
hoistNonReactStatics(ChartVoronoiContainer, VictoryVoronoiContainer);

0 commit comments

Comments
 (0)