Skip to content

Commit 1122188

Browse files
authored
chore(deps): Update components to use new JSX transform (#11582)
* chore(deps): Update components to use new JSX transform * rm import react from react in core * fix tests broken in previous commit * fix doc build errors * fix bad merged file * charts changes * table changes * code editor and fix build * clean up multi import core components * drag and drop changes * react templates changes * react integration and stragglers * change no restricted imports eslint rule to error * clean up some double imports * rebase and review comments * fix docs for merged chartlegend.md example
1 parent eeb1714 commit 1122188

File tree

1,831 files changed

+2732
-4150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,831 files changed

+2732
-4150
lines changed

eslint.config-md.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ export default [
3030
'react/jsx-uses-react': 'error',
3131
'react/jsx-uses-vars': 'error',
3232
'react/no-unknown-property': 'error',
33-
'react/jsx-no-undef': 'error'
33+
'react/jsx-no-undef': 'error',
34+
'no-restricted-imports': [
35+
'error',
36+
{
37+
paths: [
38+
{
39+
name: 'react',
40+
importNames: ['default'],
41+
message: 'Please use named imports when importing from React.'
42+
}
43+
]
44+
}
45+
]
3446
}
3547
}
3648
];

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default [
101101
'no-new-wrappers': 'error',
102102
'no-prototype-builtins': 'off',
103103
'no-restricted-imports': [
104-
'warn',
104+
'error',
105105
{
106106
paths: [
107107
{

packages/react-charts/src/victory/components/Chart/Chart.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from './Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/Chart/Chart.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { Children, cloneElement, isValidElement, useEffect } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33

44
/* eslint-disable camelcase */
@@ -30,7 +30,6 @@ import { getComputedLegend, getLegendItemsExtraHeight, getLegendMaxTextWidth } f
3030
import { getPaddingForSide } from '../ChartUtils/chart-padding';
3131
import { getPatternDefs, mergePatternData, useDefaultPatternProps } from '../ChartUtils/chart-patterns';
3232
import { getChartTheme } from '../ChartUtils/chart-theme-types';
33-
import { useEffect } from 'react';
3433
import { ChartLabel } from '../ChartLabel/ChartLabel';
3534
import { ChartPoint } from '../ChartPoint/ChartPoint';
3635
import { ChartThemeColor } from '../ChartTheme/ChartThemeColor';
@@ -69,7 +68,7 @@ export interface ChartProps extends VictoryChartProps {
6968
* The backgroundComponent prop takes a component instance which will be responsible for rendering a background if the
7069
* Chart's style component includes background styles. The new element created from the passed backgroundComponent
7170
* will be provided with the following properties calculated by Chart: height, polar, scale, style, x, y, width.
72-
* All of these props on Background should take prececence over what VictoryChart is trying to set.
71+
* All of these props on Background should take precedence over what VictoryChart is trying to set.
7372
*/
7473
backgroundComponent?: React.ReactElement<any>;
7574
/**
@@ -152,7 +151,7 @@ export interface ChartProps extends VictoryChartProps {
152151
* events. The eventKey may optionally be used to select a single element by index rather than
153152
* an entire set. The eventHandlers object should be given as an object whose keys are standard
154153
* event names (i.e. onClick) and whose values are event callbacks. The return value
155-
* of an event handler is used to modify elemnts. The return value should be given
154+
* of an event handler is used to modify elements. The return value should be given
156155
* as an object or an array of objects with optional target and eventKey keys,
157156
* and a mutation key whose value is a function. The target and eventKey keys
158157
* will default to those corresponding to the element the event handler was attached to.
@@ -513,15 +512,15 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
513512
containerComponent.props.labelComponent &&
514513
containerComponent.props.labelComponent.type.displayName === 'ChartLegendTooltip'
515514
) {
516-
labelComponent = React.cloneElement(containerComponent.props.labelComponent, {
515+
labelComponent = cloneElement(containerComponent.props.labelComponent, {
517516
theme,
518517
...(defaultPatternScale && { patternScale: defaultPatternScale }),
519518
...containerComponent.props.labelComponent.props
520519
});
521520
}
522521

523522
// Clone so users can override container props
524-
const container = React.cloneElement(containerComponent, {
523+
const container = cloneElement(containerComponent, {
525524
desc: ariaDesc,
526525
title: ariaTitle,
527526
theme,
@@ -536,22 +535,22 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
536535
legendXOffset = getLegendMaxTextWidth(legendData, theme);
537536
}
538537

539-
const legend = React.cloneElement(legendComponent, {
538+
const legend = cloneElement(legendComponent, {
540539
data: legendData,
541540
...(name && { name: `${name}-${(legendComponent as any).type.displayName}` }),
542541
orientation: legendOrientation,
543542
theme,
544543
themeColor,
545544
...(legendDirection === 'rtl' && {
546545
dataComponent: legendComponent.props.dataComponent ? (
547-
React.cloneElement(legendComponent.props.dataComponent, { transform: `translate(${legendXOffset})` })
546+
cloneElement(legendComponent.props.dataComponent, { transform: `translate(${legendXOffset})` })
548547
) : (
549548
<ChartPoint transform={`translate(${legendXOffset})`} />
550549
)
551550
}),
552551
...(legendDirection === 'rtl' && {
553552
labelComponent: legendComponent.props.labelComponent ? (
554-
React.cloneElement(legendComponent.props.labelComponent, { direction: 'rtl', dx: legendXOffset - 30 })
553+
cloneElement(legendComponent.props.labelComponent, { direction: 'rtl', dx: legendXOffset - 30 })
555554
) : (
556555
<ChartLabel direction="rtl" dx={legendXOffset - 30} />
557556
)
@@ -570,7 +569,7 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
570569
let legendTitleHeight = legend.props.title ? 10 : 0;
571570

572571
// Adjust for axis label
573-
React.Children.toArray(children).map((child: any) => {
572+
Children.toArray(children).map((child: any) => {
574573
if (child.type.role === 'axis' && child.props.label && child.props.fixAxisLabelHeight) {
575574
xAxisLabelHeight = getLabelTextSize({ text: child.props.label, theme }).height + 10;
576575
legendTitleHeight = 0;
@@ -608,10 +607,10 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
608607

609608
// Render children
610609
const renderChildren = () =>
611-
React.Children.toArray(children).map((child, index) => {
612-
if (React.isValidElement(child)) {
610+
Children.toArray(children).map((child, index) => {
611+
if (isValidElement(child)) {
613612
const { ...childProps } = child.props;
614-
return React.cloneElement(child, {
613+
return cloneElement(child, {
615614
colorScale,
616615
...(defaultPatternScale && { patternScale: defaultPatternScale }),
617616
...(name &&

packages/react-charts/src/victory/components/ChartArea/ChartArea.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { ChartArea } from '../ChartArea/ChartArea';
43

packages/react-charts/src/victory/components/ChartArea/ChartArea.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -129,7 +129,7 @@ export interface ChartAreaProps extends VictoryAreaProps {
129129
* Since ChartArea only renders a single element, the eventKey property is not used.
130130
* The eventHandlers object should be given as an object whose keys are standard
131131
* event names (i.e. onClick) and whose values are event callbacks. The return value
132-
* of an event handler is used to modify elemnts. The return value should be given
132+
* of an event handler is used to modify elements. The return value should be given
133133
* as an object or an array of objects with optional target and eventKey keys,
134134
* and a mutation key whose value is a function. The target and eventKey keys
135135
* will default to those corresponding to the element the event handler was attached to.
@@ -433,7 +433,7 @@ export const ChartArea: React.FunctionComponent<ChartAreaProps> = ({
433433
...rest
434434
}: ChartAreaProps) => {
435435
// Clone so users can override container props
436-
const container = React.cloneElement(containerComponent, {
436+
const container = cloneElement(containerComponent, {
437437
theme,
438438
...containerComponent.props
439439
});

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ propComponents: [
1111
]
1212
hideDarkMode: true
1313
---
14-
14+
import { createRef } from 'react';
1515
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThreshold, ChartThemeColor, ChartLegendTooltip, ChartVoronoiContainer, createContainer } from '@patternfly/react-charts/victory';
1616
import { getResizeObserver } from '@patternfly/react-core';
1717

@@ -23,7 +23,6 @@ PatternFly React charts are based on the [Victory](https://formidable.com/open-s
2323
## Examples
2424
### Basic with right aligned legend
2525
```js
26-
import React from 'react';
2726
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
2827
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
2928

@@ -88,7 +87,6 @@ import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '
8887
This demonstrates how to combine cursor and voronoi containers to display tooltips along with a cursor.
8988

9089
```js
91-
import React from 'react';
9290
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartLegendTooltip, createContainer } from '@patternfly/react-charts/victory';
9391
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
9492

@@ -172,15 +170,14 @@ class BottomAlignedLegend extends React.Component {
172170

173171
### Multi-color (unordered) bottom-left aligned legend and responsive container
174172
```js
175-
import React from 'react';
176173
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
177174
import { getResizeObserver } from '@patternfly/react-core';
178175
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
179176

180177
class MultiColorChart extends React.Component {
181178
constructor(props) {
182179
super(props);
183-
this.containerRef = React.createRef();
180+
this.containerRef = createRef();
184181
this.observer = () => {};
185182
this.state = {
186183
width: 0

packages/react-charts/src/victory/components/ChartAxis/ChartAxis.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from '../Chart/Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/ChartAxis/ChartAxis.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -117,7 +117,7 @@ export interface ChartAxisProps extends VictoryAxisProps {
117117
* single element by index rather than an entire set. The eventHandlers object
118118
* should be given as an object whose keys are standard event names (i.e. onClick)
119119
* and whose values are event callbacks. The return value of an event handler
120-
* be used to modify other elemnts. The return value should be given as an object or
120+
* be used to modify other elements. The return value should be given as an object or
121121
* an array of objects with optional target and eventKey keys, and a mutation
122122
* key whose value is a function. The target and eventKey keys will default to those
123123
* corresponding to the element the event handler was attached to. The mutation
@@ -458,13 +458,13 @@ export const ChartAxis: React.FunctionComponent<ChartAxisProps> = ({
458458
const componentTheme = getComponentTheme(themeColor);
459459

460460
// Clone so users can override container props
461-
const container = React.cloneElement(containerComponent, {
461+
const container = cloneElement(containerComponent, {
462462
theme,
463463
...containerComponent.props
464464
});
465465

466466
const getAxisLabelComponent = () =>
467-
React.cloneElement(axisLabelComponent, {
467+
cloneElement(axisLabelComponent, {
468468
...(name && {
469469
id: () => `${name}-${(axisLabelComponent as any).type.displayName}`
470470
}),
@@ -473,7 +473,7 @@ export const ChartAxis: React.FunctionComponent<ChartAxisProps> = ({
473473
});
474474

475475
const getTickLabelComponent = () =>
476-
React.cloneElement(tickLabelComponent, {
476+
cloneElement(tickLabelComponent, {
477477
...(name && {
478478
id: (props: any) => `${name}-${(tickLabelComponent as any).type.displayName}-${props.index}`
479479
}),

packages/react-charts/src/victory/components/ChartBar/ChartBar.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from '../Chart/Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/ChartBar/ChartBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -169,7 +169,7 @@ export interface ChartBarProps extends VictoryBarProps {
169169
* The eventKey may optionally be used to select a single element by index rather than an entire
170170
* set. The eventHandlers object should be given as an object whose keys are standard
171171
* event names (i.e. onClick) and whose values are event callbacks. The return value
172-
* of an event handler is used to modify elemnts. The return value should be given
172+
* of an event handler is used to modify elements. The return value should be given
173173
* as an object or an array of objects with optional target and eventKey keys,
174174
* and a mutation key whose value is a function. The target and eventKey keys
175175
* will default to those corresponding to the element the event handler was attached to.
@@ -471,7 +471,7 @@ export const ChartBar: React.FunctionComponent<ChartBarProps> = ({
471471
...rest
472472
}: ChartBarProps) => {
473473
// Clone so users can override container props
474-
const container = React.cloneElement(containerComponent, {
474+
const container = cloneElement(containerComponent, {
475475
theme,
476476
...containerComponent.props
477477
});

packages/react-charts/src/victory/components/ChartBar/examples/ChartBar.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ PatternFly React charts are based on the [Victory](https://formidable.com/open-s
2222
### Basic with right aligned legend
2323

2424
```js
25-
import React from 'react';
2625
import { Chart, ChartAxis, ChartBar, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
2726

2827
<div style={{ height: '250px', width: '600px' }}>
@@ -92,7 +91,6 @@ import { Chart, ChartAxis, ChartBar, ChartGroup, ChartVoronoiContainer } from '@
9291
This demonstrates an alternate way of applying tooltips using data labels.
9392

9493
```js
95-
import React from 'react';
9694
import { Chart, ChartAxis, ChartBar, ChartGroup, ChartThemeColor, ChartTooltip } from '@patternfly/react-charts/victory';
9795

9896
class EmbeddedLegend extends React.Component {
@@ -170,7 +168,6 @@ class EmbeddedLegend extends React.Component {
170168
This demonstrates zoom for both the x and y axis.
171169

172170
```js
173-
import React from 'react';
174171
import { Chart, ChartAxis, ChartBar, ChartGroup, ChartThemeColor } from '@patternfly/react-charts/victory';
175172
import { VictoryZoomContainer } from 'victory-zoom-container';
176173

@@ -236,7 +233,6 @@ import { VictoryZoomContainer } from 'victory-zoom-container';
236233
### Single with right aligned legend
237234

238235
```js
239-
import React from 'react';
240236
import { Chart, ChartBar, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
241237

242238
<div style={{ height: '250px', width: '600px' }}>
@@ -278,7 +274,6 @@ import { Chart, ChartBar, ChartVoronoiContainer } from '@patternfly/react-charts
278274
A gnatt-like chart using `y` and `y0` data properties for alert start/end dates
279275

280276
```js
281-
import React from 'react';
282277
import {
283278
Chart,
284279
ChartAxis,

packages/react-charts/src/victory/components/ChartBoxPlot/ChartBoxPlot.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from '../Chart/Chart';
43
import { ChartBoxPlot } from './ChartBoxPlot';

packages/react-charts/src/victory/components/ChartBoxPlot/ChartBoxPlot.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -157,7 +157,7 @@ export interface ChartBoxPlotProps extends VictoryBoxPlotProps {
157157
* The eventKey may optionally be used to select a single element by index rather than an entire
158158
* set. The eventHandlers object should be given as an object whose keys are standard
159159
* event names (i.e. onClick) and whose values are event callbacks. The return value
160-
* of an event handler is used to modify elemnts. The return value should be given
160+
* of an event handler is used to modify elements. The return value should be given
161161
* as an object or an array of objects with optional target and eventKey keys,
162162
* and a mutation key whose value is a function. The target and eventKey keys
163163
* will default to those corresponding to the element the event handler was attached to.
@@ -685,7 +685,7 @@ export const ChartBoxPlot: React.FunctionComponent<ChartBoxPlotProps> = ({
685685
...rest
686686
}: ChartBoxPlotProps) => {
687687
// Clone so users can override container props
688-
const container = React.cloneElement(containerComponent, {
688+
const container = cloneElement(containerComponent, {
689689
theme,
690690
...containerComponent.props
691691
});

packages/react-charts/src/victory/components/ChartBoxPlot/examples/ChartBoxPlot.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ PatternFly React charts are based on the [Victory](https://formidable.com/open-s
2525
## Examples
2626
### Basic with right aligned legend
2727
```js
28-
import React from 'react';
2928
import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/react-charts/victory';
3029

3130
<div style={{ height: '300px', width: '750px' }}>
@@ -67,7 +66,6 @@ import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/rea
6766
This demonstrates how to display labels.
6867

6968
```js
70-
import React from 'react';
7169
import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/react-charts/victory';
7270

7371
<div style={{ height: '300px', width: '600px' }}>
@@ -114,7 +112,6 @@ import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/rea
114112
This demonstrates how to embed a legend within a tooltip. Combining cursor and voronoi containers is required to display tooltips with a vertical cursor.
115113

116114
```js
117-
import React from 'react';
118115
import { Chart, ChartAxis, ChartBoxPlot, ChartLegendTooltip, ChartThemeColor, ChartThreshold, createContainer } from '@patternfly/react-charts/victory';
119116
import chart_color_orange_300 from '@patternfly/react-tokens/dist/esm/chart_color_orange_300';
120117

@@ -216,7 +213,6 @@ class EmbeddedLegend extends React.Component {
216213
This demonstrates how to embed HTML within a tooltip. Combining cursor and voronoi containers is required to display tooltips with a vertical cursor.
217214

218215
```js
219-
import React from 'react';
220216
import { Chart, ChartAxis, ChartBoxPlot, ChartCursorTooltip, ChartThemeColor, createContainer } from '@patternfly/react-charts/victory';
221217

222218
class EmbeddedHtml extends React.Component {

packages/react-charts/src/victory/components/ChartBullet/ChartBullet.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { ChartAxis } from '../ChartAxis/ChartAxis';
43
import { ChartLabel } from '../ChartLabel/ChartLabel';

0 commit comments

Comments
 (0)