Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1321 from framer/fix/remove-padding-from-height-m…
…easurement Removing padding from measurement when converting width/height values
- Loading branch information
Showing
4 changed files
with
107 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from "react" | ||
import { useState } from "react" | ||
import { motion, AnimatePresence } from "@framer" | ||
|
||
export const App = () => { | ||
const [isExpanded, setExpanded] = useState(false) | ||
|
||
return ( | ||
<div className="example-container"> | ||
<AnimatePresence> | ||
{isExpanded ? ( | ||
<motion.div | ||
animate={{ | ||
height: "auto", | ||
opacity: 1, | ||
paddingTop: 30, | ||
paddingBottom: 30, | ||
}} | ||
exit={{ | ||
height: 0, | ||
opacity: 0, | ||
paddingTop: 0, | ||
paddingBottom: 0, | ||
}} | ||
initial={{ | ||
height: 0, | ||
opacity: 0, | ||
paddingTop: 0, | ||
paddingBottom: 0, | ||
}} | ||
style={{ background: "white", width: 200 }} | ||
> | ||
Test | ||
</motion.div> | ||
) : null} | ||
</AnimatePresence> | ||
<button style={{}} onClick={() => setExpanded(!isExpanded)}> | ||
Toggle | ||
</button> | ||
<style>{styles}</style> | ||
</div> | ||
) | ||
} | ||
|
||
const styles = `body { | ||
background: white!important; | ||
background-repeat: no-repeat; | ||
padding: 0; | ||
margin: 0; | ||
display: flex; | ||
justify-content: flex-start; | ||
align-items: flex-start; | ||
} | ||
.example-container { | ||
width: 320px; | ||
padding: 20px; | ||
} | ||
}` |
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,25 @@ | ||
import { positionalValues } from "../unit-conversion" | ||
|
||
describe("Unit conversion", () => { | ||
test("Correctly factors in padding when measuring width/height", () => { | ||
const testDimensions = { | ||
x: { min: 0, max: 100 }, | ||
y: { min: 0, max: 300 }, | ||
} | ||
expect( | ||
positionalValues.width(testDimensions, { paddingLeft: "50px" }) | ||
).toBe(50) | ||
|
||
expect( | ||
positionalValues.width(testDimensions, { paddingRight: "25px" }) | ||
).toBe(75) | ||
|
||
expect( | ||
positionalValues.height(testDimensions, { paddingTop: "50px" }) | ||
).toBe(250) | ||
|
||
expect( | ||
positionalValues.height(testDimensions, { paddingBottom: "25px" }) | ||
).toBe(275) | ||
}) | ||
}) |
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