Skip to content

Commit daef7d4

Browse files
authored
Merge branch 'master' into feat/link-contributors-docsite
2 parents 92811f5 + 39269ba commit daef7d4

File tree

7 files changed

+72
-30
lines changed

7 files changed

+72
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "refactor: migrate Fade motion component to new variant structure",
4+
"packageName": "@fluentui/react-motion-components-preview",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-motion-components-preview/library/etc/react-motion-components-preview.api.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import type { MotionParam } from '@fluentui/react-motion';
88
import { PresenceComponent } from '@fluentui/react-motion';
9+
import type { PresenceMotion } from '@fluentui/react-motion';
910
import type { PresenceMotionFn } from '@fluentui/react-motion';
1011

1112
// @public
@@ -26,6 +27,9 @@ export const createCollapseDelayedPresence: PresenceMotionFnCreator<CollapseDela
2627
// @public
2728
export const createCollapsePresence: PresenceMotionFnCreator<CollapseVariantParams, CollapseRuntimeParams>;
2829

30+
// @public
31+
export const createFadePresence: PresenceMotionCreator<FadeVariantParams>;
32+
2933
// @public
3034
export const Fade: PresenceComponent< {}>;
3135

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
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';
73

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;
107

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;
1516
};
1617

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+
1729
/** A React component that applies fade in/out transitions to its children. */
18-
export const Fade = createPresenceComponent(fadeMotion);
30+
export const Fade = createPresenceComponent(createFadePresence());
1931

20-
export const FadeSnappy = createPresenceComponentVariant(Fade, { all: { duration: motionTokens.durationFast } });
32+
export const FadeSnappy = createPresenceComponent(createFadePresence({ enterDuration: motionTokens.durationFast }));
2133

22-
export const FadeExaggerated = createPresenceComponentVariant(Fade, { all: { duration: motionTokens.durationGentle } });
34+
export const FadeExaggerated = createPresenceComponent(
35+
createFadePresence({ enterDuration: motionTokens.durationGentle }),
36+
);

packages/react-components/react-motion-components-preview/library/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export {
66
createCollapsePresence,
77
createCollapseDelayedPresence,
88
} from './components/Collapse';
9-
export { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';
9+
export { Fade, FadeSnappy, FadeExaggerated, createFadePresence } from './components/Fade';
1010
export { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';

packages/react-components/react-motion-components-preview/library/src/types.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import type { MotionParam, PresenceMotionFn } from '@fluentui/react-motion';
1+
import type { MotionParam, PresenceMotion, PresenceMotionFn } from '@fluentui/react-motion';
2+
3+
/**
4+
* This is a factory function that generates a motion object from variant params, e.g. duration, easing, etc.
5+
* The generated object defines a presence motion with `enter` and `exit` transitions.
6+
* This motion object is declarative, i.e. data without side effects,
7+
* and it is framework-independent, i.e. non-React.
8+
* It can be turned into a React component using `createPresenceComponent`.
9+
*/
10+
// TODO: move to @fluentui/react-motion when stable
11+
export type PresenceMotionCreator<MotionVariantParams extends Record<string, MotionParam> = {}> = (
12+
variantParams?: MotionVariantParams,
13+
) => PresenceMotion;
214

315
/**
416
* This is a factory function that generates a motion function, which has variant params bound into it.

packages/react-components/react-motion-components-preview/stories/src/Fade/FadeCustomization.stories.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
- `duration` and `easing` can be customized for each transition separately using `createPresenceComponentVariant()`.
1+
- A fade variant can be created with the factory function `createFadePresence()`, then converting the result to a React component using `createPresenceComponent()`:
22

33
```tsx
4-
import { motionTokens, createPresenceComponentVariant } from '@fluentui/react-components';
5-
import { Fade } from '@fluentui/react-motion-components-preview';
4+
import { motionTokens } from '@fluentui/react-components';
65

7-
const CustomFadeVariant = createPresenceComponentVariant(Fade, {
8-
enter: { duration: motionTokens.durationSlow, easing: motionTokens.curveEasyEaseMax },
9-
exit: { duration: motionTokens.durationNormal, easing: motionTokens.curveEasyEaseMax },
10-
});
6+
const CustomFadeVariant = createPresenceComponent(
7+
createFadePresence({
8+
enterDuration: motionTokens.durationSlow,
9+
enterEasing: motionTokens.curveEasyEaseMax,
10+
exitDuration: motionTokens.durationNormal,
11+
}),
12+
);
1113

1214
const CustomFade = ({ visible }) => (
1315
<CustomFadeVariant unmountOnExit visible={visible}>

packages/react-components/react-motion-components-preview/stories/src/Fade/FadeCustomization.stories.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import {
3-
createPresenceComponentVariant,
3+
createPresenceComponent,
44
Field,
55
makeStyles,
66
mergeClasses,
@@ -10,7 +10,7 @@ import {
1010
Switch,
1111
tokens,
1212
} from '@fluentui/react-components';
13-
import { Fade } from '@fluentui/react-motion-components-preview';
13+
import { createFadePresence } from '@fluentui/react-motion-components-preview';
1414

1515
import description from './FadeCustomization.stories.md';
1616

@@ -54,10 +54,13 @@ const useClasses = makeStyles({
5454
},
5555
});
5656

57-
const CustomFadeVariant = createPresenceComponentVariant(Fade, {
58-
enter: { duration: motionTokens.durationSlow, easing: motionTokens.curveEasyEaseMax },
59-
exit: { duration: motionTokens.durationNormal, easing: motionTokens.curveEasyEaseMax },
60-
});
57+
const CustomFadeVariant = createPresenceComponent(
58+
createFadePresence({
59+
enterDuration: motionTokens.durationSlow,
60+
enterEasing: motionTokens.curveEasyEaseMax,
61+
exitDuration: motionTokens.durationNormal,
62+
}),
63+
);
6164

6265
const LoremIpsum = () => (
6366
<>

0 commit comments

Comments
 (0)