|
1 |
| -import { |
2 |
| - motionTokens, |
3 |
| - PresenceMotion, |
4 |
| - createPresenceComponent, |
5 |
| - createPresenceComponentVariant, |
6 |
| -} from '@fluentui/react-motion'; |
| 1 | +import { motionTokens, createPresenceComponent } from '@fluentui/react-motion'; |
| 2 | +import type { PresenceMotionCreator } from '../../types'; |
7 | 3 |
|
8 |
| -const duration = motionTokens.durationNormal; |
9 |
| -const easing = motionTokens.curveEasyEase; |
| 4 | +type FadeVariantParams = { |
| 5 | + /** Time (ms) for the enter transition (fade-in). Defaults to the `durationNormal` value (200 ms). */ |
| 6 | + enterDuration?: number; |
10 | 7 |
|
11 |
| -/** Define a presence motion for fade in/out */ |
12 |
| -const fadeMotion: PresenceMotion = { |
13 |
| - enter: { duration, easing, keyframes: [{ opacity: 0 }, { opacity: 1 }] }, |
14 |
| - exit: { duration, easing, keyframes: [{ opacity: 1 }, { opacity: 0 }] }, |
| 8 | + /** Easing curve for the enter transition (fade-in). Defaults to the `easeEase` value. */ |
| 9 | + enterEasing?: string; |
| 10 | + |
| 11 | + /** Time (ms) for the exit transition (fade-out). Defaults to the `enterDuration` param for symmetry. */ |
| 12 | + exitDuration?: number; |
| 13 | + |
| 14 | + /** Easing curve for the exit transition (fade-out). Defaults to the `enterEasing` param for symmetry. */ |
| 15 | + exitEasing?: string; |
15 | 16 | };
|
16 | 17 |
|
| 18 | +/** Define a presence motion for fade in/out */ |
| 19 | +export const createFadePresence: PresenceMotionCreator<FadeVariantParams> = ({ |
| 20 | + enterDuration = motionTokens.durationNormal, |
| 21 | + enterEasing = motionTokens.curveEasyEase, |
| 22 | + exitDuration = enterDuration, |
| 23 | + exitEasing = enterEasing, |
| 24 | +} = {}) => ({ |
| 25 | + enter: { duration: enterDuration, easing: enterEasing, keyframes: [{ opacity: 0 }, { opacity: 1 }] }, |
| 26 | + exit: { duration: exitDuration, easing: exitEasing, keyframes: [{ opacity: 1 }, { opacity: 0 }] }, |
| 27 | +}); |
| 28 | + |
17 | 29 | /** A React component that applies fade in/out transitions to its children. */
|
18 |
| -export const Fade = createPresenceComponent(fadeMotion); |
| 30 | +export const Fade = createPresenceComponent(createFadePresence()); |
19 | 31 |
|
20 |
| -export const FadeSnappy = createPresenceComponentVariant(Fade, { all: { duration: motionTokens.durationFast } }); |
| 32 | +export const FadeSnappy = createPresenceComponent(createFadePresence({ enterDuration: motionTokens.durationFast })); |
21 | 33 |
|
22 |
| -export const FadeExaggerated = createPresenceComponentVariant(Fade, { all: { duration: motionTokens.durationGentle } }); |
| 34 | +export const FadeExaggerated = createPresenceComponent( |
| 35 | + createFadePresence({ enterDuration: motionTokens.durationGentle }), |
| 36 | +); |
0 commit comments