@fluentui/react-motion 0.0.0-nightly-20240607-0405.1
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 +171 -0
- package/LICENSE +15 -0
- package/README.md +5 -0
- package/dist/index.d.ts +144 -0
- package/lib/components/PresenceGroup.js +53 -0
- package/lib/components/PresenceGroup.js.map +1 -0
- package/lib/components/PresenceGroupItemProvider.js +25 -0
- package/lib/components/PresenceGroupItemProvider.js.map +1 -0
- package/lib/contexts/PresenceGroupChildContext.js +4 -0
- package/lib/contexts/PresenceGroupChildContext.js.map +1 -0
- package/lib/factories/createMotionComponent.js +41 -0
- package/lib/factories/createMotionComponent.js.map +1 -0
- package/lib/factories/createPresenceComponent.js +86 -0
- package/lib/factories/createPresenceComponent.js.map +1 -0
- package/lib/hooks/useIsReducedMotion.js +30 -0
- package/lib/hooks/useIsReducedMotion.js.map +1 -0
- package/lib/hooks/useMotionImperativeRef.js +22 -0
- package/lib/hooks/useMotionImperativeRef.js.map +1 -0
- package/lib/hooks/useMountedState.js +26 -0
- package/lib/hooks/useMountedState.js.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/motions/motionTokens.js +40 -0
- package/lib/motions/motionTokens.js.map +1 -0
- package/lib/types.js +1 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/animateAtoms.js +74 -0
- package/lib/utils/animateAtoms.js.map +1 -0
- package/lib/utils/getChildElement.js +18 -0
- package/lib/utils/getChildElement.js.map +1 -0
- package/lib/utils/groups/getChildMapping.js +20 -0
- package/lib/utils/groups/getChildMapping.js.map +1 -0
- package/lib/utils/groups/getNextChildMapping.js +30 -0
- package/lib/utils/groups/getNextChildMapping.js.map +1 -0
- package/lib/utils/groups/mergeChildMappings.js +39 -0
- package/lib/utils/groups/mergeChildMappings.js.map +1 -0
- package/lib/utils/groups/types.js +1 -0
- package/lib/utils/groups/types.js.map +1 -0
- package/lib-commonjs/components/PresenceGroup.js +64 -0
- package/lib-commonjs/components/PresenceGroup.js.map +1 -0
- package/lib-commonjs/components/PresenceGroupItemProvider.js +31 -0
- package/lib-commonjs/components/PresenceGroupItemProvider.js.map +1 -0
- package/lib-commonjs/contexts/PresenceGroupChildContext.js +13 -0
- package/lib-commonjs/contexts/PresenceGroupChildContext.js.map +1 -0
- package/lib-commonjs/factories/createMotionComponent.js +48 -0
- package/lib-commonjs/factories/createMotionComponent.js.map +1 -0
- package/lib-commonjs/factories/createPresenceComponent.js +96 -0
- package/lib-commonjs/factories/createPresenceComponent.js.map +1 -0
- package/lib-commonjs/hooks/useIsReducedMotion.js +40 -0
- package/lib-commonjs/hooks/useIsReducedMotion.js.map +1 -0
- package/lib-commonjs/hooks/useMotionImperativeRef.js +33 -0
- package/lib-commonjs/hooks/useMotionImperativeRef.js.map +1 -0
- package/lib-commonjs/hooks/useMountedState.js +34 -0
- package/lib-commonjs/hooks/useMountedState.js.map +1 -0
- package/lib-commonjs/index.js +34 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/motions/motionTokens.js +58 -0
- package/lib-commonjs/motions/motionTokens.js.map +1 -0
- package/lib-commonjs/types.js +4 -0
- package/lib-commonjs/types.js.map +1 -0
- package/lib-commonjs/utils/animateAtoms.js +84 -0
- package/lib-commonjs/utils/animateAtoms.js.map +1 -0
- package/lib-commonjs/utils/getChildElement.js +29 -0
- package/lib-commonjs/utils/getChildElement.js.map +1 -0
- package/lib-commonjs/utils/groups/getChildMapping.js +29 -0
- package/lib-commonjs/utils/groups/getChildMapping.js.map +1 -0
- package/lib-commonjs/utils/groups/getNextChildMapping.js +40 -0
- package/lib-commonjs/utils/groups/getNextChildMapping.js.map +1 -0
- package/lib-commonjs/utils/groups/mergeChildMappings.js +49 -0
- package/lib-commonjs/utils/groups/mergeChildMappings.js.map +1 -0
- package/lib-commonjs/utils/groups/types.js +6 -0
- package/lib-commonjs/utils/groups/types.js.map +1 -0
- package/package.json +60 -0
package/CHANGELOG.md
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
# Change Log - @fluentui/react-motion
|
2
|
+
|
3
|
+
This log was last generated on Fri, 07 Jun 2024 04:24:06 GMT and should not be manually modified.
|
4
|
+
|
5
|
+
<!-- Start content -->
|
6
|
+
|
7
|
+
## [0.0.0-nightly-20240607-0405.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-motion_v0.0.0-nightly-20240607-0405.1)
|
8
|
+
|
9
|
+
Fri, 07 Jun 2024 04:24:06 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motion_v9.0.0..@fluentui/react-motion_v0.0.0-nightly-20240607-0405.1)
|
11
|
+
|
12
|
+
### Changes
|
13
|
+
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
15
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20240607-0405.1 ([commit](https://github.com/microsoft/fluentui/commit/e219591328e69d0e326772cfeb1d5634636bb417) by beachball)
|
16
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20240607-0405.1 ([commit](https://github.com/microsoft/fluentui/commit/e219591328e69d0e326772cfeb1d5634636bb417) by beachball)
|
17
|
+
- Bump @fluentui/react-conformance to v0.0.0-nightly-20240607-0405.1 ([commit](https://github.com/microsoft/fluentui/commit/e219591328e69d0e326772cfeb1d5634636bb417) by beachball)
|
18
|
+
- Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20240607-0405.1 ([commit](https://github.com/microsoft/fluentui/commit/e219591328e69d0e326772cfeb1d5634636bb417) by beachball)
|
19
|
+
|
20
|
+
## [9.0.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-motion_v9.0.0)
|
21
|
+
|
22
|
+
Thu, 06 Jun 2024 15:26:35 GMT
|
23
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.3.2..@fluentui/react-motion_v9.0.0)
|
24
|
+
|
25
|
+
### Minor changes
|
26
|
+
|
27
|
+
- feat: release stable ([PR #31574](https://github.com/microsoft/fluentui/pull/31574) by olfedias@microsoft.com)
|
28
|
+
- Bump @fluentui/react-utilities to v9.18.10 ([PR #31586](https://github.com/microsoft/fluentui/pull/31586) by beachball)
|
29
|
+
|
30
|
+
## [0.3.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.3.2)
|
31
|
+
|
32
|
+
Mon, 20 May 2024 12:44:59 GMT
|
33
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.3.1..@fluentui/react-motions-preview_v0.3.2)
|
34
|
+
|
35
|
+
### Patches
|
36
|
+
|
37
|
+
- chore(motions): add mock for .animate() calls ([PR #31390](https://github.com/microsoft/fluentui/pull/31390) by olfedias@microsoft.com)
|
38
|
+
- Bump @fluentui/react-shared-contexts to v9.19.0 ([PR #26682](https://github.com/microsoft/fluentui/pull/26682) by beachball)
|
39
|
+
- Bump @fluentui/react-utilities to v9.18.9 ([PR #26682](https://github.com/microsoft/fluentui/pull/26682) by beachball)
|
40
|
+
|
41
|
+
## [0.3.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.3.1)
|
42
|
+
|
43
|
+
Thu, 16 May 2024 09:25:16 GMT
|
44
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.3.0..@fluentui/react-motions-preview_v0.3.1)
|
45
|
+
|
46
|
+
### Patches
|
47
|
+
|
48
|
+
- fix(motions): use useFirstMount() in createPresenceComponent() ([PR #31379](https://github.com/microsoft/fluentui/pull/31379) by olfedias@microsoft.com)
|
49
|
+
|
50
|
+
## [0.3.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.3.0)
|
51
|
+
|
52
|
+
Thu, 09 May 2024 19:35:11 GMT
|
53
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.8..@fluentui/react-motions-preview_v0.3.0)
|
54
|
+
|
55
|
+
### Minor changes
|
56
|
+
|
57
|
+
- BREAKING: fix motion token values and adjust structure to match original source ([PR #31262](https://github.com/microsoft/fluentui/pull/31262) by robert@robertpenner.com)
|
58
|
+
|
59
|
+
## [0.2.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.8)
|
60
|
+
|
61
|
+
Mon, 06 May 2024 12:55:02 GMT
|
62
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.7..@fluentui/react-motions-preview_v0.2.8)
|
63
|
+
|
64
|
+
### Patches
|
65
|
+
|
66
|
+
- Bump @fluentui/react-shared-contexts to v9.18.0 ([PR #31271](https://github.com/microsoft/fluentui/pull/31271) by beachball)
|
67
|
+
- Bump @fluentui/react-utilities to v9.18.8 ([PR #31271](https://github.com/microsoft/fluentui/pull/31271) by beachball)
|
68
|
+
|
69
|
+
## [0.2.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.7)
|
70
|
+
|
71
|
+
Thu, 02 May 2024 11:36:35 GMT
|
72
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.6..@fluentui/react-motions-preview_v0.2.7)
|
73
|
+
|
74
|
+
### Patches
|
75
|
+
|
76
|
+
- fix(PresenceGroup): cleanup children properly ([PR #31175](https://github.com/microsoft/fluentui/pull/31175) by olfedias@microsoft.com)
|
77
|
+
- chore: improve state handling in createPresenceComponent() ([PR #31143](https://github.com/microsoft/fluentui/pull/31143) by olfedias@microsoft.com)
|
78
|
+
|
79
|
+
## [0.2.6](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.6)
|
80
|
+
|
81
|
+
Tue, 23 Apr 2024 08:17:49 GMT
|
82
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.5..@fluentui/react-motions-preview_v0.2.6)
|
83
|
+
|
84
|
+
### Patches
|
85
|
+
|
86
|
+
- Bump @fluentui/react-shared-contexts to v9.17.0 ([PR #31113](https://github.com/microsoft/fluentui/pull/31113) by beachball)
|
87
|
+
- Bump @fluentui/react-utilities to v9.18.7 ([PR #31113](https://github.com/microsoft/fluentui/pull/31113) by beachball)
|
88
|
+
|
89
|
+
## [0.2.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.5)
|
90
|
+
|
91
|
+
Tue, 02 Apr 2024 09:48:01 GMT
|
92
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.4..@fluentui/react-motions-preview_v0.2.5)
|
93
|
+
|
94
|
+
### Patches
|
95
|
+
|
96
|
+
- Bump @fluentui/react-shared-contexts to v9.16.0 ([PR #30644](https://github.com/microsoft/fluentui/pull/30644) by beachball)
|
97
|
+
- Bump @fluentui/react-utilities to v9.18.6 ([PR #30644](https://github.com/microsoft/fluentui/pull/30644) by beachball)
|
98
|
+
|
99
|
+
## [0.2.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.4)
|
100
|
+
|
101
|
+
Mon, 18 Mar 2024 19:50:46 GMT
|
102
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.3..@fluentui/react-motions-preview_v0.2.4)
|
103
|
+
|
104
|
+
### Patches
|
105
|
+
|
106
|
+
- Bump @fluentui/react-shared-contexts to v9.15.2 ([PR #30600](https://github.com/microsoft/fluentui/pull/30600) by beachball)
|
107
|
+
- Bump @fluentui/react-utilities to v9.18.5 ([PR #30600](https://github.com/microsoft/fluentui/pull/30600) by beachball)
|
108
|
+
|
109
|
+
## [0.2.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.3)
|
110
|
+
|
111
|
+
Fri, 15 Mar 2024 21:43:49 GMT
|
112
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.2..@fluentui/react-motions-preview_v0.2.3)
|
113
|
+
|
114
|
+
### Patches
|
115
|
+
|
116
|
+
- Bump @fluentui/react-shared-contexts to v9.15.1 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
117
|
+
- Bump @fluentui/react-utilities to v9.18.4 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
118
|
+
|
119
|
+
## [0.2.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.2)
|
120
|
+
|
121
|
+
Thu, 07 Mar 2024 19:33:27 GMT
|
122
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.1..@fluentui/react-motions-preview_v0.2.2)
|
123
|
+
|
124
|
+
### Patches
|
125
|
+
|
126
|
+
- Bump @fluentui/react-shared-contexts to v9.15.0 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
127
|
+
- Bump @fluentui/react-utilities to v9.18.3 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
128
|
+
|
129
|
+
## [0.2.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.1)
|
130
|
+
|
131
|
+
Wed, 28 Feb 2024 02:34:19 GMT
|
132
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.2.0..@fluentui/react-motions-preview_v0.2.1)
|
133
|
+
|
134
|
+
### Patches
|
135
|
+
|
136
|
+
- Bump @fluentui/react-shared-contexts to v9.14.1 ([PR #30639](https://github.com/microsoft/fluentui/pull/30639) by beachball)
|
137
|
+
- Bump @fluentui/react-utilities to v9.18.2 ([PR #30639](https://github.com/microsoft/fluentui/pull/30639) by beachball)
|
138
|
+
|
139
|
+
## [0.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.2.0)
|
140
|
+
|
141
|
+
Tue, 20 Feb 2024 14:22:22 GMT
|
142
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.1.1..@fluentui/react-motions-preview_v0.2.0)
|
143
|
+
|
144
|
+
### Minor changes
|
145
|
+
|
146
|
+
- BREAKING: rename createAtom() to createMotionComponent() & createPresence() to createPresenceMotion() ([PR #30550](https://github.com/microsoft/fluentui/pull/30550) by olfedias@microsoft.com)
|
147
|
+
- BREAKING: remove exports for atom & presence definitions ([PR #30548](https://github.com/microsoft/fluentui/pull/30548) by olfedias@microsoft.com)
|
148
|
+
- Bump @fluentui/react-utilities to v9.18.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
149
|
+
|
150
|
+
### Patches
|
151
|
+
|
152
|
+
- feat: add onMotionFinish() callback to createPresenceComponent() ([PR #30529](https://github.com/microsoft/fluentui/pull/30529) by olfedias@microsoft.com)
|
153
|
+
- feat: add PresenceGroup component ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by olfedias@microsoft.com)
|
154
|
+
|
155
|
+
## [0.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.1.1)
|
156
|
+
|
157
|
+
Tue, 30 Jan 2024 23:16:54 GMT
|
158
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-motions-preview_v0.1.0..@fluentui/react-motions-preview_v0.1.1)
|
159
|
+
|
160
|
+
### Patches
|
161
|
+
|
162
|
+
- Bump @fluentui/react-utilities to v9.18.0 ([PR #29983](https://github.com/microsoft/fluentui/pull/29983) by beachball)
|
163
|
+
|
164
|
+
## [0.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-motions-preview_v0.1.0)
|
165
|
+
|
166
|
+
Tue, 23 Jan 2024 15:10:59 GMT
|
167
|
+
|
168
|
+
### Minor changes
|
169
|
+
|
170
|
+
- chore: initial release ([PR #30359](https://github.com/microsoft/fluentui/pull/30359) by olfedias@microsoft.com)
|
171
|
+
- Bump @fluentui/react-utilities to v9.17.0 ([PR #30359](https://github.com/microsoft/fluentui/pull/30359) by beachball)
|
package/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
@fluentui/react-motions-preview
|
2
|
+
|
3
|
+
Copyright (c) Microsoft Corporation
|
4
|
+
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
MIT License
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
|
15
|
+
Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
|
package/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# @fluentui/react-motion
|
2
|
+
|
3
|
+
**React Motions components for [Fluent UI React](https://react.fluentui.dev/)**
|
4
|
+
|
5
|
+
These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release.
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
import * as React_2 from 'react';
|
2
|
+
|
3
|
+
export declare type AtomMotion = {
|
4
|
+
keyframes: Keyframe[];
|
5
|
+
} & KeyframeEffectOptions;
|
6
|
+
|
7
|
+
export declare type AtomMotionFn = (params: {
|
8
|
+
element: HTMLElement;
|
9
|
+
}) => AtomMotion | AtomMotion[];
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Creates a component that will animate the children using the provided motion.
|
13
|
+
*
|
14
|
+
* @param value - A motion definition.
|
15
|
+
*/
|
16
|
+
export declare function createMotionComponent(value: AtomMotion | AtomMotion[] | AtomMotionFn): React_2.FC<MotionComponentProps>;
|
17
|
+
|
18
|
+
export declare function createPresenceComponent(value: PresenceMotion | PresenceMotionFn): React_2.FC<PresenceComponentProps>;
|
19
|
+
|
20
|
+
export declare const curves: {
|
21
|
+
readonly curveAccelerateMax: "cubic-bezier(0.9,0.1,1,0.2)";
|
22
|
+
readonly curveAccelerateMid: "cubic-bezier(1,0,1,1)";
|
23
|
+
readonly curveAccelerateMin: "cubic-bezier(0.8,0,0.78,1)";
|
24
|
+
readonly curveDecelerateMax: "cubic-bezier(0.1,0.9,0.2,1)";
|
25
|
+
readonly curveDecelerateMid: "cubic-bezier(0,0,0,1)";
|
26
|
+
readonly curveDecelerateMin: "cubic-bezier(0.33,0,0.1,1)";
|
27
|
+
readonly curveEasyEaseMax: "cubic-bezier(0.8,0,0.2,1)";
|
28
|
+
readonly curveEasyEase: "cubic-bezier(0.33,0,0.67,1)";
|
29
|
+
readonly curveLinear: "cubic-bezier(0,0,1,1)";
|
30
|
+
};
|
31
|
+
|
32
|
+
export declare const durations: {
|
33
|
+
readonly durationUltraFast: 50;
|
34
|
+
readonly durationFaster: 100;
|
35
|
+
readonly durationFast: 150;
|
36
|
+
readonly durationNormal: 200;
|
37
|
+
readonly durationGentle: 250;
|
38
|
+
readonly durationSlow: 300;
|
39
|
+
readonly durationSlower: 400;
|
40
|
+
readonly durationUltraSlow: 500;
|
41
|
+
};
|
42
|
+
|
43
|
+
export declare type MotionComponentProps = {
|
44
|
+
children: React_2.ReactElement;
|
45
|
+
/** Provides imperative controls for the animation. */
|
46
|
+
imperativeRef?: React_2.Ref<MotionImperativeRef | undefined>;
|
47
|
+
};
|
48
|
+
|
49
|
+
export declare type MotionImperativeRef = {
|
50
|
+
/** Sets the playback rate of the animation, where 1 is normal speed. */
|
51
|
+
setPlaybackRate: (rate: number) => void;
|
52
|
+
/** Sets the state of the animation to running or paused. */
|
53
|
+
setPlayState: (state: 'running' | 'paused') => void;
|
54
|
+
};
|
55
|
+
|
56
|
+
export declare const motionTokens: {
|
57
|
+
curveAccelerateMax: "cubic-bezier(0.9,0.1,1,0.2)";
|
58
|
+
curveAccelerateMid: "cubic-bezier(1,0,1,1)";
|
59
|
+
curveAccelerateMin: "cubic-bezier(0.8,0,0.78,1)";
|
60
|
+
curveDecelerateMax: "cubic-bezier(0.1,0.9,0.2,1)";
|
61
|
+
curveDecelerateMid: "cubic-bezier(0,0,0,1)";
|
62
|
+
curveDecelerateMin: "cubic-bezier(0.33,0,0.1,1)";
|
63
|
+
curveEasyEaseMax: "cubic-bezier(0.8,0,0.2,1)";
|
64
|
+
curveEasyEase: "cubic-bezier(0.33,0,0.67,1)";
|
65
|
+
curveLinear: "cubic-bezier(0,0,1,1)";
|
66
|
+
durationUltraFast: 50;
|
67
|
+
durationFaster: 100;
|
68
|
+
durationFast: 150;
|
69
|
+
durationNormal: 200;
|
70
|
+
durationGentle: 250;
|
71
|
+
durationSlow: 300;
|
72
|
+
durationSlower: 400;
|
73
|
+
durationUltraSlow: 500;
|
74
|
+
};
|
75
|
+
|
76
|
+
export declare type PresenceComponentProps = {
|
77
|
+
/**
|
78
|
+
* By default, the child component won't execute the "enter" motion when it initially mounts, regardless of the value
|
79
|
+
* of "visible". If you desire this behavior, ensure both "appear" and "visible" are set to "true".
|
80
|
+
*/
|
81
|
+
appear?: boolean;
|
82
|
+
/** A React element that will be cloned and will have motion effects applied to it. */
|
83
|
+
children: React_2.ReactElement;
|
84
|
+
/** Provides imperative controls for the animation. */
|
85
|
+
imperativeRef?: React_2.Ref<MotionImperativeRef | undefined>;
|
86
|
+
/**
|
87
|
+
* Callback that is called when the whole motion finishes.
|
88
|
+
*
|
89
|
+
* A motion definition can contain multiple animations and therefore multiple "finish" events. The callback is
|
90
|
+
* triggered once all animations have finished with "null" instead of an event object to avoid ambiguity.
|
91
|
+
*/
|
92
|
+
onMotionFinish?: (ev: null, data: {
|
93
|
+
direction: 'enter' | 'exit';
|
94
|
+
}) => void;
|
95
|
+
/** Defines whether a component is visible; triggers the "enter" or "exit" motions. */
|
96
|
+
visible?: boolean;
|
97
|
+
/**
|
98
|
+
* By default, the child component remains mounted after it reaches the "finished" state. Set "unmountOnExit" if
|
99
|
+
* you prefer to unmount the component after it finishes exiting.
|
100
|
+
*/
|
101
|
+
unmountOnExit?: boolean;
|
102
|
+
};
|
103
|
+
|
104
|
+
export declare class PresenceGroup extends React_2.Component<PresenceGroupProps, PresenceGroupState> {
|
105
|
+
private mounted;
|
106
|
+
static getDerivedStateFromProps(nextProps: PresenceGroupProps, { childMapping: prevChildMapping, firstRender }: PresenceGroupState): {
|
107
|
+
childMapping: PresenceGroupChildMapping;
|
108
|
+
firstRender: boolean;
|
109
|
+
};
|
110
|
+
constructor(props: PresenceGroupProps, context: unknown);
|
111
|
+
private handleExit;
|
112
|
+
componentDidMount(): void;
|
113
|
+
componentWillUnmount(): void;
|
114
|
+
render(): JSX.Element;
|
115
|
+
}
|
116
|
+
|
117
|
+
declare type PresenceGroupChild = {
|
118
|
+
element: React_2.ReactElement;
|
119
|
+
appear: boolean;
|
120
|
+
visible: boolean;
|
121
|
+
unmountOnExit: boolean;
|
122
|
+
};
|
123
|
+
|
124
|
+
declare type PresenceGroupChildMapping = Record<string, PresenceGroupChild>;
|
125
|
+
|
126
|
+
declare type PresenceGroupProps = {
|
127
|
+
children: React_2.ReactNode;
|
128
|
+
};
|
129
|
+
|
130
|
+
declare type PresenceGroupState = {
|
131
|
+
childMapping: PresenceGroupChildMapping;
|
132
|
+
firstRender: boolean;
|
133
|
+
};
|
134
|
+
|
135
|
+
export declare type PresenceMotion = {
|
136
|
+
enter: AtomMotion | AtomMotion[];
|
137
|
+
exit: AtomMotion | AtomMotion[];
|
138
|
+
};
|
139
|
+
|
140
|
+
export declare type PresenceMotionFn = (params: {
|
141
|
+
element: HTMLElement;
|
142
|
+
}) => PresenceMotion;
|
143
|
+
|
144
|
+
export { }
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
2
|
+
import * as React from 'react';
|
3
|
+
import { getNextChildMapping } from '../utils/groups/getNextChildMapping';
|
4
|
+
import { getChildMapping } from '../utils/groups/getChildMapping';
|
5
|
+
import { PresenceGroupItemProvider } from './PresenceGroupItemProvider';
|
6
|
+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */ /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/member-ordering */ export class PresenceGroup extends React.Component {
|
7
|
+
static getDerivedStateFromProps(nextProps, { childMapping: prevChildMapping, firstRender }) {
|
8
|
+
const nextChildMapping = getChildMapping(nextProps.children);
|
9
|
+
return {
|
10
|
+
childMapping: firstRender ? nextChildMapping : getNextChildMapping(prevChildMapping, nextChildMapping),
|
11
|
+
firstRender: false
|
12
|
+
};
|
13
|
+
}
|
14
|
+
componentDidMount() {
|
15
|
+
this.mounted = true;
|
16
|
+
}
|
17
|
+
componentWillUnmount() {
|
18
|
+
this.mounted = false;
|
19
|
+
}
|
20
|
+
render() {
|
21
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, Object.entries(this.state.childMapping).map(([childKey, childProps])=>/*#__PURE__*/ React.createElement(PresenceGroupItemProvider, {
|
22
|
+
...childProps,
|
23
|
+
childKey: childKey,
|
24
|
+
key: childKey,
|
25
|
+
onExit: this.handleExit
|
26
|
+
}, childProps.element)));
|
27
|
+
}
|
28
|
+
constructor(props, context){
|
29
|
+
super(props, context);
|
30
|
+
_define_property(this, "mounted", false);
|
31
|
+
_define_property(this, "handleExit", (childKey)=>{
|
32
|
+
const currentChildMapping = getChildMapping(this.props.children);
|
33
|
+
if (childKey in currentChildMapping) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
if (this.mounted) {
|
37
|
+
this.setState((state)=>{
|
38
|
+
const childMapping = {
|
39
|
+
...state.childMapping
|
40
|
+
};
|
41
|
+
delete childMapping[childKey];
|
42
|
+
return {
|
43
|
+
childMapping
|
44
|
+
};
|
45
|
+
});
|
46
|
+
}
|
47
|
+
});
|
48
|
+
this.state = {
|
49
|
+
childMapping: {},
|
50
|
+
firstRender: true
|
51
|
+
};
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["PresenceGroup.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { getNextChildMapping } from '../utils/groups/getNextChildMapping';\nimport { getChildMapping } from '../utils/groups/getChildMapping';\nimport type { PresenceGroupChildMapping } from '../utils/groups/types';\nimport { PresenceGroupItemProvider } from './PresenceGroupItemProvider';\n\ntype PresenceGroupProps = {\n children: React.ReactNode;\n};\n\ntype PresenceGroupState = {\n childMapping: PresenceGroupChildMapping;\n firstRender: boolean;\n};\n\n/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n/* eslint-disable @typescript-eslint/naming-convention */\n/* eslint-disable @typescript-eslint/member-ordering */\n\nexport class PresenceGroup extends React.Component<PresenceGroupProps, PresenceGroupState> {\n private mounted: boolean = false;\n\n static getDerivedStateFromProps(\n nextProps: PresenceGroupProps,\n { childMapping: prevChildMapping, firstRender }: PresenceGroupState,\n ) {\n const nextChildMapping = getChildMapping(nextProps.children);\n\n return {\n childMapping: firstRender ? nextChildMapping : getNextChildMapping(prevChildMapping, nextChildMapping),\n firstRender: false,\n };\n }\n\n constructor(props: PresenceGroupProps, context: unknown) {\n super(props, context);\n\n this.state = {\n childMapping: {},\n firstRender: true,\n };\n }\n\n private handleExit = (childKey: string) => {\n const currentChildMapping = getChildMapping(this.props.children);\n\n if (childKey in currentChildMapping) {\n return;\n }\n\n if (this.mounted) {\n this.setState(state => {\n const childMapping = { ...state.childMapping };\n delete childMapping[childKey];\n\n return { childMapping };\n });\n }\n };\n\n componentDidMount() {\n this.mounted = true;\n }\n\n componentWillUnmount() {\n this.mounted = false;\n }\n\n render() {\n return (\n <>\n {Object.entries(this.state.childMapping).map(([childKey, childProps]) => (\n <PresenceGroupItemProvider {...childProps} childKey={childKey} key={childKey} onExit={this.handleExit}>\n {childProps.element}\n </PresenceGroupItemProvider>\n ))}\n </>\n );\n }\n}\n"],"names":["React","getNextChildMapping","getChildMapping","PresenceGroupItemProvider","PresenceGroup","Component","getDerivedStateFromProps","nextProps","childMapping","prevChildMapping","firstRender","nextChildMapping","children","componentDidMount","mounted","componentWillUnmount","render","Object","entries","state","map","childKey","childProps","key","onExit","handleExit","element","constructor","props","context","currentChildMapping","setState"],"mappings":";AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,mBAAmB,QAAQ,sCAAsC;AAC1E,SAASC,eAAe,QAAQ,kCAAkC;AAElE,SAASC,yBAAyB,QAAQ,8BAA8B;AAWxE,mEAAmE,GACnE,uDAAuD,GACvD,qDAAqD,GAErD,OAAO,MAAMC,sBAAsBJ,MAAMK,SAAS;IAGhD,OAAOC,yBACLC,SAA6B,EAC7B,EAAEC,cAAcC,gBAAgB,EAAEC,WAAW,EAAsB,EACnE;QACA,MAAMC,mBAAmBT,gBAAgBK,UAAUK,QAAQ;QAE3D,OAAO;YACLJ,cAAcE,cAAcC,mBAAmBV,oBAAoBQ,kBAAkBE;YACrFD,aAAa;QACf;IACF;IA4BAG,oBAAoB;QAClB,IAAI,CAACC,OAAO,GAAG;IACjB;IAEAC,uBAAuB;QACrB,IAAI,CAACD,OAAO,GAAG;IACjB;IAEAE,SAAS;QACP,qBACE,0CACGC,OAAOC,OAAO,CAAC,IAAI,CAACC,KAAK,CAACX,YAAY,EAAEY,GAAG,CAAC,CAAC,CAACC,UAAUC,WAAW,iBAClE,oBAACnB;gBAA2B,GAAGmB,UAAU;gBAAED,UAAUA;gBAAUE,KAAKF;gBAAUG,QAAQ,IAAI,CAACC,UAAU;eAClGH,WAAWI,OAAO;IAK7B;IA5CAC,YAAYC,KAAyB,EAAEC,OAAgB,CAAE;QACvD,KAAK,CAACD,OAAOC;QAff,uBAAQf,WAAmB;QAuB3B,uBAAQW,cAAa,CAACJ;YACpB,MAAMS,sBAAsB5B,gBAAgB,IAAI,CAAC0B,KAAK,CAAChB,QAAQ;YAE/D,IAAIS,YAAYS,qBAAqB;gBACnC;YACF;YAEA,IAAI,IAAI,CAAChB,OAAO,EAAE;gBAChB,IAAI,CAACiB,QAAQ,CAACZ,CAAAA;oBACZ,MAAMX,eAAe;wBAAE,GAAGW,MAAMX,YAAY;oBAAC;oBAC7C,OAAOA,YAAY,CAACa,SAAS;oBAE7B,OAAO;wBAAEb;oBAAa;gBACxB;YACF;QACF;QArBE,IAAI,CAACW,KAAK,GAAG;YACXX,cAAc,CAAC;YACfE,aAAa;QACf;IACF;AAsCF"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { PresenceGroupChildContext } from '../contexts/PresenceGroupChildContext';
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
*
|
6
|
+
* Provides context for a single child of a `PresenceGroup`. Exists only to make a stable context value for a child.
|
7
|
+
* Not intended for direct use.
|
8
|
+
*/ export const PresenceGroupItemProvider = (props)=>{
|
9
|
+
const { appear, childKey, onExit, visible, unmountOnExit } = props;
|
10
|
+
const contextValue = React.useMemo(()=>({
|
11
|
+
appear,
|
12
|
+
visible,
|
13
|
+
onExit: ()=>onExit(childKey),
|
14
|
+
unmountOnExit
|
15
|
+
}), [
|
16
|
+
appear,
|
17
|
+
childKey,
|
18
|
+
onExit,
|
19
|
+
visible,
|
20
|
+
unmountOnExit
|
21
|
+
]);
|
22
|
+
return /*#__PURE__*/ React.createElement(PresenceGroupChildContext.Provider, {
|
23
|
+
value: contextValue
|
24
|
+
}, props.children);
|
25
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["PresenceGroupItemProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { PresenceGroupChildContext } from '../contexts/PresenceGroupChildContext';\nimport type { PresenceGroupChildContextValue } from '../contexts/PresenceGroupChildContext';\n\ntype PresenceGroupItemProviderProps = Omit<PresenceGroupChildContextValue, 'onExit'> & {\n children: React.ReactElement;\n childKey: string;\n // That's an internal callback, so we don't need to enforce the type here\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onExit: (childKey: string) => void;\n};\n\n/**\n * @internal\n *\n * Provides context for a single child of a `PresenceGroup`. Exists only to make a stable context value for a child.\n * Not intended for direct use.\n */\nexport const PresenceGroupItemProvider: React.FC<PresenceGroupItemProviderProps> = props => {\n const { appear, childKey, onExit, visible, unmountOnExit } = props;\n const contextValue = React.useMemo(\n () => ({\n appear,\n visible,\n onExit: () => onExit(childKey),\n unmountOnExit,\n }),\n [appear, childKey, onExit, visible, unmountOnExit],\n );\n\n return <PresenceGroupChildContext.Provider value={contextValue}>{props.children}</PresenceGroupChildContext.Provider>;\n};\n"],"names":["React","PresenceGroupChildContext","PresenceGroupItemProvider","props","appear","childKey","onExit","visible","unmountOnExit","contextValue","useMemo","Provider","value","children"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,yBAAyB,QAAQ,wCAAwC;AAWlF;;;;;CAKC,GACD,OAAO,MAAMC,4BAAsEC,CAAAA;IACjF,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGL;IAC7D,MAAMM,eAAeT,MAAMU,OAAO,CAChC,IAAO,CAAA;YACLN;YACAG;YACAD,QAAQ,IAAMA,OAAOD;YACrBG;QACF,CAAA,GACA;QAACJ;QAAQC;QAAUC;QAAQC;QAASC;KAAc;IAGpD,qBAAO,oBAACP,0BAA0BU,QAAQ;QAACC,OAAOH;OAAeN,MAAMU,QAAQ;AACjF,EAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["PresenceGroupChildContext.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type PresenceGroupChildContextValue = {\n appear: boolean;\n visible: boolean;\n unmountOnExit: boolean;\n\n onExit: () => void;\n};\n\n/**\n * @internal\n */\nexport const PresenceGroupChildContext = React.createContext<PresenceGroupChildContextValue | undefined>(undefined);\n"],"names":["React","PresenceGroupChildContext","createContext","undefined"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAa/B;;CAEC,GACD,OAAO,MAAMC,4BAA4BD,MAAME,aAAa,CAA6CC,WAAW"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';
|
2
|
+
import * as React from 'react';
|
3
|
+
import { useIsReducedMotion } from '../hooks/useIsReducedMotion';
|
4
|
+
import { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';
|
5
|
+
import { animateAtoms } from '../utils/animateAtoms';
|
6
|
+
import { getChildElement } from '../utils/getChildElement';
|
7
|
+
/**
|
8
|
+
* Creates a component that will animate the children using the provided motion.
|
9
|
+
*
|
10
|
+
* @param value - A motion definition.
|
11
|
+
*/ export function createMotionComponent(value) {
|
12
|
+
const Atom = (props)=>{
|
13
|
+
const { children, imperativeRef } = props;
|
14
|
+
const child = getChildElement(children);
|
15
|
+
const handleRef = useMotionImperativeRef(imperativeRef);
|
16
|
+
const elementRef = React.useRef();
|
17
|
+
const isReducedMotion = useIsReducedMotion();
|
18
|
+
useIsomorphicLayoutEffect(()=>{
|
19
|
+
const element = elementRef.current;
|
20
|
+
if (element) {
|
21
|
+
const atoms = typeof value === 'function' ? value({
|
22
|
+
element
|
23
|
+
}) : value;
|
24
|
+
const handle = animateAtoms(element, atoms, {
|
25
|
+
isReducedMotion: isReducedMotion()
|
26
|
+
});
|
27
|
+
handleRef.current = handle;
|
28
|
+
return ()=>{
|
29
|
+
handle.cancel();
|
30
|
+
};
|
31
|
+
}
|
32
|
+
}, [
|
33
|
+
handleRef,
|
34
|
+
isReducedMotion
|
35
|
+
]);
|
36
|
+
return React.cloneElement(children, {
|
37
|
+
ref: useMergedRefs(elementRef, child.ref)
|
38
|
+
});
|
39
|
+
};
|
40
|
+
return Atom;
|
41
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["createMotionComponent.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { useIsReducedMotion } from '../hooks/useIsReducedMotion';\nimport { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';\nimport { animateAtoms } from '../utils/animateAtoms';\nimport { getChildElement } from '../utils/getChildElement';\nimport type { AtomMotion, AtomMotionFn, MotionImperativeRef } from '../types';\n\nexport type MotionComponentProps = {\n children: React.ReactElement;\n\n /** Provides imperative controls for the animation. */\n imperativeRef?: React.Ref<MotionImperativeRef | undefined>;\n};\n\n/**\n * Creates a component that will animate the children using the provided motion.\n *\n * @param value - A motion definition.\n */\nexport function createMotionComponent(value: AtomMotion | AtomMotion[] | AtomMotionFn) {\n const Atom: React.FC<MotionComponentProps> = props => {\n const { children, imperativeRef } = props;\n const child = getChildElement(children);\n\n const handleRef = useMotionImperativeRef(imperativeRef);\n const elementRef = React.useRef<HTMLElement>();\n\n const isReducedMotion = useIsReducedMotion();\n\n useIsomorphicLayoutEffect(() => {\n const element = elementRef.current;\n\n if (element) {\n const atoms = typeof value === 'function' ? value({ element }) : value;\n const handle = animateAtoms(element, atoms, { isReducedMotion: isReducedMotion() });\n\n handleRef.current = handle;\n\n return () => {\n handle.cancel();\n };\n }\n }, [handleRef, isReducedMotion]);\n\n return React.cloneElement(children, { ref: useMergedRefs(elementRef, child.ref) });\n };\n\n return Atom;\n}\n"],"names":["useIsomorphicLayoutEffect","useMergedRefs","React","useIsReducedMotion","useMotionImperativeRef","animateAtoms","getChildElement","createMotionComponent","value","Atom","props","children","imperativeRef","child","handleRef","elementRef","useRef","isReducedMotion","element","current","atoms","handle","cancel","cloneElement","ref"],"mappings":"AAAA,SAASA,yBAAyB,EAAEC,aAAa,QAAQ,4BAA4B;AACrF,YAAYC,WAAW,QAAQ;AAE/B,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,sBAAsB,QAAQ,kCAAkC;AACzE,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,eAAe,QAAQ,2BAA2B;AAU3D;;;;CAIC,GACD,OAAO,SAASC,sBAAsBC,KAA+C;IACnF,MAAMC,OAAuCC,CAAAA;QAC3C,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAE,GAAGF;QACpC,MAAMG,QAAQP,gBAAgBK;QAE9B,MAAMG,YAAYV,uBAAuBQ;QACzC,MAAMG,aAAab,MAAMc,MAAM;QAE/B,MAAMC,kBAAkBd;QAExBH,0BAA0B;YACxB,MAAMkB,UAAUH,WAAWI,OAAO;YAElC,IAAID,SAAS;gBACX,MAAME,QAAQ,OAAOZ,UAAU,aAAaA,MAAM;oBAAEU;gBAAQ,KAAKV;gBACjE,MAAMa,SAAShB,aAAaa,SAASE,OAAO;oBAAEH,iBAAiBA;gBAAkB;gBAEjFH,UAAUK,OAAO,GAAGE;gBAEpB,OAAO;oBACLA,OAAOC,MAAM;gBACf;YACF;QACF,GAAG;YAACR;YAAWG;SAAgB;QAE/B,OAAOf,MAAMqB,YAAY,CAACZ,UAAU;YAAEa,KAAKvB,cAAcc,YAAYF,MAAMW,GAAG;QAAE;IAClF;IAEA,OAAOf;AACT"}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { useEventCallback, useFirstMount, useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';
|
2
|
+
import * as React from 'react';
|
3
|
+
import { PresenceGroupChildContext } from '../contexts/PresenceGroupChildContext';
|
4
|
+
import { useIsReducedMotion } from '../hooks/useIsReducedMotion';
|
5
|
+
import { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';
|
6
|
+
import { useMountedState } from '../hooks/useMountedState';
|
7
|
+
import { animateAtoms } from '../utils/animateAtoms';
|
8
|
+
import { getChildElement } from '../utils/getChildElement';
|
9
|
+
function shouldSkipAnimation(appear, isFirstMount, visible) {
|
10
|
+
return !appear && isFirstMount && visible;
|
11
|
+
}
|
12
|
+
export function createPresenceComponent(value) {
|
13
|
+
const Presence = (props)=>{
|
14
|
+
const itemContext = React.useContext(PresenceGroupChildContext);
|
15
|
+
const { appear, children, imperativeRef, onMotionFinish, visible, unmountOnExit } = {
|
16
|
+
...itemContext,
|
17
|
+
...props
|
18
|
+
};
|
19
|
+
const [mounted, setMounted] = useMountedState(visible, unmountOnExit);
|
20
|
+
const child = getChildElement(children);
|
21
|
+
const handleRef = useMotionImperativeRef(imperativeRef);
|
22
|
+
const elementRef = React.useRef();
|
23
|
+
const ref = useMergedRefs(elementRef, child.ref);
|
24
|
+
const optionsRef = React.useRef({});
|
25
|
+
const isFirstMount = useFirstMount();
|
26
|
+
const isReducedMotion = useIsReducedMotion();
|
27
|
+
const onEnterFinish = useEventCallback(()=>{
|
28
|
+
onMotionFinish === null || onMotionFinish === void 0 ? void 0 : onMotionFinish(null, {
|
29
|
+
direction: 'enter'
|
30
|
+
});
|
31
|
+
});
|
32
|
+
const onExitFinish = useEventCallback(()=>{
|
33
|
+
onMotionFinish === null || onMotionFinish === void 0 ? void 0 : onMotionFinish(null, {
|
34
|
+
direction: 'exit'
|
35
|
+
});
|
36
|
+
if (unmountOnExit) {
|
37
|
+
setMounted(false);
|
38
|
+
itemContext === null || itemContext === void 0 ? void 0 : itemContext.onExit();
|
39
|
+
}
|
40
|
+
});
|
41
|
+
useIsomorphicLayoutEffect(()=>{
|
42
|
+
optionsRef.current = {
|
43
|
+
appear
|
44
|
+
};
|
45
|
+
});
|
46
|
+
useIsomorphicLayoutEffect(()=>{
|
47
|
+
const element = elementRef.current;
|
48
|
+
if (!element || shouldSkipAnimation(optionsRef.current.appear, isFirstMount, visible)) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
const presenceMotion = typeof value === 'function' ? value({
|
52
|
+
element
|
53
|
+
}) : value;
|
54
|
+
const atoms = visible ? presenceMotion.enter : presenceMotion.exit;
|
55
|
+
const handle = animateAtoms(element, atoms, {
|
56
|
+
isReducedMotion: isReducedMotion()
|
57
|
+
});
|
58
|
+
if (!visible && isFirstMount) {
|
59
|
+
// Heads up!
|
60
|
+
// .finish() is used there to skip animation on first mount, but apply animation styles immediately
|
61
|
+
handle.finish();
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
handleRef.current = handle;
|
65
|
+
handle.onfinish = visible ? onEnterFinish : onExitFinish;
|
66
|
+
return ()=>{
|
67
|
+
handle.cancel();
|
68
|
+
};
|
69
|
+
}, // Excluding `isFirstMount` from deps to prevent re-triggering the animation on subsequent renders
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
71
|
+
[
|
72
|
+
handleRef,
|
73
|
+
isReducedMotion,
|
74
|
+
onEnterFinish,
|
75
|
+
onExitFinish,
|
76
|
+
visible
|
77
|
+
]);
|
78
|
+
if (mounted) {
|
79
|
+
return React.cloneElement(child, {
|
80
|
+
ref
|
81
|
+
});
|
82
|
+
}
|
83
|
+
return null;
|
84
|
+
};
|
85
|
+
return Presence;
|
86
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["createPresenceComponent.ts"],"sourcesContent":["import { useEventCallback, useFirstMount, useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { PresenceGroupChildContext } from '../contexts/PresenceGroupChildContext';\nimport { useIsReducedMotion } from '../hooks/useIsReducedMotion';\nimport { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';\nimport { useMountedState } from '../hooks/useMountedState';\nimport { animateAtoms } from '../utils/animateAtoms';\nimport { getChildElement } from '../utils/getChildElement';\nimport type { PresenceMotion, MotionImperativeRef, PresenceMotionFn } from '../types';\n\nexport type PresenceComponentProps = {\n /**\n * By default, the child component won't execute the \"enter\" motion when it initially mounts, regardless of the value\n * of \"visible\". If you desire this behavior, ensure both \"appear\" and \"visible\" are set to \"true\".\n */\n appear?: boolean;\n\n /** A React element that will be cloned and will have motion effects applied to it. */\n children: React.ReactElement;\n\n /** Provides imperative controls for the animation. */\n imperativeRef?: React.Ref<MotionImperativeRef | undefined>;\n\n /**\n * Callback that is called when the whole motion finishes.\n *\n * A motion definition can contain multiple animations and therefore multiple \"finish\" events. The callback is\n * triggered once all animations have finished with \"null\" instead of an event object to avoid ambiguity.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionFinish?: (ev: null, data: { direction: 'enter' | 'exit' }) => void;\n\n /** Defines whether a component is visible; triggers the \"enter\" or \"exit\" motions. */\n visible?: boolean;\n\n /**\n * By default, the child component remains mounted after it reaches the \"finished\" state. Set \"unmountOnExit\" if\n * you prefer to unmount the component after it finishes exiting.\n */\n unmountOnExit?: boolean;\n};\n\nfunction shouldSkipAnimation(appear: boolean | undefined, isFirstMount: boolean, visible: boolean | undefined) {\n return !appear && isFirstMount && visible;\n}\n\nexport function createPresenceComponent(value: PresenceMotion | PresenceMotionFn) {\n const Presence: React.FC<PresenceComponentProps> = props => {\n const itemContext = React.useContext(PresenceGroupChildContext);\n const { appear, children, imperativeRef, onMotionFinish, visible, unmountOnExit } = { ...itemContext, ...props };\n\n const [mounted, setMounted] = useMountedState(visible, unmountOnExit);\n const child = getChildElement(children);\n\n const handleRef = useMotionImperativeRef(imperativeRef);\n const elementRef = React.useRef<HTMLElement>();\n const ref = useMergedRefs(elementRef, child.ref);\n const optionsRef = React.useRef<{ appear?: boolean }>({});\n\n const isFirstMount = useFirstMount();\n const isReducedMotion = useIsReducedMotion();\n\n const onEnterFinish = useEventCallback(() => {\n onMotionFinish?.(null, { direction: 'enter' });\n });\n const onExitFinish = useEventCallback(() => {\n onMotionFinish?.(null, { direction: 'exit' });\n\n if (unmountOnExit) {\n setMounted(false);\n itemContext?.onExit();\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n optionsRef.current = { appear };\n });\n\n useIsomorphicLayoutEffect(\n () => {\n const element = elementRef.current;\n\n if (!element || shouldSkipAnimation(optionsRef.current.appear, isFirstMount, visible)) {\n return;\n }\n\n const presenceMotion = typeof value === 'function' ? value({ element }) : value;\n const atoms = visible ? presenceMotion.enter : presenceMotion.exit;\n\n const handle = animateAtoms(element, atoms, { isReducedMotion: isReducedMotion() });\n\n if (!visible && isFirstMount) {\n // Heads up!\n // .finish() is used there to skip animation on first mount, but apply animation styles immediately\n handle.finish();\n return;\n }\n\n handleRef.current = handle;\n handle.onfinish = visible ? onEnterFinish : onExitFinish;\n\n return () => {\n handle.cancel();\n };\n },\n // Excluding `isFirstMount` from deps to prevent re-triggering the animation on subsequent renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [handleRef, isReducedMotion, onEnterFinish, onExitFinish, visible],\n );\n\n if (mounted) {\n return React.cloneElement(child, { ref });\n }\n\n return null;\n };\n\n return Presence;\n}\n"],"names":["useEventCallback","useFirstMount","useIsomorphicLayoutEffect","useMergedRefs","React","PresenceGroupChildContext","useIsReducedMotion","useMotionImperativeRef","useMountedState","animateAtoms","getChildElement","shouldSkipAnimation","appear","isFirstMount","visible","createPresenceComponent","value","Presence","props","itemContext","useContext","children","imperativeRef","onMotionFinish","unmountOnExit","mounted","setMounted","child","handleRef","elementRef","useRef","ref","optionsRef","isReducedMotion","onEnterFinish","direction","onExitFinish","onExit","current","element","presenceMotion","atoms","enter","exit","handle","finish","onfinish","cancel","cloneElement"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,aAAa,EAAEC,yBAAyB,EAAEC,aAAa,QAAQ,4BAA4B;AACtH,YAAYC,WAAW,QAAQ;AAE/B,SAASC,yBAAyB,QAAQ,wCAAwC;AAClF,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,sBAAsB,QAAQ,kCAAkC;AACzE,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,eAAe,QAAQ,2BAA2B;AAmC3D,SAASC,oBAAoBC,MAA2B,EAAEC,YAAqB,EAAEC,OAA4B;IAC3G,OAAO,CAACF,UAAUC,gBAAgBC;AACpC;AAEA,OAAO,SAASC,wBAAwBC,KAAwC;IAC9E,MAAMC,WAA6CC,CAAAA;QACjD,MAAMC,cAAcf,MAAMgB,UAAU,CAACf;QACrC,MAAM,EAAEO,MAAM,EAAES,QAAQ,EAAEC,aAAa,EAAEC,cAAc,EAAET,OAAO,EAAEU,aAAa,EAAE,GAAG;YAAE,GAAGL,WAAW;YAAE,GAAGD,KAAK;QAAC;QAE/G,MAAM,CAACO,SAASC,WAAW,GAAGlB,gBAAgBM,SAASU;QACvD,MAAMG,QAAQjB,gBAAgBW;QAE9B,MAAMO,YAAYrB,uBAAuBe;QACzC,MAAMO,aAAazB,MAAM0B,MAAM;QAC/B,MAAMC,MAAM5B,cAAc0B,YAAYF,MAAMI,GAAG;QAC/C,MAAMC,aAAa5B,MAAM0B,MAAM,CAAuB,CAAC;QAEvD,MAAMjB,eAAeZ;QACrB,MAAMgC,kBAAkB3B;QAExB,MAAM4B,gBAAgBlC,iBAAiB;YACrCuB,2BAAAA,qCAAAA,eAAiB,MAAM;gBAAEY,WAAW;YAAQ;QAC9C;QACA,MAAMC,eAAepC,iBAAiB;YACpCuB,2BAAAA,qCAAAA,eAAiB,MAAM;gBAAEY,WAAW;YAAO;YAE3C,IAAIX,eAAe;gBACjBE,WAAW;gBACXP,wBAAAA,kCAAAA,YAAakB,MAAM;YACrB;QACF;QAEAnC,0BAA0B;YACxB8B,WAAWM,OAAO,GAAG;gBAAE1B;YAAO;QAChC;QAEAV,0BACE;YACE,MAAMqC,UAAUV,WAAWS,OAAO;YAElC,IAAI,CAACC,WAAW5B,oBAAoBqB,WAAWM,OAAO,CAAC1B,MAAM,EAAEC,cAAcC,UAAU;gBACrF;YACF;YAEA,MAAM0B,iBAAiB,OAAOxB,UAAU,aAAaA,MAAM;gBAAEuB;YAAQ,KAAKvB;YAC1E,MAAMyB,QAAQ3B,UAAU0B,eAAeE,KAAK,GAAGF,eAAeG,IAAI;YAElE,MAAMC,SAASnC,aAAa8B,SAASE,OAAO;gBAAER,iBAAiBA;YAAkB;YAEjF,IAAI,CAACnB,WAAWD,cAAc;gBAC5B,YAAY;gBACZ,mGAAmG;gBACnG+B,OAAOC,MAAM;gBACb;YACF;YAEAjB,UAAUU,OAAO,GAAGM;YACpBA,OAAOE,QAAQ,GAAGhC,UAAUoB,gBAAgBE;YAE5C,OAAO;gBACLQ,OAAOG,MAAM;YACf;QACF,GACA,kGAAkG;QAClG,uDAAuD;QACvD;YAACnB;YAAWK;YAAiBC;YAAeE;YAActB;SAAQ;QAGpE,IAAIW,SAAS;YACX,OAAOrB,MAAM4C,YAAY,CAACrB,OAAO;gBAAEI;YAAI;QACzC;QAEA,OAAO;IACT;IAEA,OAAOd;AACT"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
|
+
const REDUCED_MEDIA_QUERY = 'screen and (prefers-reduced-motion: reduce)';
|
4
|
+
// TODO: find a better approach there as each hook creates a separate subscription
|
5
|
+
export function useIsReducedMotion() {
|
6
|
+
const { targetDocument } = useFluent();
|
7
|
+
var _targetDocument_defaultView;
|
8
|
+
const targetWindow = (_targetDocument_defaultView = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) !== null && _targetDocument_defaultView !== void 0 ? _targetDocument_defaultView : null;
|
9
|
+
const queryValue = React.useRef(false);
|
10
|
+
const isEnabled = React.useCallback(()=>queryValue.current, []);
|
11
|
+
React.useEffect(()=>{
|
12
|
+
if (targetWindow === null || typeof targetWindow.matchMedia !== 'function') {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
const queryMatch = targetWindow.matchMedia(REDUCED_MEDIA_QUERY);
|
16
|
+
if (queryMatch.matches) {
|
17
|
+
queryValue.current = true;
|
18
|
+
}
|
19
|
+
const matchListener = (e)=>{
|
20
|
+
queryValue.current = e.matches;
|
21
|
+
};
|
22
|
+
queryMatch.addEventListener('change', matchListener);
|
23
|
+
return ()=>{
|
24
|
+
queryMatch.removeEventListener('change', matchListener);
|
25
|
+
};
|
26
|
+
}, [
|
27
|
+
targetWindow
|
28
|
+
]);
|
29
|
+
return isEnabled;
|
30
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useIsReducedMotion.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst REDUCED_MEDIA_QUERY = 'screen and (prefers-reduced-motion: reduce)';\n\n// TODO: find a better approach there as each hook creates a separate subscription\n\nexport function useIsReducedMotion(): () => boolean {\n const { targetDocument } = useFluent();\n const targetWindow: Window | null = targetDocument?.defaultView ?? null;\n\n const queryValue = React.useRef<boolean>(false);\n const isEnabled = React.useCallback(() => queryValue.current, []);\n\n React.useEffect(() => {\n if (targetWindow === null || typeof targetWindow.matchMedia !== 'function') {\n return;\n }\n\n const queryMatch = targetWindow.matchMedia(REDUCED_MEDIA_QUERY);\n\n if (queryMatch.matches) {\n queryValue.current = true;\n }\n\n const matchListener = (e: MediaQueryListEvent) => {\n queryValue.current = e.matches;\n };\n\n queryMatch.addEventListener('change', matchListener);\n\n return () => {\n queryMatch.removeEventListener('change', matchListener);\n };\n }, [targetWindow]);\n\n return isEnabled;\n}\n"],"names":["React","useFluent_unstable","useFluent","REDUCED_MEDIA_QUERY","useIsReducedMotion","targetDocument","targetWindow","defaultView","queryValue","useRef","isEnabled","useCallback","current","useEffect","matchMedia","queryMatch","matches","matchListener","e","addEventListener","removeEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,MAAMC,sBAAsB;AAE5B,kFAAkF;AAElF,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGH;QACSG;IAApC,MAAMC,eAA8BD,CAAAA,8BAAAA,2BAAAA,qCAAAA,eAAgBE,WAAW,cAA3BF,yCAAAA,8BAA+B;IAEnE,MAAMG,aAAaR,MAAMS,MAAM,CAAU;IACzC,MAAMC,YAAYV,MAAMW,WAAW,CAAC,IAAMH,WAAWI,OAAO,EAAE,EAAE;IAEhEZ,MAAMa,SAAS,CAAC;QACd,IAAIP,iBAAiB,QAAQ,OAAOA,aAAaQ,UAAU,KAAK,YAAY;YAC1E;QACF;QAEA,MAAMC,aAAaT,aAAaQ,UAAU,CAACX;QAE3C,IAAIY,WAAWC,OAAO,EAAE;YACtBR,WAAWI,OAAO,GAAG;QACvB;QAEA,MAAMK,gBAAgB,CAACC;YACrBV,WAAWI,OAAO,GAAGM,EAAEF,OAAO;QAChC;QAEAD,WAAWI,gBAAgB,CAAC,UAAUF;QAEtC,OAAO;YACLF,WAAWK,mBAAmB,CAAC,UAAUH;QAC3C;IACF,GAAG;QAACX;KAAa;IAEjB,OAAOI;AACT"}
|