Skip to content

Commit a60b9e9

Browse files
Merge pull request #2083 from framer/fix/svg-scale-attr
Adding support for `attrScale`
2 parents c447773 + b2cd14f commit a60b9e9

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

packages/framer-motion/src/render/svg/__tests__/use-props.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe("SVG useProps", () => {
99
{
1010
attrX: 1,
1111
attrY: motionValue(5),
12+
attrScale: 3,
1213
cx: 2,
1314
style: {
1415
x: 3,
@@ -18,6 +19,7 @@ describe("SVG useProps", () => {
1819
{
1920
attrX: 6,
2021
attrY: 10,
22+
attrScale: 4,
2123
cx: 7,
2224
x: 8,
2325
scale: 9,
@@ -30,6 +32,7 @@ describe("SVG useProps", () => {
3032
expect(result.current).toStrictEqual({
3133
x: 6,
3234
y: 10,
35+
scale: 4,
3336
cx: 7,
3437
style: {},
3538
})

packages/framer-motion/src/render/svg/utils/__tests__/scrape-motion-values.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ describe("SVG scrapeMotionValuesFromProps", () => {
66
const x = motionValue(0)
77
const attrX = motionValue(0)
88
const attrY = motionValue(0)
9+
const scale = motionValue(0)
10+
const attrScale = motionValue(0)
911

1012
expect(
1113
scrapeMotionValuesFromProps(
1214
{
1315
x: attrX,
1416
attrY,
17+
scale: attrScale,
1518
prev: 0,
16-
style: { x },
19+
style: { x, scale },
1720
} as any,
1821
{
1922
prev: motionValue(1),
@@ -22,7 +25,9 @@ describe("SVG scrapeMotionValuesFromProps", () => {
2225
).toEqual({
2326
attrX,
2427
attrY,
28+
attrScale,
2529
x,
30+
scale,
2631
prev: 0,
2732
})
2833
})

packages/framer-motion/src/render/svg/utils/build-attrs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function buildSVGAttrs(
1414
{
1515
attrX,
1616
attrY,
17+
attrScale,
1718
originX,
1819
originY,
1920
pathLength,
@@ -63,9 +64,10 @@ export function buildSVGAttrs(
6364
)
6465
}
6566

66-
// Treat x/y not as shortcuts but as actual attributes
67+
// Render attrX/attrY/attrScale as attributes
6768
if (attrX !== undefined) attrs.x = attrX
6869
if (attrY !== undefined) attrs.y = attrY
70+
if (attrScale !== undefined) attrs.scale = attrScale
6971

7072
// Build SVG path if one has been defined
7173
if (pathLength !== undefined) {

packages/framer-motion/src/render/svg/utils/scrape-motion-values.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MotionProps } from "../../../motion/types"
22
import { isMotionValue } from "../../../value/utils/is-motion-value"
33
import { scrapeMotionValuesFromProps as scrapeHTMLMotionValuesFromProps } from "../../html/utils/scrape-motion-values"
4+
import { transformPropOrder } from "../../html/utils/transform"
45

56
export function scrapeMotionValuesFromProps(
67
props: MotionProps,
@@ -11,7 +12,10 @@ export function scrapeMotionValuesFromProps(
1112
for (const key in props) {
1213
if (isMotionValue(props[key]) || isMotionValue(prevProps[key])) {
1314
const targetKey =
14-
key === "x" || key === "y" ? "attr" + key.toUpperCase() : key
15+
transformPropOrder.indexOf(key) !== -1
16+
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
17+
: key
18+
1519
newValues[targetKey] = props[key]
1620
}
1721
}

0 commit comments

Comments
 (0)