Skip to content

Commit

Permalink
Removing default transforms from transform string
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Aug 1, 2024
1 parent 58b8687 commit ebf9861
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ describe("buildTransform", () => {
({ x }: { x: string }) => `translateX(${parseFloat(x) * 2}px)`
)
).toBe("translateX(10px)")

expect(
buildTransform(
{ x: 0, y: 200 },
{},
({ x }: { x: string }, generated) =>
`translateX(${parseFloat(x) + 10}px) ${generated}`
)
).toBe("translateX(10px) translateY(200px)")
})

it("Outputs transform values in the correct order", () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/framer-motion/src/render/html/utils/build-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export function buildTransform(
valueIsDefault = parseFloat(value) === 0
}

if (!valueIsDefault) {
transformIsDefault = false
}

if (!valueIsDefault || transformTemplate) {
const transformName = translateAlias[key] || key
const valueAsType = getValueAsType(value, numberValueTypes[key])
transformString += `${transformName}(${valueAsType}) `

if (!valueIsDefault) {
transformIsDefault = false
const transformName = translateAlias[key] || key
transformString += `${transformName}(${valueAsType}) `
}

if (transformTemplate) {
transform[key] = valueAsType
Expand Down

0 comments on commit ebf9861

Please sign in to comment.