-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly type props in Victory Primitives (#2695)
- Loading branch information
1 parent
238972d
commit 4b3b417
Showing
9 changed files
with
133 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"victory-core": patch | ||
--- | ||
|
||
Correctly type props in Victory Primitives |
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,26 @@ | ||
import React from "react"; | ||
import React, { forwardRef } from "react"; | ||
import { evaluateProp } from "../victory-util/helpers"; | ||
import { VictoryPrimitiveShapeProps } from "./types"; | ||
|
||
export const Circle = (props: VictoryPrimitiveShapeProps) => { | ||
// eslint-disable-next-line react/prop-types | ||
const { desc, ...rest } = props; | ||
return desc ? ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<circle vectorEffect="non-scaling-stroke" {...rest}> | ||
<desc>{desc}</desc> | ||
</circle> | ||
) : ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<circle vectorEffect="non-scaling-stroke" {...rest} /> | ||
); | ||
}; | ||
export const Circle = forwardRef<SVGCircleElement, VictoryPrimitiveShapeProps>( | ||
(props, ref) => { | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars -- | ||
* origin conflicts with the SVG element's origin attribute | ||
*/ | ||
const { desc, id, tabIndex, origin, ...rest } = props; | ||
|
||
const svgProps: React.SVGProps<SVGCircleElement> = { | ||
vectorEffect: "non-scaling-stroke", | ||
id: evaluateProp(id, props)?.toString(), | ||
tabIndex: evaluateProp(tabIndex, props), | ||
...rest, | ||
}; | ||
return desc ? ( | ||
<circle {...svgProps} ref={ref}> | ||
<desc>{desc}</desc> | ||
</circle> | ||
) : ( | ||
<circle {...svgProps} ref={ref} /> | ||
); | ||
}, | ||
); |
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,27 @@ | ||
import React from "react"; | ||
import React, { forwardRef } from "react"; | ||
import { evaluateProp } from "../victory-util/helpers"; | ||
import { VictoryPrimitiveShapeProps } from "./types"; | ||
|
||
export const Line = (props: VictoryPrimitiveShapeProps) => { | ||
// eslint-disable-next-line react/prop-types | ||
const { desc, ...rest } = props; | ||
return desc ? ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<line vectorEffect="non-scaling-stroke" {...rest}> | ||
<desc>{desc}</desc> | ||
</line> | ||
) : ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<line vectorEffect="non-scaling-stroke" {...rest} /> | ||
); | ||
}; | ||
export const Line = forwardRef<SVGLineElement, VictoryPrimitiveShapeProps>( | ||
(props, ref) => { | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars -- | ||
* origin conflicts with the SVG element's origin attribute | ||
*/ | ||
const { desc, id, tabIndex, origin, ...rest } = props; | ||
|
||
const svgProps: React.SVGProps<SVGLineElement> = { | ||
vectorEffect: "non-scaling-stroke", | ||
id: evaluateProp(id, props)?.toString(), | ||
tabIndex: evaluateProp(tabIndex, props), | ||
...rest, | ||
}; | ||
|
||
return desc ? ( | ||
<line {...svgProps} ref={ref}> | ||
<desc>{desc}</desc> | ||
</line> | ||
) : ( | ||
<line {...svgProps} ref={ref} /> | ||
); | ||
}, | ||
); |
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,20 +1,26 @@ | ||
import React, { forwardRef } from "react"; | ||
import { evaluateProp } from "../victory-util/helpers"; | ||
import { VictoryPrimitiveShapeProps } from "./types"; | ||
|
||
// eslint-disable-next-line prefer-arrow-callback | ||
export const Path = forwardRef(function Path( | ||
props: VictoryPrimitiveShapeProps, | ||
ref, | ||
) { | ||
// eslint-disable-next-line react/prop-types | ||
const { desc, ...rest } = props; | ||
return desc ? ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<path {...rest} ref={ref}> | ||
<desc>{desc}</desc> | ||
</path> | ||
) : ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<path {...rest} ref={ref} /> | ||
); | ||
}); | ||
export const Path = forwardRef<SVGPathElement, VictoryPrimitiveShapeProps>( | ||
(props, ref) => { | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars -- | ||
* origin conflicts with the SVG element's origin attribute | ||
*/ | ||
const { desc, id, tabIndex, origin, ...rest } = props; | ||
|
||
const svgProps: React.SVGProps<SVGPathElement> = { | ||
id: evaluateProp(id, props)?.toString(), | ||
tabIndex: evaluateProp(tabIndex, props), | ||
...rest, | ||
}; | ||
|
||
return desc ? ( | ||
<path {...svgProps} ref={ref}> | ||
<desc>{desc}</desc> | ||
</path> | ||
) : ( | ||
<path {...svgProps} ref={ref} /> | ||
); | ||
}, | ||
); |
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,27 @@ | ||
import React from "react"; | ||
import React, { forwardRef } from "react"; | ||
import { evaluateProp } from "../victory-util/helpers"; | ||
import { VictoryPrimitiveShapeProps } from "./types"; | ||
|
||
export const Rect = (props: VictoryPrimitiveShapeProps) => { | ||
// eslint-disable-next-line react/prop-types | ||
const { desc, ...rest } = props; | ||
return desc ? ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<rect vectorEffect="non-scaling-stroke" {...rest}> | ||
<desc>{desc}</desc> | ||
</rect> | ||
) : ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<rect vectorEffect="non-scaling-stroke" {...rest} /> | ||
); | ||
}; | ||
export const Rect = forwardRef<SVGRectElement, VictoryPrimitiveShapeProps>( | ||
(props, ref) => { | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars -- | ||
* origin conflicts with the SVG element's origin attribute | ||
*/ | ||
const { desc, id, tabIndex, origin, ...rest } = props; | ||
|
||
const svgProps: React.SVGProps<SVGRectElement> = { | ||
vectorEffect: "non-scaling-stroke", | ||
id: evaluateProp(id, props)?.toString(), | ||
tabIndex: evaluateProp(tabIndex, props), | ||
...rest, | ||
}; | ||
|
||
return desc ? ( | ||
<rect {...svgProps} ref={ref}> | ||
<desc>{desc}</desc> | ||
</rect> | ||
) : ( | ||
<rect {...svgProps} ref={ref} /> | ||
); | ||
}, | ||
); |
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,7 +1,18 @@ | ||
import React from "react"; | ||
import { evaluateProp } from "../victory-util/helpers"; | ||
import { VictoryCommonPrimitiveProps } from "../victory-util/common-props"; | ||
|
||
export const TSpan = (props: VictoryCommonPrimitiveProps) => ( | ||
// @ts-expect-error FIXME: "id cannot be a number" | ||
<tspan {...props} /> | ||
); | ||
export const TSpan = (props: VictoryCommonPrimitiveProps) => { | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars -- | ||
* origin conflicts with the SVG element's origin attribute | ||
*/ | ||
const { desc, id, tabIndex, origin, ...rest } = props; | ||
|
||
const svgProps: React.SVGProps<SVGTSpanElement> = { | ||
id: evaluateProp(id, props)?.toString(), | ||
tabIndex: evaluateProp(tabIndex, props), | ||
...rest, | ||
}; | ||
|
||
return <tspan {...svgProps} />; | ||
}; |
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
4b3b417
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
victory – ./
victory-git-main-formidable-labs.vercel.app
victory-formidable-labs.vercel.app
victory-rose.vercel.app