-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(canvas): add custom ref to ScatterPlotCanvas and NetworkCanvas (#…
…1953) * Add forwardRef to ScatterPlotCanvas * Add story * Adding support for NetworkCanvas * Aligned function names * Formatting * Type fixes
- Loading branch information
1 parent
45c31e9
commit b021074
Showing
6 changed files
with
171 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import { ResponsiveWrapper } from '@nivo/core' | ||
import { ForwardedRef, forwardRef } from 'react' | ||
import { NetworkCanvasProps, InputNode, InputLink } from './types' | ||
import { NetworkCanvas } from './NetworkCanvas' | ||
|
||
export const ResponsiveNetworkCanvas = < | ||
export const ResponsiveNetworkCanvas = forwardRef(function ResponsiveBarCanvas< | ||
Node extends InputNode = InputNode, | ||
Link extends InputLink = InputLink | ||
>( | ||
props: Omit<NetworkCanvasProps<Node, Link>, 'height' | 'width'> | ||
) => ( | ||
<ResponsiveWrapper> | ||
{({ width, height }) => ( | ||
<NetworkCanvas<Node, Link> width={width} height={height} {...props} /> | ||
)} | ||
</ResponsiveWrapper> | ||
) | ||
props: Omit<NetworkCanvasProps<Node, Link>, 'height' | 'width'>, | ||
ref: ForwardedRef<HTMLCanvasElement> | ||
) { | ||
return ( | ||
<ResponsiveWrapper> | ||
{({ width, height }) => ( | ||
<NetworkCanvas | ||
width={width} | ||
height={height} | ||
{...(props as Omit< | ||
NetworkCanvasProps<InputNode, InputLink>, | ||
'height' | 'width' | ||
>)} | ||
ref={ref} | ||
/> | ||
)} | ||
</ResponsiveWrapper> | ||
) | ||
}) |
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,13 +1,28 @@ | ||
import { ResponsiveWrapper } from '@nivo/core' | ||
import { ForwardedRef, forwardRef } from 'react' | ||
|
||
import { ScatterPlotCanvas } from './ScatterPlotCanvas' | ||
import { ScatterPlotCanvasProps, ScatterPlotDatum } from './types' | ||
|
||
export const ResponsiveScatterPlotCanvas = <RawDatum extends ScatterPlotDatum>( | ||
props: Omit<ScatterPlotCanvasProps<RawDatum>, 'width' | 'height'> | ||
) => ( | ||
<ResponsiveWrapper> | ||
{({ width, height }) => ( | ||
<ScatterPlotCanvas<RawDatum> width={width} height={height} {...props} /> | ||
)} | ||
</ResponsiveWrapper> | ||
) | ||
export const ResponsiveScatterPlotCanvas = forwardRef(function ResponsiveScatterPlotCanvas< | ||
RawDatum extends ScatterPlotDatum | ||
>( | ||
props: Omit<ScatterPlotCanvasProps<RawDatum>, 'width' | 'height'>, | ||
ref: ForwardedRef<HTMLCanvasElement> | ||
) { | ||
return ( | ||
<ResponsiveWrapper> | ||
{({ width, height }) => ( | ||
<ScatterPlotCanvas | ||
width={width} | ||
height={height} | ||
{...(props as Omit< | ||
ScatterPlotCanvasProps<ScatterPlotDatum>, | ||
'height' | 'width' | ||
>)} | ||
ref={ref} | ||
/> | ||
)} | ||
</ResponsiveWrapper> | ||
) | ||
}) |
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