-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,7 @@ | ||
import React, { forwardRef } from 'react'; | ||
import Chart from 'chart.js/auto'; | ||
import { defaults } from 'chart.js'; | ||
// @todo Remove these exports | ||
export { default as Chart } from 'chart.js/auto'; | ||
export { defaults } from 'chart.js'; | ||
|
||
import { Props } from './types'; | ||
import ChartComponent from './chart'; | ||
|
||
export const Line = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='line' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Bar = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='bar' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Radar = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='radar' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Doughnut = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='doughnut' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const PolarArea = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='polarArea' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Bubble = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='bubble' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Pie = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='pie' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export const Scatter = forwardRef<Chart | undefined, Omit<Props, 'type'>>( | ||
(props, ref) => ( | ||
<ChartComponent | ||
{...props} | ||
type='scatter' | ||
ref={ref} | ||
options={props.options || {}} | ||
/> | ||
) | ||
); | ||
|
||
export { Chart, defaults }; | ||
|
||
export default ChartComponent; | ||
// @todo Make named export instead of default | ||
export { Chart as default } from './chart'; | ||
export * from './typedCharts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { ChartType } from 'chart.js'; | ||
|
||
import { Props, ChartJSOrUndefined, TypedChartComponent } from './types'; | ||
import { Chart } from './chart'; | ||
|
||
function createTypedChart<T extends ChartType>(type: T) { | ||
return forwardRef<ChartJSOrUndefined<T>, Omit<Props<T>, 'type'>>( | ||
(props, ref) => <Chart {...props} ref={ref} type={type} /> | ||
) as TypedChartComponent<T, true>; | ||
} | ||
|
||
export const Line = createTypedChart('line'); | ||
|
||
export const Bar = createTypedChart('bar'); | ||
|
||
export const Radar = createTypedChart('radar'); | ||
|
||
export const Doughnut = createTypedChart('doughnut'); | ||
|
||
export const PolarArea = createTypedChart('polarArea'); | ||
|
||
export const Bubble = createTypedChart('bubble'); | ||
|
||
export const Pie = createTypedChart('pie'); | ||
|
||
export const Scatter = createTypedChart('scatter'); |
Oops, something went wrong.