Skip to content

Commit 525c782

Browse files
authored
fix: Chart component children type (#2071)
`react@18` no longer has implicit `children` for the `Component` props.
1 parent 5212833 commit 525c782

6 files changed

Lines changed: 33 additions & 14 deletions

File tree

packages/charts/api/charts.api.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ export interface Cell {
480480
yIndex: number;
481481
}
482482

483-
// Warning: (ae-forgotten-export) The symbol "ChartProps" needs to be exported by the entry point index.d.ts
484483
// Warning: (ae-forgotten-export) The symbol "ChartState" needs to be exported by the entry point index.d.ts
485484
//
486485
// @public (undocumented)
@@ -493,7 +492,7 @@ export class Chart extends React_2.Component<ChartProps, ChartState> {
493492
// (undocumented)
494493
componentWillUnmount(): void;
495494
// (undocumented)
496-
static defaultProps: ChartProps;
495+
static defaultProps: Pick<ChartProps, OptionalKeys<ChartProps>>;
497496
// (undocumented)
498497
dispatchExternalPointerEvent(event: PointerEvent_2): void;
499498
// (undocumented)
@@ -509,6 +508,23 @@ export class Chart extends React_2.Component<ChartProps, ChartState> {
509508
render(): JSX.Element;
510509
}
511510

511+
// @public (undocumented)
512+
export interface ChartProps {
513+
// (undocumented)
514+
children?: ReactNode;
515+
// (undocumented)
516+
className?: string;
517+
// (undocumented)
518+
description?: string;
519+
// (undocumented)
520+
id?: string;
521+
renderer?: 'svg' | 'canvas';
522+
// (undocumented)
523+
size?: ChartSize;
524+
// (undocumented)
525+
title?: string;
526+
}
527+
512528
// @public (undocumented)
513529
export type ChartSize = number | string | ChartSizeArray | ChartSizeObject;
514530

packages/charts/src/chart_types/specs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export {
2727

2828
export * from './xy_chart/utils/specs';
2929

30+
export * from './wordcloud/specs';
31+
32+
export * from './goal_chart/specs';
33+
3034
export { Partition } from './partition_chart/specs';
3135

3236
export { Heatmap, HeatmapSpec, RasterTimeScale, TimeScale, LinearScale, OrdinalScale } from './heatmap/specs';

packages/charts/src/components/chart.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

99
import classNames from 'classnames';
10-
import React, { CSSProperties, createRef } from 'react';
10+
import React, { CSSProperties, ReactNode, createRef } from 'react';
1111
import { Provider } from 'react-redux';
1212
import { createStore, Store, Unsubscribe, StoreEnhancer, applyMiddleware, Middleware } from 'redux';
13+
import { OptionalKeys } from 'utility-types';
1314
import { v4 as uuidv4 } from 'uuid';
1415

1516
import { ChartBackground } from './chart_background';
@@ -33,7 +34,8 @@ import { ChartSize, getChartSize } from '../utils/chart_size';
3334
import { LayoutDirection } from '../utils/common';
3435
import { LIGHT_THEME } from '../utils/themes/light_theme';
3536

36-
interface ChartProps {
37+
/** @public */
38+
export interface ChartProps {
3739
/**
3840
* The type of rendered
3941
* @defaultValue `canvas`
@@ -44,6 +46,7 @@ interface ChartProps {
4446
id?: string;
4547
title?: string;
4648
description?: string;
49+
children?: ReactNode;
4750
}
4851

4952
interface ChartState {
@@ -70,7 +73,7 @@ const getMiddlware = (id: string): StoreEnhancer => {
7073

7174
/** @public */
7275
export class Chart extends React.Component<ChartProps, ChartState> {
73-
static defaultProps: ChartProps = {
76+
static defaultProps: Pick<ChartProps, OptionalKeys<ChartProps>> = {
7477
renderer: 'canvas',
7578
};
7679

packages/charts/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* Side Public License, v 1.
77
*/
88

9-
export { Chart } from './chart';
9+
export * from './chart';
1010
export { Placement, TooltipPortalSettings } from './portal';

packages/charts/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export { CategoryKey, CategoryLabel } from './common/category';
4848
export { Layer as PartitionLayer, PartitionProps } from './chart_types/partition_chart/specs/index';
4949
export { FillLabelConfig as PartitionFillLabel, PartitionStyle } from './utils/themes/partition';
5050
export { PartitionLayout } from './chart_types/partition_chart/layout/types/config_types';
51-
export * from './chart_types/goal_chart/specs/index';
52-
export * from './chart_types/wordcloud/specs/index';
5351

5452
export {
5553
Accessor,

storybook/stories/annotations/rects/4_styling.story.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
import { action } from '@storybook/addon-actions';
1010
import { array, boolean, color, number } from '@storybook/addon-knobs';
11-
import React, { memo, useEffect, useMemo, useState, ComponentProps } from 'react';
11+
import React, { memo, useEffect, useMemo, useState } from 'react';
1212

1313
import {
1414
AnnotationAnimationConfig,
1515
AnnotationDomainType,
1616
Axis,
1717
Chart,
18+
ChartProps,
1819
LineAnnotation,
1920
LineAnnotationDatum,
2021
RectAnnotation,
@@ -33,11 +34,8 @@ import { customKnobs } from '../../utils/knobs';
3334

3435
const rng = getRandomNumberGenerator();
3536
const randomArray = new Array(100).fill(0).map(() => rng(0, 10, 2));
36-
const ExampleChart = memo(
37-
({
38-
animationOptions,
39-
...chartProps
40-
}: { animationOptions: AnnotationAnimationConfig['options'] } & ComponentProps<typeof Chart>) => {
37+
const ExampleChart = memo<{ animationOptions: AnnotationAnimationConfig['options'] } & ChartProps>(
38+
({ animationOptions, ...chartProps }) => {
4139
const debug = boolean('debug', false);
4240
const [SeriesType] = customKnobs.enum.xySeries(undefined, 'line');
4341
const xScaleType = customKnobs.enum.scaleType('Scale type', ScaleType.Linear, { include: ['Linear', 'Ordinal'] });

0 commit comments

Comments
 (0)