-
-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animate values when child variant definitions change (#2804)
* Animate values when child variant definitions change * Fixing test * Updating bundlesize
- Loading branch information
1 parent
f7b6212
commit 111c7c0
Showing
6 changed files
with
83 additions
and
51 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
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
43 changes: 43 additions & 0 deletions
43
packages/framer-motion/src/render/utils/get-variant-context.ts
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,43 @@ | ||
import { VisualElement } from "../VisualElement" | ||
import { isVariantLabel } from "./is-variant-label" | ||
import { variantProps } from "./variant-props" | ||
|
||
const numVariantProps = variantProps.length | ||
|
||
type VariantStateContext = { | ||
initial?: string | string[] | ||
animate?: string | string[] | ||
exit?: string | string[] | ||
whileHover?: string | string[] | ||
whileDrag?: string | string[] | ||
whileFocus?: string | string[] | ||
whileTap?: string | string[] | ||
} | ||
|
||
export function getVariantContext( | ||
visualElement?: VisualElement | ||
): undefined | VariantStateContext { | ||
if (!visualElement) return undefined | ||
|
||
if (!visualElement.isControllingVariants) { | ||
const context = visualElement.parent | ||
? getVariantContext(visualElement.parent) || {} | ||
: {} | ||
if (visualElement.props.initial !== undefined) { | ||
context.initial = visualElement.props.initial as any | ||
} | ||
return context | ||
} | ||
|
||
const context = {} | ||
for (let i = 0; i < numVariantProps; i++) { | ||
const name = variantProps[i] as keyof typeof context | ||
const prop = visualElement.props[name] | ||
|
||
if (isVariantLabel(prop) || prop === false) { | ||
context[name] = prop | ||
} | ||
} | ||
|
||
return context | ||
} |