1- import { createElement , Fragment , ReactNode } from 'react'
1+ import { createElement , Fragment , ReactNode , Ref , forwardRef } from 'react'
22import { Container , SvgWrapper , useDimensions } from '@nivo/core'
33import { BoxLegendSvg } from '@nivo/legends'
44import { svgDefaultProps } from './defaults'
@@ -8,46 +8,43 @@ import { ChordArcs } from './ChordArcs'
88import { ChordLabels } from './ChordLabels'
99import { ChordSvgProps , LayerId } from './types'
1010
11- type InnerChordProps = Omit < ChordSvgProps , 'animate' | 'motionConfig' | 'renderWrapper' | 'theme' >
11+ type InnerChordProps = Omit <
12+ ChordSvgProps ,
13+ 'animate' | 'motionConfig' | 'renderWrapper' | 'theme'
14+ > & {
15+ forwardedRef : Ref < SVGSVGElement >
16+ }
1217
1318const InnerChord = ( {
1419 data,
1520 keys,
1621 label,
1722 valueFormat,
18-
1923 margin : partialMargin ,
2024 width,
2125 height,
22-
2326 innerRadiusRatio = svgDefaultProps . innerRadiusRatio ,
2427 innerRadiusOffset = svgDefaultProps . innerRadiusOffset ,
2528 padAngle = svgDefaultProps . padAngle ,
26-
2729 layers = svgDefaultProps . layers ,
28-
2930 colors = svgDefaultProps . colors ,
30-
3131 arcBorderWidth = svgDefaultProps . arcBorderWidth ,
3232 arcBorderColor = svgDefaultProps . arcBorderColor ,
3333 arcOpacity = svgDefaultProps . arcOpacity ,
3434 activeArcOpacity = svgDefaultProps . activeArcOpacity ,
3535 inactiveArcOpacity = svgDefaultProps . inactiveArcOpacity ,
3636 arcTooltip = svgDefaultProps . arcTooltip ,
37-
3837 ribbonBorderWidth = svgDefaultProps . ribbonBorderWidth ,
3938 ribbonBorderColor = svgDefaultProps . ribbonBorderColor ,
4039 ribbonBlendMode = svgDefaultProps . ribbonBlendMode ,
4140 ribbonOpacity = svgDefaultProps . ribbonOpacity ,
4241 activeRibbonOpacity = svgDefaultProps . activeRibbonOpacity ,
4342 inactiveRibbonOpacity = svgDefaultProps . inactiveRibbonOpacity ,
4443 ribbonTooltip = svgDefaultProps . ribbonTooltip ,
45-
4644 enableLabel = svgDefaultProps . enableLabel ,
4745 labelOffset = svgDefaultProps . labelOffset ,
4846 labelRotation = svgDefaultProps . labelRotation ,
4947 labelTextColor = svgDefaultProps . labelTextColor ,
50-
5148 isInteractive = svgDefaultProps . isInteractive ,
5249 onArcMouseEnter,
5350 onArcMouseMove,
@@ -57,13 +54,12 @@ const InnerChord = ({
5754 onRibbonMouseMove,
5855 onRibbonMouseLeave,
5956 onRibbonClick,
60-
6157 legends = svgDefaultProps . legends ,
62-
6358 role = svgDefaultProps . role ,
6459 ariaLabel,
6560 ariaLabelledBy,
6661 ariaDescribedBy,
62+ forwardedRef,
6763} : InnerChordProps ) => {
6864 const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions (
6965 width ,
@@ -199,6 +195,7 @@ const InnerChord = ({
199195 ariaLabel = { ariaLabel }
200196 ariaLabelledBy = { ariaLabelledBy }
201197 ariaDescribedBy = { ariaDescribedBy }
198+ ref = { forwardedRef }
202199 >
203200 { layers . map ( ( layer , i ) => {
204201 if ( typeof layer === 'function' ) {
@@ -211,23 +208,26 @@ const InnerChord = ({
211208 )
212209}
213210
214- export const Chord = ( {
215- isInteractive = svgDefaultProps . isInteractive ,
216- animate = svgDefaultProps . animate ,
217- motionConfig = svgDefaultProps . motionConfig ,
218- theme,
219- renderWrapper,
220- ...otherProps
221- } : ChordSvgProps ) => (
222- < Container
223- { ...{
224- animate,
225- isInteractive,
226- motionConfig,
227- renderWrapper,
211+ export const Chord = forwardRef (
212+ (
213+ {
214+ isInteractive = svgDefaultProps . isInteractive ,
215+ animate = svgDefaultProps . animate ,
216+ motionConfig = svgDefaultProps . motionConfig ,
228217 theme,
229- } }
230- >
231- < InnerChord isInteractive = { isInteractive } { ...otherProps } />
232- </ Container >
218+ renderWrapper,
219+ ...props
220+ } : ChordSvgProps ,
221+ ref : Ref < SVGSVGElement >
222+ ) => (
223+ < Container
224+ animate = { animate }
225+ isInteractive = { isInteractive }
226+ motionConfig = { motionConfig }
227+ renderWrapper = { renderWrapper }
228+ theme = { theme }
229+ >
230+ < InnerChord isInteractive = { isInteractive } { ...props } forwardedRef = { ref } />
231+ </ Container >
232+ )
233233)
0 commit comments