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 #1829 from framer/fix/map-easing-names
Map WAAPI easing names
- Loading branch information
Showing
7 changed files
with
180 additions
and
9 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,23 @@ | ||
import * as React from "react" | ||
import { useState } from "react" | ||
import { motion } from "framer-motion" | ||
|
||
const style = { | ||
width: 100, | ||
height: 100, | ||
background: "white", | ||
} | ||
|
||
export const App = () => { | ||
const [state, setState] = useState(false) | ||
|
||
return ( | ||
<motion.div | ||
initial={{ backgroundColor: "#00f" }} | ||
animate={{ backgroundColor: state ? "#00f" : "#f00" }} | ||
onClick={() => setState(!state)} | ||
transition={{ duration: 1 }} | ||
style={style} | ||
/> | ||
) | ||
} |
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,4 +1,26 @@ | ||
import { BezierDefinition } from "../../easing/types" | ||
import { BezierDefinition, EasingDefinition } from "../../easing/types" | ||
import { camelToDash } from "../../render/dom/utils/camel-to-dash" | ||
|
||
export const cubicBezierAsString = ([a, b, c, d]: BezierDefinition) => | ||
`cubic-bezier(${a}, ${b}, ${c}, ${d})` | ||
|
||
const validWaapiEasing = new Set([ | ||
"linear", | ||
"ease-in", | ||
"ease-out", | ||
"ease-in-out", | ||
]) | ||
|
||
export function mapEasingName(easingName: string): string { | ||
const name = camelToDash(easingName) | ||
return validWaapiEasing.has(name) ? name : "ease" | ||
} | ||
|
||
export function mapEasingToNativeEasing( | ||
easing?: EasingDefinition | ||
): string | undefined { | ||
if (!easing) return undefined | ||
return Array.isArray(easing) | ||
? cubicBezierAsString(easing) | ||
: mapEasingName(easing) | ||
} |
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
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