Skip to content

Commit

Permalink
fix: Chart component children type (#2071)
Browse files Browse the repository at this point in the history
`react@18` no longer has implicit `children` for the `Component` props.
  • Loading branch information
nickofthyme authored Jun 20, 2023
1 parent 5212833 commit 525c782
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
20 changes: 18 additions & 2 deletions packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ export interface Cell {
yIndex: number;
}

// Warning: (ae-forgotten-export) The symbol "ChartProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ChartState" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand All @@ -493,7 +492,7 @@ export class Chart extends React_2.Component<ChartProps, ChartState> {
// (undocumented)
componentWillUnmount(): void;
// (undocumented)
static defaultProps: ChartProps;
static defaultProps: Pick<ChartProps, OptionalKeys<ChartProps>>;
// (undocumented)
dispatchExternalPointerEvent(event: PointerEvent_2): void;
// (undocumented)
Expand All @@ -509,6 +508,23 @@ export class Chart extends React_2.Component<ChartProps, ChartState> {
render(): JSX.Element;
}

// @public (undocumented)
export interface ChartProps {
// (undocumented)
children?: ReactNode;
// (undocumented)
className?: string;
// (undocumented)
description?: string;
// (undocumented)
id?: string;
renderer?: 'svg' | 'canvas';
// (undocumented)
size?: ChartSize;
// (undocumented)
title?: string;
}

// @public (undocumented)
export type ChartSize = number | string | ChartSizeArray | ChartSizeObject;

Expand Down
4 changes: 4 additions & 0 deletions packages/charts/src/chart_types/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export {

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

export * from './wordcloud/specs';

export * from './goal_chart/specs';

export { Partition } from './partition_chart/specs';

export { Heatmap, HeatmapSpec, RasterTimeScale, TimeScale, LinearScale, OrdinalScale } from './heatmap/specs';
Expand Down
9 changes: 6 additions & 3 deletions packages/charts/src/components/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import classNames from 'classnames';
import React, { CSSProperties, createRef } from 'react';
import React, { CSSProperties, ReactNode, createRef } from 'react';
import { Provider } from 'react-redux';
import { createStore, Store, Unsubscribe, StoreEnhancer, applyMiddleware, Middleware } from 'redux';
import { OptionalKeys } from 'utility-types';
import { v4 as uuidv4 } from 'uuid';

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

interface ChartProps {
/** @public */
export interface ChartProps {
/**
* The type of rendered
* @defaultValue `canvas`
Expand All @@ -44,6 +46,7 @@ interface ChartProps {
id?: string;
title?: string;
description?: string;
children?: ReactNode;
}

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

/** @public */
export class Chart extends React.Component<ChartProps, ChartState> {
static defaultProps: ChartProps = {
static defaultProps: Pick<ChartProps, OptionalKeys<ChartProps>> = {
renderer: 'canvas',
};

Expand Down
2 changes: 1 addition & 1 deletion packages/charts/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Side Public License, v 1.
*/

export { Chart } from './chart';
export * from './chart';
export { Placement, TooltipPortalSettings } from './portal';
2 changes: 0 additions & 2 deletions packages/charts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export { CategoryKey, CategoryLabel } from './common/category';
export { Layer as PartitionLayer, PartitionProps } from './chart_types/partition_chart/specs/index';
export { FillLabelConfig as PartitionFillLabel, PartitionStyle } from './utils/themes/partition';
export { PartitionLayout } from './chart_types/partition_chart/layout/types/config_types';
export * from './chart_types/goal_chart/specs/index';
export * from './chart_types/wordcloud/specs/index';

export {
Accessor,
Expand Down
10 changes: 4 additions & 6 deletions storybook/stories/annotations/rects/4_styling.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

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

import {
AnnotationAnimationConfig,
AnnotationDomainType,
Axis,
Chart,
ChartProps,
LineAnnotation,
LineAnnotationDatum,
RectAnnotation,
Expand All @@ -33,11 +34,8 @@ import { customKnobs } from '../../utils/knobs';

const rng = getRandomNumberGenerator();
const randomArray = new Array(100).fill(0).map(() => rng(0, 10, 2));
const ExampleChart = memo(
({
animationOptions,
...chartProps
}: { animationOptions: AnnotationAnimationConfig['options'] } & ComponentProps<typeof Chart>) => {
const ExampleChart = memo<{ animationOptions: AnnotationAnimationConfig['options'] } & ChartProps>(
({ animationOptions, ...chartProps }) => {
const debug = boolean('debug', false);
const [SeriesType] = customKnobs.enum.xySeries(undefined, 'line');
const xScaleType = customKnobs.enum.scaleType('Scale type', ScaleType.Linear, { include: ['Linear', 'Ordinal'] });
Expand Down

0 comments on commit 525c782

Please sign in to comment.