-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(motion): Refactor scale, migrate to new variant structure (#33341)
- Loading branch information
1 parent
a9535f5
commit 899b968
Showing
7 changed files
with
97 additions
and
51 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-motion-components-preview-e2694b39-2078-4d73-ae64-e1515473b8e0.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "feat(motion): Refactor scale, migrate to new variant structure", | ||
"packageName": "@fluentui/react-motion-components-preview", | ||
"email": "olkatruk@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
85 changes: 48 additions & 37 deletions
85
...es/react-components/react-motion-components-preview/library/src/components/Scale/Scale.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 |
---|---|---|
@@ -1,46 +1,57 @@ | ||
import { | ||
motionTokens, | ||
PresenceMotionFn, | ||
createPresenceComponent, | ||
createPresenceComponentVariant, | ||
} from '@fluentui/react-motion'; | ||
import { motionTokens, createPresenceComponent } from '@fluentui/react-motion'; | ||
import { PresenceMotionFnCreator } from '../../types'; | ||
import { ScaleRuntimeParams_unstable, ScaleVariantParams_unstable } from './Scale.types'; | ||
|
||
/** Define a presence motion for scale in/out */ | ||
const scaleMotion: PresenceMotionFn<{ animateOpacity?: boolean }> = ({ 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; | ||
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 enterKeyframes = [ | ||
{ opacity: fromOpacity, transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'visible' }, | ||
{ opacity: toOpacity, transform: `scale3d(${toScale}, ${toScale}, 1)` }, | ||
]; | ||
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: motionTokens.durationGentle, | ||
easing: motionTokens.curveDecelerateMax, | ||
keyframes: enterKeyframes, | ||
}, | ||
exit: { duration: motionTokens.durationNormal, easing: motionTokens.curveAccelerateMax, keyframes: exitKeyframes }, | ||
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 }, | ||
}; | ||
}; | ||
}; | ||
|
||
/** A React component that applies scale in/out transitions to its children. */ | ||
export const Scale = createPresenceComponent(scaleMotion); | ||
export const Scale = createPresenceComponent(createScalePresence()); | ||
|
||
export const ScaleSnappy = createPresenceComponentVariant(Scale, { | ||
enter: { duration: motionTokens.durationNormal, easing: motionTokens.curveDecelerateMax }, | ||
exit: { duration: motionTokens.durationFast, easing: motionTokens.curveAccelerateMax }, | ||
}); | ||
export const ScaleSnappy = createPresenceComponent( | ||
createScalePresence({ | ||
enterDuration: motionTokens.durationNormal, | ||
enterEasing: motionTokens.curveDecelerateMax, | ||
exitDuration: motionTokens.durationFast, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}), | ||
); | ||
|
||
export const ScaleRelaxed = createPresenceComponentVariant(Scale, { | ||
enter: { duration: motionTokens.durationSlow, easing: motionTokens.curveDecelerateMax }, | ||
exit: { duration: motionTokens.durationGentle, easing: motionTokens.curveAccelerateMax }, | ||
}); | ||
export const ScaleRelaxed = createPresenceComponent( | ||
createScalePresence({ | ||
enterDuration: motionTokens.durationSlow, | ||
enterEasing: motionTokens.curveDecelerateMax, | ||
exitDuration: motionTokens.durationGentle, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}), | ||
); |
20 changes: 20 additions & 0 deletions
20
...ct-components/react-motion-components-preview/library/src/components/Scale/Scale.types.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,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type ScaleVariantParams_unstable = { | ||
/** Time (ms) for the enter transition. Defaults to the `durationNormal` value (200 ms). */ | ||
enterDuration?: number; | ||
|
||
/** Easing curve for the enter transition. Defaults to the `easeEaseMax` value. */ | ||
enterEasing?: string; | ||
|
||
/** Time (ms) for the exit transition. Defaults to the `enterDuration` param for symmetry. */ | ||
exitDuration?: number; | ||
|
||
/** Easing curve for the exit transition. Defaults to the `enterEasing` param for symmetry. */ | ||
exitEasing?: string; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type ScaleRuntimeParams_unstable = { | ||
/** Whether to animate the opacity. Defaults to `true`. */ | ||
animateOpacity?: boolean; | ||
}; |
2 changes: 1 addition & 1 deletion
2
...es/react-components/react-motion-components-preview/library/src/components/Scale/index.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 |
---|---|---|
@@ -1 +1 @@ | ||
export { Scale, ScaleRelaxed, ScaleSnappy } from './Scale'; | ||
export { Scale, ScaleRelaxed, ScaleSnappy, createScalePresence } from './Scale'; |
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
16 changes: 10 additions & 6 deletions
16
...react-motion-components-preview/stories/src/Scale/ScaleCustomization.stories.md
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