Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/chart.tsx → src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DefaultDataPoint
} from 'chart.js'
import {
createElement,
useEffect,
useRef,
forwardRef
Expand Down Expand Up @@ -117,16 +118,18 @@ function ChartComponent<
return () => destroyChart()
}, [])

return (
<canvas
ref={canvasRef}
role='img'
height={height}
width={width}
{...canvasProps}
>
{fallbackContent}
</canvas>
// createElement instead of JSX: strict ES module resolution, as in Node.js and webpack 5,
// cannot find `react/jsx-runtime` in React 16 and 17, which have no `exports` field (#1319)
return createElement(
'canvas',
{
ref: canvasRef,
role: 'img',
height,
width,
...canvasProps
},
fallbackContent
)
}

Expand Down
17 changes: 9 additions & 8 deletions src/typedCharts.tsx → src/typedCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type {
ChartType,
ChartComponentLike
} from 'chart.js'
import { forwardRef } from 'react'
import {
createElement,
forwardRef
} from 'react'
import {
Chart as ChartJS,
LineController,
Expand All @@ -28,13 +31,11 @@ function createTypedChart<T extends ChartType>(
ChartJS.register(registerables)

return /* @__PURE__ */ forwardRef<ChartJSOrUndefined<T>, Omit<ChartProps<T>, 'type'>>(
(props, ref) => (
<Chart
{...props}
ref={ref}
type={type}
/>
)
(props, ref) => createElement(Chart<T>, {
...props,
ref,
type
})
) as TypedChartComponent<T>
}

Expand Down
4 changes: 2 additions & 2 deletions website/src/components/PropsTable.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function getDocs() {
// Standard <canvas> props are mentioned once on the page instead of being listed
propFilter: prop => !prop.parent || !prop.parent.fileName.includes('node_modules')
}).parse([
resolve(root, 'src/chart.tsx'),
resolve(root, 'src/typedCharts.tsx')
resolve(root, 'src/chart.ts'),
resolve(root, 'src/typedCharts.ts')
])

return docs
Expand Down