@fluentui/react-motion-components-preview 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/index.d.ts +40 -9
- package/lib/components/Collapse/Collapse.js +91 -68
- package/lib/components/Collapse/Collapse.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types.js +11 -0
- package/lib/types.js.map +1 -0
- package/lib-commonjs/components/Collapse/Collapse.js +92 -67
- package/lib-commonjs/components/Collapse/Collapse.js.map +1 -1
- package/lib-commonjs/index.js +3 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.js +14 -0
- package/lib-commonjs/types.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,23 @@
|
|
1
1
|
# Change Log - @fluentui/react-motion-components-preview
|
2
2
|
|
3
|
-
This log was last generated on Tue,
|
3
|
+
This log was last generated on Tue, 15 Oct 2024 17:13:29 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [0.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-motion-components-preview_v0.2.0)
|
8
|
+
|
9
|
+
Tue, 15 Oct 2024 17:13:29 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motion-components-preview_v0.1.1..@fluentui/react-motion-components-preview_v0.2.0)
|
11
|
+
|
12
|
+
### Minor changes
|
13
|
+
|
14
|
+
- refactor: simplify motion component variant creation ([PR #32939](https://github.com/microsoft/fluentui/pull/32939) by robertpenner@microsoft.com)
|
15
|
+
- feat: add Collapse orientation parameter & horizontal implementation ([PR #32998](https://github.com/microsoft/fluentui/pull/32998) by robertpenner@microsoft.com)
|
16
|
+
|
17
|
+
### Patches
|
18
|
+
|
19
|
+
- fix: Collapse should only effect opacity when animateOpacity is true ([PR #32999](https://github.com/microsoft/fluentui/pull/32999) by robertpenner@microsoft.com)
|
20
|
+
|
7
21
|
## [0.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-motion-components-preview_v0.1.1)
|
8
22
|
|
9
23
|
Tue, 23 Jul 2024 20:13:12 GMT
|
package/dist/index.d.ts
CHANGED
@@ -1,17 +1,36 @@
|
|
1
|
+
import type { MotionParam } from '@fluentui/react-motion';
|
1
2
|
import { PresenceComponent } from '@fluentui/react-motion';
|
3
|
+
import type { PresenceMotionFn } from '@fluentui/react-motion';
|
2
4
|
|
3
5
|
/** A React component that applies collapse/expand transitions to its children. */
|
4
|
-
export declare const Collapse: PresenceComponent<
|
5
|
-
animateOpacity?: boolean | undefined;
|
6
|
-
}>;
|
6
|
+
export declare const Collapse: PresenceComponent<CollapseRuntimeParams>;
|
7
7
|
|
8
|
-
export declare const CollapseExaggerated: PresenceComponent<
|
9
|
-
animateOpacity?: boolean | undefined;
|
10
|
-
}>;
|
8
|
+
export declare const CollapseExaggerated: PresenceComponent<CollapseRuntimeParams>;
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
declare type CollapseOrientation = 'horizontal' | 'vertical';
|
11
|
+
|
12
|
+
declare type CollapseRuntimeParams = {
|
13
|
+
/** Whether to animate the opacity. Defaults to `true`. */
|
14
|
+
animateOpacity?: boolean;
|
15
|
+
/** The orientation of the size animation. Defaults to `'vertical'` to expand/collapse the height. */
|
16
|
+
orientation?: CollapseOrientation;
|
17
|
+
};
|
18
|
+
|
19
|
+
export declare const CollapseSnappy: PresenceComponent<CollapseRuntimeParams>;
|
20
|
+
|
21
|
+
declare type CollapseVariantParams = {
|
22
|
+
/** Time (ms) for the enter transition (expand). Defaults to the `durationNormal` value (200 ms). */
|
23
|
+
enterDuration?: number;
|
24
|
+
/** Easing curve for the enter transition (expand). Defaults to the `easeEaseMax` value. */
|
25
|
+
enterEasing?: string;
|
26
|
+
/** Time (ms) for the exit transition (collapse). Defaults to the `enterDuration` param for symmetry. */
|
27
|
+
exitDuration?: number;
|
28
|
+
/** Easing curve for the exit transition (collapse). Defaults to the `enterEasing` param for symmetry. */
|
29
|
+
exitEasing?: string;
|
30
|
+
};
|
31
|
+
|
32
|
+
/** Define a presence motion for collapse/expand */
|
33
|
+
export declare const createCollapsePresence: PresenceMotionFnCreator<CollapseVariantParams, CollapseRuntimeParams>;
|
15
34
|
|
16
35
|
/** A React component that applies fade in/out transitions to its children. */
|
17
36
|
export declare const Fade: PresenceComponent< {}>;
|
@@ -20,6 +39,18 @@ export declare const FadeExaggerated: PresenceComponent< {}>;
|
|
20
39
|
|
21
40
|
export declare const FadeSnappy: PresenceComponent< {}>;
|
22
41
|
|
42
|
+
/**
|
43
|
+
* This is a factory function that generates a motion function, which has variant params bound into it.
|
44
|
+
* The generated motion function accepts other runtime params that aren't locked into the variant, but supplied at runtime.
|
45
|
+
* This separation allows the variant to be defined once and reused with different runtime params which may be orthogonal to the variant params.
|
46
|
+
* For example, a variant may define the duration and easing of a transition, which are fixed for all instances of the variant,
|
47
|
+
* while the runtime params may give access to the target element, which is different for each instance.
|
48
|
+
*
|
49
|
+
* The generated motion function is also framework-independent, i.e. non-React.
|
50
|
+
* It can be turned into a React component using `createPresenceComponent`.
|
51
|
+
*/
|
52
|
+
declare type PresenceMotionFnCreator<MotionVariantParams extends Record<string, MotionParam> = {}, MotionRuntimeParams extends Record<string, MotionParam> = {}> = (variantParams?: MotionVariantParams) => PresenceMotionFn<MotionRuntimeParams>;
|
53
|
+
|
23
54
|
/** A React component that applies scale in/out transitions to its children. */
|
24
55
|
export declare const Scale: PresenceComponent< {
|
25
56
|
animateOpacity?: boolean | undefined;
|
@@ -1,71 +1,94 @@
|
|
1
|
-
import { motionTokens, createPresenceComponent
|
2
|
-
/** Define a presence motion for collapse/expand */ const
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
import { motionTokens, createPresenceComponent } from '@fluentui/react-motion';
|
2
|
+
/** Define a presence motion for collapse/expand */ export const createCollapsePresence = ({ enterDuration = motionTokens.durationNormal, enterEasing = motionTokens.curveEasyEaseMax, exitDuration = enterDuration, exitEasing = enterEasing } = {})=>({ element, animateOpacity = true, orientation = 'vertical' })=>{
|
3
|
+
const fromOpacity = 0;
|
4
|
+
const toOpacity = 1;
|
5
|
+
const fromSize = '0'; // Could be a custom param in the future to start with partially expanded width or height
|
6
|
+
const measuredSize = orientation === 'horizontal' ? element.scrollWidth : element.scrollHeight;
|
7
|
+
const toSize = `${measuredSize}px`;
|
8
|
+
// use generic names for size and overflow, handling vertical or horizontal orientation
|
9
|
+
const sizeName = orientation === 'horizontal' ? 'maxWidth' : 'maxHeight';
|
10
|
+
const overflowName = orientation === 'horizontal' ? 'overflowX' : 'overflowY';
|
11
|
+
// The enter transition is an array of up to 2 motion atoms: size and opacity.
|
12
|
+
const enterAtoms = [
|
13
|
+
// Expand size (height or width)
|
14
|
+
{
|
15
|
+
keyframes: [
|
16
|
+
{
|
17
|
+
[sizeName]: fromSize,
|
18
|
+
[overflowName]: 'hidden'
|
19
|
+
},
|
20
|
+
{
|
21
|
+
[sizeName]: toSize,
|
22
|
+
offset: 0.9999,
|
23
|
+
[overflowName]: 'hidden'
|
24
|
+
},
|
25
|
+
{
|
26
|
+
[sizeName]: 'unset',
|
27
|
+
[overflowName]: 'unset'
|
28
|
+
}
|
29
|
+
],
|
30
|
+
duration: enterDuration,
|
31
|
+
easing: enterEasing
|
32
|
+
}
|
33
|
+
];
|
34
|
+
// Fade in only if animateOpacity is true. Otherwise, leave opacity unaffected.
|
35
|
+
if (animateOpacity) {
|
36
|
+
enterAtoms.push({
|
37
|
+
keyframes: [
|
38
|
+
{
|
39
|
+
opacity: fromOpacity
|
40
|
+
},
|
41
|
+
{
|
42
|
+
opacity: toOpacity
|
43
|
+
}
|
44
|
+
],
|
45
|
+
duration: enterDuration,
|
46
|
+
easing: enterEasing,
|
47
|
+
fill: 'both'
|
48
|
+
});
|
29
49
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
easing,
|
47
|
-
keyframes: enterKeyframes
|
48
|
-
},
|
49
|
-
exit: {
|
50
|
-
duration,
|
51
|
-
easing,
|
52
|
-
keyframes: exitKeyframes
|
50
|
+
// The exit transition is an array of up to 2 motion atoms: opacity and size.
|
51
|
+
const exitAtoms = [];
|
52
|
+
// Fade out only if animateOpacity is false. Otherwise, leave opacity unaffected.
|
53
|
+
if (animateOpacity) {
|
54
|
+
exitAtoms.push({
|
55
|
+
keyframes: [
|
56
|
+
{
|
57
|
+
opacity: toOpacity
|
58
|
+
},
|
59
|
+
{
|
60
|
+
opacity: fromOpacity
|
61
|
+
}
|
62
|
+
],
|
63
|
+
duration: exitDuration,
|
64
|
+
easing: exitEasing
|
65
|
+
});
|
53
66
|
}
|
67
|
+
exitAtoms.push(// Collapse size (height or width)
|
68
|
+
{
|
69
|
+
keyframes: [
|
70
|
+
{
|
71
|
+
[sizeName]: toSize,
|
72
|
+
[overflowName]: 'hidden'
|
73
|
+
},
|
74
|
+
{
|
75
|
+
[sizeName]: fromSize,
|
76
|
+
[overflowName]: 'hidden'
|
77
|
+
}
|
78
|
+
],
|
79
|
+
duration: exitDuration,
|
80
|
+
easing: exitEasing,
|
81
|
+
fill: 'both'
|
82
|
+
});
|
83
|
+
return {
|
84
|
+
enter: enterAtoms,
|
85
|
+
exit: exitAtoms
|
86
|
+
};
|
54
87
|
};
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
});
|
62
|
-
export const CollapseExaggerated = createPresenceComponentVariant(Collapse, {
|
63
|
-
enter: {
|
64
|
-
duration: motionTokens.durationSlow,
|
65
|
-
easing: motionTokens.curveEasyEaseMax
|
66
|
-
},
|
67
|
-
exit: {
|
68
|
-
duration: motionTokens.durationNormal,
|
69
|
-
easing: motionTokens.curveEasyEaseMax
|
70
|
-
}
|
71
|
-
});
|
88
|
+
/** A React component that applies collapse/expand transitions to its children. */ export const Collapse = createPresenceComponent(createCollapsePresence());
|
89
|
+
export const CollapseSnappy = createPresenceComponent(createCollapsePresence({
|
90
|
+
enterDuration: motionTokens.durationFast
|
91
|
+
}));
|
92
|
+
export const CollapseExaggerated = createPresenceComponent(createCollapsePresence({
|
93
|
+
enterDuration: motionTokens.durationSlower
|
94
|
+
}));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Collapse.ts"],"sourcesContent":["import {\n
|
1
|
+
{"version":3,"sources":["Collapse.ts"],"sourcesContent":["import { motionTokens, createPresenceComponent, AtomMotion } from '@fluentui/react-motion';\nimport type { PresenceMotionFnCreator } from '../../types';\n\ntype CollapseOrientation = 'horizontal' | 'vertical';\n\ntype CollapseVariantParams = {\n /** Time (ms) for the enter transition (expand). Defaults to the `durationNormal` value (200 ms). */\n enterDuration?: number;\n\n /** Easing curve for the enter transition (expand). Defaults to the `easeEaseMax` value. */\n enterEasing?: string;\n\n /** Time (ms) for the exit transition (collapse). Defaults to the `enterDuration` param for symmetry. */\n exitDuration?: number;\n\n /** Easing curve for the exit transition (collapse). Defaults to the `enterEasing` param for symmetry. */\n exitEasing?: string;\n};\n\ntype CollapseRuntimeParams = {\n /** Whether to animate the opacity. Defaults to `true`. */\n animateOpacity?: boolean;\n\n /** The orientation of the size animation. Defaults to `'vertical'` to expand/collapse the height. */\n orientation?: CollapseOrientation;\n};\n\n/** Define a presence motion for collapse/expand */\nexport const createCollapsePresence: PresenceMotionFnCreator<CollapseVariantParams, CollapseRuntimeParams> =\n ({\n enterDuration = motionTokens.durationNormal,\n enterEasing = motionTokens.curveEasyEaseMax,\n exitDuration = enterDuration,\n exitEasing = enterEasing,\n } = {}) =>\n ({ element, animateOpacity = true, orientation = 'vertical' }) => {\n const fromOpacity = 0;\n const toOpacity = 1;\n const fromSize = '0'; // Could be a custom param in the future to start with partially expanded width or height\n const measuredSize = orientation === 'horizontal' ? element.scrollWidth : element.scrollHeight;\n const toSize = `${measuredSize}px`;\n // use generic names for size and overflow, handling vertical or horizontal orientation\n const sizeName = orientation === 'horizontal' ? 'maxWidth' : 'maxHeight';\n const overflowName = orientation === 'horizontal' ? 'overflowX' : 'overflowY';\n\n // The enter transition is an array of up to 2 motion atoms: size and opacity.\n const enterAtoms: AtomMotion[] = [\n // Expand size (height or width)\n {\n keyframes: [\n {\n [sizeName]: fromSize,\n [overflowName]: 'hidden',\n },\n { [sizeName]: toSize, offset: 0.9999, [overflowName]: 'hidden' },\n { [sizeName]: 'unset', [overflowName]: 'unset' },\n ],\n duration: enterDuration,\n easing: enterEasing,\n },\n ];\n // Fade in only if animateOpacity is true. Otherwise, leave opacity unaffected.\n if (animateOpacity) {\n enterAtoms.push({\n keyframes: [{ opacity: fromOpacity }, { opacity: toOpacity }],\n duration: enterDuration,\n easing: enterEasing,\n fill: 'both',\n });\n }\n\n // The exit transition is an array of up to 2 motion atoms: opacity and size.\n const exitAtoms: AtomMotion[] = [];\n // Fade out only if animateOpacity is false. Otherwise, leave opacity unaffected.\n if (animateOpacity) {\n exitAtoms.push({\n keyframes: [{ opacity: toOpacity }, { opacity: fromOpacity }],\n duration: exitDuration,\n easing: exitEasing,\n });\n }\n exitAtoms.push(\n // Collapse size (height or width)\n {\n keyframes: [\n { [sizeName]: toSize, [overflowName]: 'hidden' },\n { [sizeName]: fromSize, [overflowName]: 'hidden' },\n ],\n duration: exitDuration,\n easing: exitEasing,\n fill: 'both',\n },\n );\n\n return {\n enter: enterAtoms,\n exit: exitAtoms,\n };\n };\n\n/** A React component that applies collapse/expand transitions to its children. */\nexport const Collapse = createPresenceComponent(createCollapsePresence());\n\nexport const CollapseSnappy = createPresenceComponent(\n createCollapsePresence({ enterDuration: motionTokens.durationFast }),\n);\n\nexport const CollapseExaggerated = createPresenceComponent(\n createCollapsePresence({ enterDuration: motionTokens.durationSlower }),\n);\n"],"names":["motionTokens","createPresenceComponent","createCollapsePresence","enterDuration","durationNormal","enterEasing","curveEasyEaseMax","exitDuration","exitEasing","element","animateOpacity","orientation","fromOpacity","toOpacity","fromSize","measuredSize","scrollWidth","scrollHeight","toSize","sizeName","overflowName","enterAtoms","keyframes","offset","duration","easing","push","opacity","fill","exitAtoms","enter","exit","Collapse","CollapseSnappy","durationFast","CollapseExaggerated","durationSlower"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,YAAY,EAAEC,uBAAuB,QAAoB,yBAAyB;AA2B3F,iDAAiD,GACjD,OAAO,MAAMC,yBACX,CAAC,EACCC,gBAAgBH,aAAaI,cAAc,EAC3CC,cAAcL,aAAaM,gBAAgB,EAC3CC,eAAeJ,aAAa,EAC5BK,aAAaH,WAAW,EACzB,GAAG,CAAC,CAAC,GACN,CAAC,EAAEI,OAAO,EAAEC,iBAAiB,IAAI,EAAEC,cAAc,UAAU,EAAE;QAC3D,MAAMC,cAAc;QACpB,MAAMC,YAAY;QAClB,MAAMC,WAAW,KAAK,yFAAyF;QAC/G,MAAMC,eAAeJ,gBAAgB,eAAeF,QAAQO,WAAW,GAAGP,QAAQQ,YAAY;QAC9F,MAAMC,SAAS,CAAC,EAAEH,aAAa,EAAE,CAAC;QAClC,uFAAuF;QACvF,MAAMI,WAAWR,gBAAgB,eAAe,aAAa;QAC7D,MAAMS,eAAeT,gBAAgB,eAAe,cAAc;QAElE,8EAA8E;QAC9E,MAAMU,aAA2B;YAC/B,gCAAgC;YAChC;g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IACpE"}
|
package/lib/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export { Collapse, CollapseSnappy, CollapseExaggerated } from './components/Collapse';
|
1
|
+
export { Collapse, CollapseSnappy, CollapseExaggerated, createCollapsePresence } from './components/Collapse';
|
2
2
|
export { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';
|
3
3
|
export { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export { Collapse, CollapseSnappy, CollapseExaggerated } from './components/Collapse';\nexport { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';\n"],"names":["Collapse","CollapseSnappy","CollapseExaggerated","Fade","FadeSnappy","FadeExaggerated","Scale","ScaleSnappy","ScaleExaggerated"],"rangeMappings":";;","mappings":"AAAA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,mBAAmB,QAAQ,wBAAwB;
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export { Collapse, CollapseSnappy, CollapseExaggerated, createCollapsePresence } from './components/Collapse';\nexport { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';\n"],"names":["Collapse","CollapseSnappy","CollapseExaggerated","createCollapsePresence","Fade","FadeSnappy","FadeExaggerated","Scale","ScaleSnappy","ScaleExaggerated"],"rangeMappings":";;","mappings":"AAAA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,sBAAsB,QAAQ,wBAAwB;AAC9G,SAASC,IAAI,EAAEC,UAAU,EAAEC,eAAe,QAAQ,oBAAoB;AACtE,SAASC,KAAK,EAAEC,WAAW,EAAEC,gBAAgB,QAAQ,qBAAqB"}
|
package/lib/types.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* This is a factory function that generates a motion function, which has variant params bound into it.
|
3
|
+
* The generated motion function accepts other runtime params that aren't locked into the variant, but supplied at runtime.
|
4
|
+
* This separation allows the variant to be defined once and reused with different runtime params which may be orthogonal to the variant params.
|
5
|
+
* For example, a variant may define the duration and easing of a transition, which are fixed for all instances of the variant,
|
6
|
+
* while the runtime params may give access to the target element, which is different for each instance.
|
7
|
+
*
|
8
|
+
* The generated motion function is also framework-independent, i.e. non-React.
|
9
|
+
* It can be turned into a React component using `createPresenceComponent`.
|
10
|
+
*/ // TODO: move to @fluentui/react-motion when stable
|
11
|
+
export { };
|
package/lib/types.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["import type { MotionParam, PresenceMotionFn } from '@fluentui/react-motion';\n\n/**\n * This is a factory function that generates a motion function, which has variant params bound into it.\n * The generated motion function accepts other runtime params that aren't locked into the variant, but supplied at runtime.\n * This separation allows the variant to be defined once and reused with different runtime params which may be orthogonal to the variant params.\n * For example, a variant may define the duration and easing of a transition, which are fixed for all instances of the variant,\n * while the runtime params may give access to the target element, which is different for each instance.\n *\n * The generated motion function is also framework-independent, i.e. non-React.\n * It can be turned into a React component using `createPresenceComponent`.\n */\n// TODO: move to @fluentui/react-motion when stable\nexport type PresenceMotionFnCreator<\n MotionVariantParams extends Record<string, MotionParam> = {},\n MotionRuntimeParams extends Record<string, MotionParam> = {},\n> = (variantParams?: MotionVariantParams) => PresenceMotionFn<MotionRuntimeParams>;\n"],"names":[],"rangeMappings":";;;;;;;;;;","mappings":"AAEA;;;;;;;;;CASC,GACD,mDAAmD;AACnD,WAGmF"}
|
@@ -17,76 +17,101 @@ _export(exports, {
|
|
17
17
|
},
|
18
18
|
CollapseSnappy: function() {
|
19
19
|
return CollapseSnappy;
|
20
|
+
},
|
21
|
+
createCollapsePresence: function() {
|
22
|
+
return createCollapsePresence;
|
20
23
|
}
|
21
24
|
});
|
22
25
|
const _reactmotion = require("@fluentui/react-motion");
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
26
|
+
const createCollapsePresence = ({ enterDuration = _reactmotion.motionTokens.durationNormal, enterEasing = _reactmotion.motionTokens.curveEasyEaseMax, exitDuration = enterDuration, exitEasing = enterEasing } = {})=>({ element, animateOpacity = true, orientation = 'vertical' })=>{
|
27
|
+
const fromOpacity = 0;
|
28
|
+
const toOpacity = 1;
|
29
|
+
const fromSize = '0'; // Could be a custom param in the future to start with partially expanded width or height
|
30
|
+
const measuredSize = orientation === 'horizontal' ? element.scrollWidth : element.scrollHeight;
|
31
|
+
const toSize = `${measuredSize}px`;
|
32
|
+
// use generic names for size and overflow, handling vertical or horizontal orientation
|
33
|
+
const sizeName = orientation === 'horizontal' ? 'maxWidth' : 'maxHeight';
|
34
|
+
const overflowName = orientation === 'horizontal' ? 'overflowX' : 'overflowY';
|
35
|
+
// The enter transition is an array of up to 2 motion atoms: size and opacity.
|
36
|
+
const enterAtoms = [
|
37
|
+
// Expand size (height or width)
|
38
|
+
{
|
39
|
+
keyframes: [
|
40
|
+
{
|
41
|
+
[sizeName]: fromSize,
|
42
|
+
[overflowName]: 'hidden'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
[sizeName]: toSize,
|
46
|
+
offset: 0.9999,
|
47
|
+
[overflowName]: 'hidden'
|
48
|
+
},
|
49
|
+
{
|
50
|
+
[sizeName]: 'unset',
|
51
|
+
[overflowName]: 'unset'
|
52
|
+
}
|
53
|
+
],
|
54
|
+
duration: enterDuration,
|
55
|
+
easing: enterEasing
|
56
|
+
}
|
57
|
+
];
|
58
|
+
// Fade in only if animateOpacity is true. Otherwise, leave opacity unaffected.
|
59
|
+
if (animateOpacity) {
|
60
|
+
enterAtoms.push({
|
61
|
+
keyframes: [
|
62
|
+
{
|
63
|
+
opacity: fromOpacity
|
64
|
+
},
|
65
|
+
{
|
66
|
+
opacity: toOpacity
|
67
|
+
}
|
68
|
+
],
|
69
|
+
duration: enterDuration,
|
70
|
+
easing: enterEasing,
|
71
|
+
fill: 'both'
|
72
|
+
});
|
62
73
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
// The exit transition is an array of up to 2 motion atoms: opacity and size.
|
75
|
+
const exitAtoms = [];
|
76
|
+
// Fade out only if animateOpacity is false. Otherwise, leave opacity unaffected.
|
77
|
+
if (animateOpacity) {
|
78
|
+
exitAtoms.push({
|
79
|
+
keyframes: [
|
80
|
+
{
|
81
|
+
opacity: toOpacity
|
82
|
+
},
|
83
|
+
{
|
84
|
+
opacity: fromOpacity
|
85
|
+
}
|
86
|
+
],
|
87
|
+
duration: exitDuration,
|
88
|
+
easing: exitEasing
|
89
|
+
});
|
74
90
|
}
|
91
|
+
exitAtoms.push({
|
92
|
+
keyframes: [
|
93
|
+
{
|
94
|
+
[sizeName]: toSize,
|
95
|
+
[overflowName]: 'hidden'
|
96
|
+
},
|
97
|
+
{
|
98
|
+
[sizeName]: fromSize,
|
99
|
+
[overflowName]: 'hidden'
|
100
|
+
}
|
101
|
+
],
|
102
|
+
duration: exitDuration,
|
103
|
+
easing: exitEasing,
|
104
|
+
fill: 'both'
|
105
|
+
});
|
106
|
+
return {
|
107
|
+
enter: enterAtoms,
|
108
|
+
exit: exitAtoms
|
109
|
+
};
|
75
110
|
};
|
76
|
-
|
77
|
-
const
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
});
|
83
|
-
const CollapseExaggerated = (0, _reactmotion.createPresenceComponentVariant)(Collapse, {
|
84
|
-
enter: {
|
85
|
-
duration: _reactmotion.motionTokens.durationSlow,
|
86
|
-
easing: _reactmotion.motionTokens.curveEasyEaseMax
|
87
|
-
},
|
88
|
-
exit: {
|
89
|
-
duration: _reactmotion.motionTokens.durationNormal,
|
90
|
-
easing: _reactmotion.motionTokens.curveEasyEaseMax
|
91
|
-
}
|
92
|
-
});
|
111
|
+
const Collapse = (0, _reactmotion.createPresenceComponent)(createCollapsePresence());
|
112
|
+
const CollapseSnappy = (0, _reactmotion.createPresenceComponent)(createCollapsePresence({
|
113
|
+
enterDuration: _reactmotion.motionTokens.durationFast
|
114
|
+
}));
|
115
|
+
const CollapseExaggerated = (0, _reactmotion.createPresenceComponent)(createCollapsePresence({
|
116
|
+
enterDuration: _reactmotion.motionTokens.durationSlower
|
117
|
+
}));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Collapse.ts"],"sourcesContent":["import {\n
|
1
|
+
{"version":3,"sources":["Collapse.ts"],"sourcesContent":["import { motionTokens, createPresenceComponent, AtomMotion } from '@fluentui/react-motion';\nimport type { PresenceMotionFnCreator } from '../../types';\n\ntype CollapseOrientation = 'horizontal' | 'vertical';\n\ntype CollapseVariantParams = {\n /** Time (ms) for the enter transition (expand). Defaults to the `durationNormal` value (200 ms). */\n enterDuration?: number;\n\n /** Easing curve for the enter transition (expand). Defaults to the `easeEaseMax` value. */\n enterEasing?: string;\n\n /** Time (ms) for the exit transition (collapse). Defaults to the `enterDuration` param for symmetry. */\n exitDuration?: number;\n\n /** Easing curve for the exit transition (collapse). Defaults to the `enterEasing` param for symmetry. */\n exitEasing?: string;\n};\n\ntype CollapseRuntimeParams = {\n /** Whether to animate the opacity. Defaults to `true`. */\n animateOpacity?: boolean;\n\n /** The orientation of the size animation. Defaults to `'vertical'` to expand/collapse the height. */\n orientation?: CollapseOrientation;\n};\n\n/** Define a presence motion for collapse/expand */\nexport const createCollapsePresence: PresenceMotionFnCreator<CollapseVariantParams, CollapseRuntimeParams> =\n ({\n enterDuration = motionTokens.durationNormal,\n enterEasing = motionTokens.curveEasyEaseMax,\n exitDuration = enterDuration,\n exitEasing = enterEasing,\n } = {}) =>\n ({ element, animateOpacity = true, orientation = 'vertical' }) => {\n const fromOpacity = 0;\n const toOpacity = 1;\n const fromSize = '0'; // Could be a custom param in the future to start with partially expanded width or height\n const measuredSize = orientation === 'horizontal' ? element.scrollWidth : element.scrollHeight;\n const toSize = `${measuredSize}px`;\n // use generic names for size and overflow, handling vertical or horizontal orientation\n const sizeName = orientation === 'horizontal' ? 'maxWidth' : 'maxHeight';\n const overflowName = orientation === 'horizontal' ? 'overflowX' : 'overflowY';\n\n // The enter transition is an array of up to 2 motion atoms: size and opacity.\n const enterAtoms: AtomMotion[] = [\n // Expand size (height or width)\n {\n keyframes: [\n {\n [sizeName]: fromSize,\n [overflowName]: 'hidden',\n },\n { [sizeName]: toSize, offset: 0.9999, [overflowName]: 'hidden' },\n { [sizeName]: 'unset', [overflowName]: 'unset' },\n ],\n duration: enterDuration,\n easing: enterEasing,\n },\n ];\n // Fade in only if animateOpacity is true. Otherwise, leave opacity unaffected.\n if (animateOpacity) {\n enterAtoms.push({\n keyframes: [{ opacity: fromOpacity }, { opacity: toOpacity }],\n duration: enterDuration,\n easing: enterEasing,\n fill: 'both',\n });\n }\n\n // The exit transition is an array of up to 2 motion atoms: opacity and size.\n const exitAtoms: AtomMotion[] = [];\n // Fade out only if animateOpacity is false. Otherwise, leave opacity unaffected.\n if (animateOpacity) {\n exitAtoms.push({\n keyframes: [{ opacity: toOpacity }, { opacity: fromOpacity }],\n duration: exitDuration,\n easing: exitEasing,\n });\n }\n exitAtoms.push(\n // Collapse size (height or width)\n {\n keyframes: [\n { [sizeName]: toSize, [overflowName]: 'hidden' },\n { [sizeName]: fromSize, [overflowName]: 'hidden' },\n ],\n duration: exitDuration,\n easing: exitEasing,\n fill: 'both',\n },\n );\n\n return {\n enter: enterAtoms,\n exit: exitAtoms,\n };\n };\n\n/** A React component that applies collapse/expand transitions to its children. */\nexport const Collapse = createPresenceComponent(createCollapsePresence());\n\nexport const CollapseSnappy = createPresenceComponent(\n createCollapsePresence({ enterDuration: motionTokens.durationFast }),\n);\n\nexport const CollapseExaggerated = createPresenceComponent(\n createCollapsePresence({ enterDuration: motionTokens.durationSlower }),\n);\n"],"names":["Collapse","CollapseExaggerated","CollapseSnappy","createCollapsePresence","enterDuration","motionTokens","durationNormal","enterEasing","curveEasyEaseMax","exitDuration","exitEasing","element","animateOpacity","orientation","fromOpacity","toOpacity","fromSize","measuredSize","scrollWidth","scrollHeight","toSize","sizeName","overflowName","enterAtoms","keyframes","offset","duration","easing","push","opacity","fill","exitAtoms","enter","exit","createPresenceComponent","durationFast","durationSlower"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAqGaA,QAAAA;eAAAA;;IAMAC,mBAAAA;eAAAA;;IAJAC,cAAAA;eAAAA;;IA3EAC,sBAAAA;eAAAA;;;6BA5BqD;AA4B3D,MAAMA,yBACX,CAAC,EACCC,gBAAgBC,yBAAAA,CAAaC,cAAc,EAC3CC,cAAcF,yBAAAA,CAAaG,gBAAgB,EAC3CC,eAAeL,aAAa,EAC5BM,aAAaH,WAAW,EACzB,GAAG,CAAC,CAAC,GACN,CAAC,EAAEI,OAAO,EAAEC,iBAAiB,IAAI,EAAEC,cAAc,UAAU,EAAE;QAC3D,MAAMC,cAAc;QACpB,MAAMC,YAAY;QAClB,MAAMC,WAAW,KAAK,yFAAyF;QAC/G,MAAMC,eAAeJ,gBAAgB,eAAeF,QAAQO,WAAW,GAAGP,QAAQQ,YAAY;QAC9F,MAAMC,SAAS,CAAC,EAAEH,aAAa,EAAE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EAC5B/B,uBAAuB;IAAEC,eAAeC,yBAAAA,CAAa8B,YAAY;AAAC;AAG7D,MAAMlC,sBAAsBiC,IAAAA,oCAAAA,EACjC/B,uBAAuB;IAAEC,eAAeC,yBAAAA,CAAa+B,cAAc;AAAC"}
|
package/lib-commonjs/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export { Collapse, CollapseSnappy, CollapseExaggerated } from './components/Collapse';\nexport { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';\n"],"names":["Collapse","CollapseExaggerated","CollapseSnappy","Fade","FadeExaggerated","FadeSnappy","Scale","ScaleExaggerated","ScaleSnappy"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export { Collapse, CollapseSnappy, CollapseExaggerated, createCollapsePresence } from './components/Collapse';\nexport { Fade, FadeSnappy, FadeExaggerated } from './components/Fade';\nexport { Scale, ScaleSnappy, ScaleExaggerated } from './components/Scale';\n"],"names":["Collapse","CollapseExaggerated","CollapseSnappy","Fade","FadeExaggerated","FadeSnappy","Scale","ScaleExaggerated","ScaleSnappy","createCollapsePresence"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAASA,QAAQ;eAARA,kBAAQ;;IAAkBC,mBAAmB;eAAnBA,6BAAmB;;IAAnCC,cAAc;eAAdA,wBAAc;;IACxBC,IAAI;eAAJA,UAAI;;IAAcC,eAAe;eAAfA,qBAAe;;IAA3BC,UAAU;eAAVA,gBAAU;;IAChBC,KAAK;eAALA,YAAK;;IAAeC,gBAAgB;eAAhBA,uBAAgB;;IAA7BC,WAAW;eAAXA,kBAAW;;IAF6BC,sBAAsB;eAAtBA,gCAAsB;;;0BAAQ;sBACpC;uBACG"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* This is a factory function that generates a motion function, which has variant params bound into it.
|
3
|
+
* The generated motion function accepts other runtime params that aren't locked into the variant, but supplied at runtime.
|
4
|
+
* This separation allows the variant to be defined once and reused with different runtime params which may be orthogonal to the variant params.
|
5
|
+
* For example, a variant may define the duration and easing of a transition, which are fixed for all instances of the variant,
|
6
|
+
* while the runtime params may give access to the target element, which is different for each instance.
|
7
|
+
*
|
8
|
+
* The generated motion function is also framework-independent, i.e. non-React.
|
9
|
+
* It can be turned into a React component using `createPresenceComponent`.
|
10
|
+
*/ // TODO: move to @fluentui/react-motion when stable
|
11
|
+
"use strict";
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
13
|
+
value: true
|
14
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["import type { MotionParam, PresenceMotionFn } from '@fluentui/react-motion';\n\n/**\n * This is a factory function that generates a motion function, which has variant params bound into it.\n * The generated motion function accepts other runtime params that aren't locked into the variant, but supplied at runtime.\n * This separation allows the variant to be defined once and reused with different runtime params which may be orthogonal to the variant params.\n * For example, a variant may define the duration and easing of a transition, which are fixed for all instances of the variant,\n * while the runtime params may give access to the target element, which is different for each instance.\n *\n * The generated motion function is also framework-independent, i.e. non-React.\n * It can be turned into a React component using `createPresenceComponent`.\n */\n// TODO: move to @fluentui/react-motion when stable\nexport type PresenceMotionFnCreator<\n MotionVariantParams extends Record<string, MotionParam> = {},\n MotionRuntimeParams extends Record<string, MotionParam> = {},\n> = (variantParams?: MotionVariantParams) => PresenceMotionFn<MotionRuntimeParams>;\n"],"names":[],"rangeMappings":";;;;;;;;;","mappings":"AAEA;;;;;;;;;CASC,GACD,mDAAmD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-motion-components-preview",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"description": "A preview package for Fluent UI motion components, providing a collection of components",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|