-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor(motion): simplify Fade & Scale variant creation with createPresenceComponentVariant
#34042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
robertpenner
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
robertpenner:refactor/fade-scale-variants
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d44a35b
fix(motion): make createPresenceComponentVariant work with arrays of …
robertpenner c5ad39a
chore(motion): regenerate api.md
robertpenner 66b4c26
chore(motion): `yarn change`
robertpenner 59731eb
refactor(motion): have Fade & Scale use the fixed createPresenceCompo…
robertpenner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-motion-fea25e01-77ef-434c-a942-f907bdc4a2a5.json
This file contains hidden or 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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "fix(motion): createPresenceComponentVariant did not support motion arrays", | ||
"packageName": "@fluentui/react-motion", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ges/react-components/react-motion-components-preview/library/src/components/Fade/index.ts
This file contains hidden or 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 +1 @@ | ||
export { Fade, FadeRelaxed, FadeSnappy, createFadePresence } from './Fade'; | ||
export { Fade, FadeRelaxed, FadeSnappy } from './Fade'; |
102 changes: 54 additions & 48 deletions
102
...es/react-components/react-motion-components-preview/library/src/components/Scale/Scale.ts
This file contains hidden or 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,57 +1,63 @@ | ||
import { motionTokens, createPresenceComponent } from '@fluentui/react-motion'; | ||
import { PresenceMotionFnCreator } from '../../types'; | ||
import { ScaleRuntimeParams_unstable, ScaleVariantParams_unstable } from './Scale.types'; | ||
import { | ||
motionTokens, | ||
createPresenceComponent, | ||
PresenceMotionFn, | ||
createPresenceComponentVariant, | ||
} from '@fluentui/react-motion'; | ||
|
||
/** Define a presence motion for scale in/out */ | ||
export const createScalePresence: PresenceMotionFnCreator<ScaleVariantParams_unstable, ScaleRuntimeParams_unstable> = | ||
({ | ||
enterDuration = motionTokens.durationGentle, | ||
enterEasing = motionTokens.curveDecelerateMax, | ||
exitDuration = motionTokens.durationNormal, | ||
exitEasing = motionTokens.curveAccelerateMax, | ||
} = {}) => | ||
({ animateOpacity = true }) => { | ||
const fromOpacity = animateOpacity ? 0 : 1; | ||
const toOpacity = 1; | ||
const fromScale = 0.9; // Could be a custom param in the future | ||
const toScale = 1; | ||
const scalePresenceFn: PresenceMotionFn<{ | ||
duration?: number; | ||
easing?: string; | ||
exitDuration?: number; | ||
exitEasing?: string; | ||
fromScale?: number; | ||
animateOpacity?: boolean; | ||
}> = ({ | ||
duration = motionTokens.durationNormal, | ||
easing = motionTokens.curveDecelerateMid, | ||
exitDuration = duration, | ||
exitEasing = motionTokens.curveAccelerateMid, | ||
fromScale = 0.9, | ||
animateOpacity = true, | ||
}) => { | ||
const fromOpacity = animateOpacity ? 0 : 1; | ||
const toOpacity = 1; | ||
const toScale = 1; | ||
|
||
const enterKeyframes = [ | ||
{ opacity: fromOpacity, transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'visible' }, | ||
{ opacity: toOpacity, transform: `scale3d(${toScale}, ${toScale}, 1)` }, | ||
]; | ||
// TODO: use fadeAtom | ||
// TODO: make scaleAtom | ||
const enterKeyframes = [ | ||
{ opacity: fromOpacity, transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'visible' }, | ||
{ opacity: toOpacity, transform: `scale3d(${toScale}, ${toScale}, 1)` }, | ||
]; | ||
|
||
const exitKeyframes = [ | ||
{ opacity: toOpacity, transform: `scale3d(${toScale}, ${toScale}, 1)` }, | ||
{ opacity: fromOpacity, transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'hidden' }, | ||
]; | ||
return { | ||
enter: { | ||
duration: enterDuration, | ||
easing: enterEasing, | ||
keyframes: enterKeyframes, | ||
}, | ||
exit: { duration: exitDuration, easing: exitEasing, keyframes: exitKeyframes }, | ||
}; | ||
const exitKeyframes = [ | ||
{ opacity: toOpacity, transform: `scale3d(${toScale}, ${toScale}, 1)` }, | ||
{ opacity: fromOpacity, transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'hidden' }, | ||
]; | ||
|
||
return { | ||
enter: { | ||
duration, | ||
easing, | ||
keyframes: enterKeyframes, | ||
}, | ||
exit: { duration: exitDuration, easing: exitEasing, keyframes: exitKeyframes }, | ||
}; | ||
}; | ||
|
||
/** A React component that applies scale in/out transitions to its children. */ | ||
export const Scale = createPresenceComponent(createScalePresence()); | ||
export const Scale = createPresenceComponent(scalePresenceFn); | ||
|
||
export const ScaleSnappy = createPresenceComponent( | ||
createScalePresence({ | ||
enterDuration: motionTokens.durationNormal, | ||
enterEasing: motionTokens.curveDecelerateMax, | ||
exitDuration: motionTokens.durationFast, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}), | ||
); | ||
export const ScaleSnappy = createPresenceComponentVariant(Scale, { | ||
duration: motionTokens.durationFast, | ||
easing: motionTokens.curveDecelerateMax, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}); | ||
|
||
export const ScaleRelaxed = createPresenceComponent( | ||
createScalePresence({ | ||
enterDuration: motionTokens.durationSlow, | ||
enterEasing: motionTokens.curveDecelerateMax, | ||
exitDuration: motionTokens.durationGentle, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}), | ||
); | ||
export const ScaleRelaxed = createPresenceComponentVariant(Scale, { | ||
duration: motionTokens.durationGentle, | ||
easing: motionTokens.curveDecelerateMid, | ||
exitEasing: motionTokens.curveAccelerateMid, | ||
}); |
2 changes: 1 addition & 1 deletion
2
...es/react-components/react-motion-components-preview/library/src/components/Scale/index.ts
This file contains hidden or 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 +1 @@ | ||
export { Scale, ScaleRelaxed, ScaleSnappy, createScalePresence } from './Scale'; | ||
export { Scale, ScaleRelaxed, ScaleSnappy } from './Scale'; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual regressions to review in the fluentuiv9 Visual Regression Report
Drawer 2 screenshots