Skip to content

Commit 82ab334

Browse files
authored
feat: export chart props types (#810)
#720
1 parent 6fc5e98 commit 82ab334

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ See [these examples](example) for more information
5555
getElementsAtEvent?: (elements: Chart.InteractionItem[], event: React.MouseEvent<HTMLCanvasElement>) => void;
5656
```
5757

58+
In TypeScript, you can import chart props types like this:
59+
60+
```ts
61+
import type { ChartProps } from 'react-chartjs-2';
62+
```
63+
5864
#### id
5965

6066
Type `string`

src/chart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ForwardedRef, MouseEvent } from 'react';
33
import ChartJS from 'chart.js/auto';
44
import type { ChartData, ChartType, DefaultDataPoint } from 'chart.js';
55

6-
import type { Props, TypedChartComponent } from './types';
6+
import type { ChartProps, TypedChartComponent } from './types';
77
import {
88
reforwardRef,
99
cloneData,
@@ -35,7 +35,7 @@ function ChartComponent<
3535
fallbackContent,
3636
onClick: onClickProp,
3737
...props
38-
}: Props<TType, TData, TLabel>,
38+
}: ChartProps<TType, TData, TLabel>,
3939
ref: ForwardedRef<ChartJS<TType, TData, TLabel>>
4040
) {
4141
type TypedChartJS = ChartJS<TType, TData, TLabel>;

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export { defaults } from 'chart.js';
44

55
// @todo Make named export instead of default
66
export { Chart as default } from './chart';
7+
export type { ChartProps } from './types';
78
export * from './typedCharts';

src/typedCharts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react';
22
import { ChartType } from 'chart.js';
33

4-
import { Props, ChartJSOrUndefined, TypedChartComponent } from './types';
4+
import { ChartProps, ChartJSOrUndefined, TypedChartComponent } from './types';
55
import { Chart } from './chart';
66

77
function createTypedChart<T extends ChartType>(type: T) {
8-
return forwardRef<ChartJSOrUndefined<T>, Omit<Props<T>, 'type'>>(
8+
return forwardRef<ChartJSOrUndefined<T>, Omit<ChartProps<T>, 'type'>>(
99
(props, ref) => <Chart {...props} ref={ref} type={type} />
1010
) as TypedChartComponent<T, true>;
1111
}

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
InteractionItem,
1515
} from 'chart.js';
1616

17-
export interface Props<
17+
export interface ChartProps<
1818
TType extends ChartType = ChartType,
1919
TData = DefaultDataPoint<TType>,
2020
TLabel = unknown
@@ -61,7 +61,7 @@ export type TypedChartComponent<
6161
TOmitType = false
6262
> = TOmitType extends true
6363
? <TData = DefaultDataPoint<TDefaultType>, TLabel = unknown>(
64-
props: Omit<Props<TDefaultType, TData, TLabel>, 'type'> & {
64+
props: Omit<ChartProps<TDefaultType, TData, TLabel>, 'type'> & {
6565
ref?: ForwardedRef<ChartJSOrUndefined<TDefaultType, TData, TLabel>>;
6666
}
6767
) => JSX.Element
@@ -70,7 +70,7 @@ export type TypedChartComponent<
7070
TData = DefaultDataPoint<TType>,
7171
TLabel = unknown
7272
>(
73-
props: Props<TType, TData, TLabel> & {
73+
props: ChartProps<TType, TData, TLabel> & {
7474
ref?: ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>>;
7575
}
7676
) => JSX.Element;

0 commit comments

Comments
 (0)