-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scale): add scaleAtom and refactor Scale component for enhanced …
…animations
- Loading branch information
1 parent
639871a
commit 75ec58b
Showing
8 changed files
with
156 additions
and
60 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
2 changes: 1 addition & 1 deletion
2
...es/react-components/react-motion-components-preview/library/src/components/Atoms/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 { opacityAtom } from './Atoms'; | ||
export { opacityAtom, scaleAtom } from './Atoms'; |
38 changes: 37 additions & 1 deletion
38
...mponents/react-motion-components-preview/library/src/components/Collapse/Collapse.test.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
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
25 changes: 24 additions & 1 deletion
25
...act-components/react-motion-components-preview/library/src/components/Scale/Scale.test.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
100 changes: 60 additions & 40 deletions
100
...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,66 @@ | ||
import { | ||
motionTokens, | ||
PresenceMotionFn, | ||
createPresenceComponent, | ||
createPresenceComponentVariant, | ||
} from '@fluentui/react-motion'; | ||
import { motionTokens, createPresenceComponent } from '@fluentui/react-motion'; | ||
import { PresenceMotionFnCreator } from '../../types'; | ||
import { opacityAtom, scaleAtom } from '../Atoms'; | ||
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; | ||
|
||
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 }, | ||
}; | ||
}; | ||
export const createScalePresence: PresenceMotionFnCreator<ScaleVariantParams_unstable, ScaleRuntimeParams_unstable> = | ||
({ | ||
enterDuration = motionTokens.durationGentle, | ||
enterEasing = motionTokens.curveEasyEaseMax, | ||
exitDuration = motionTokens.durationNormal, | ||
exitEasing = motionTokens.curveAccelerateMax, | ||
} = {}) => | ||
({ animateOpacity = true }) => ({ | ||
enter: [ | ||
scaleAtom({ | ||
duration: enterDuration, | ||
easing: enterEasing, | ||
}), | ||
...(animateOpacity | ||
? [ | ||
opacityAtom({ | ||
duration: enterDuration, | ||
easing: enterEasing, | ||
}), | ||
] | ||
: []), | ||
], | ||
exit: [ | ||
scaleAtom({ | ||
duration: exitDuration, | ||
easing: exitEasing, | ||
direction: 'reverse', | ||
}), | ||
...(animateOpacity | ||
? [ | ||
opacityAtom({ | ||
duration: exitDuration, | ||
easing: exitEasing, | ||
direction: 'reverse', | ||
}), | ||
] | ||
: []), | ||
], | ||
}); | ||
|
||
/** 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, | ||
}), | ||
); |
28 changes: 14 additions & 14 deletions
28
...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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type ScaleRuntimeParams_unstable = { | ||
/** Whether to animate the opacity. Defaults to `true`. */ | ||
animateOpacity?: boolean; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type ScaleVariantParams_unstable = { | ||
/** Time (ms) for the enter transition (expand). Defaults to the `durationNormal` value (200 ms). */ | ||
enterScaleDuration?: number; | ||
/** Time (ms) for the enter transition. Defaults to the `durationNormal` value (200 ms). */ | ||
enterDuration?: number; | ||
|
||
/** Easing curve for the enter transition (expand). Defaults to the `easeEaseMax` value. */ | ||
enterScaleEasing?: string; | ||
/** Easing curve for the enter transition. Defaults to the `easeEaseMax` value. */ | ||
enterEasing?: string; | ||
|
||
/** Time (ms) for the exit transition (collapse). Defaults to the `enterDuration` param for symmetry. */ | ||
exitScaleDuration?: number; | ||
/** Time (ms) for the exit transition. Defaults to the `enterDuration` param for symmetry. */ | ||
exitDuration?: number; | ||
|
||
/** Easing curve for the exit transition (collapse). Defaults to the `enterEasing` param for symmetry. */ | ||
exitScaleEasing?: string; | ||
/** 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
packages/react-components/react-motion-components-preview/library/src/testing/testUtils.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