Skip to content

Commit

Permalink
Add a test case for resolveVariantFromProps
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Dec 28, 2024
1 parent 7001647 commit 52df9f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// `resolveVariantFromProps` in framer-motion
// https://github.com/motiondivision/motion/blob/ecd97f7dce8954be300aa73ab6a96208437941c5/packages/framer-motion/src/render/utils/resolve-variants.ts#L31-L72

export function resolveVariantFromProps(props, definition, custom, visualElement) {
if (typeof definition === "function") {
const [current, velocity] = getValueState(visualElement)
definition = definition(
custom !== undefined ? custom : props.custom,
current,
velocity
)
}

if (typeof definition === "string") {
definition = props.variants && props.variants[definition]
}

if (typeof definition === "function") {
const [current, velocity] = getValueState(visualElement)
definition = definition(
custom !== undefined ? custom : props.custom,
current,
velocity
)
}

return definition
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// `resolveVariantFromProps` in framer-motion
// https://github.com/motiondivision/motion/blob/ecd97f7dce8954be300aa73ab6a96208437941c5/packages/framer-motion/src/render/utils/resolve-variants.ts#L31-L72
export function resolveVariantFromProps(props, definition, custom, visualElement) {
if ("function" == typeof definition) {
const [current, velocity] = getValueState(visualElement)
definition = definition(void 0 !== custom ? custom : props.custom, current, velocity)
}
if ("string" == typeof definition) {
definition = props.variants && props.variants[definition]
}
if ("function" == typeof definition) {
const [current, velocity] = getValueState(visualElement)
definition = definition(void 0 !== custom ? custom : props.custom, current, velocity)
}
return definition
}

0 comments on commit 52df9f2

Please # to comment.