page-transition 0.1.0-beta.43 → 0.1.0-beta.45
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/README.md +27 -24
- package/dist/context/CssTransitionProvider.d.ts +1 -2
- package/dist/context/CssTransitionProvider.js +13 -14
- package/dist/context/TransitionContext.d.ts +1 -2
- package/dist/functions/parseDuration.d.ts +1 -1
- package/dist/functions/parseDuration.js +2 -3
- package/dist/functions/transitionEndReverse.js +5 -4
- package/dist/hooks/useHandleLinkClick.js +6 -3
- package/dist/hooks/usePopState.js +2 -2
- package/dist/hooks/useTransitionEndData.d.ts +2 -3
- package/dist/hooks/useTransitionEndData.js +3 -4
- package/dist/hooks/useTransitionEndObj.js +1 -2
- package/dist/types/transitionEnd.types.d.ts +2 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A page transition library for the Next.js App Router.
|
|
|
10
10
|
- Scroll restoration
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
|
-
 
|
|
14
14
|
|
|
15
15
|
`npm install page-transition@beta`
|
|
16
16
|
|
|
@@ -51,8 +51,8 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
51
51
|
|---|---|---|
|
|
52
52
|
| transitionProperty | "opacity" \| "clip-path" | "opacity" |
|
|
53
53
|
| wait | boolean | false |
|
|
54
|
-
|
|
|
55
|
-
|
|
54
|
+
| items | [number, number] | [0, 0] |
|
|
55
|
+
|
|
56
56
|
|
|
57
57
|
**Prop Descriptions**
|
|
58
58
|
|
|
@@ -65,14 +65,17 @@ The component rendered outside the transition container.
|
|
|
65
65
|
**options.transitionProperty**
|
|
66
66
|
Defines which property transitionend waits for.
|
|
67
67
|
|
|
68
|
-
**options.wait**
|
|
69
|
-
|
|
68
|
+
**options.wait**
|
|
69
|
+
false: Reverses the current enter transition.
|
|
70
|
+
true: Waits for the current enter transition to finish before starting the new transition.
|
|
70
71
|
|
|
71
|
-
**options.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
**options.items**
|
|
73
|
+
<br/>
|
|
74
|
+
options.items[0]
|
|
75
|
+
Number of items in the first group. Each item receives the `.overlay-item` class.
|
|
76
|
+
<br/>
|
|
77
|
+
options.items[1]
|
|
78
|
+
Number of items in the second group. Each item receives the `.second-item` class.
|
|
76
79
|
|
|
77
80
|
|
|
78
81
|
```tsx
|
|
@@ -80,7 +83,7 @@ Creates the same number of items as specified by overlayCount.
|
|
|
80
83
|
header={<Header/>}
|
|
81
84
|
options={{
|
|
82
85
|
transitionProperty: "clip-path",
|
|
83
|
-
|
|
86
|
+
items: [1, 0]
|
|
84
87
|
}}
|
|
85
88
|
>
|
|
86
89
|
{children}
|
|
@@ -119,10 +122,11 @@ Once the transition ends, the scroll position is restored and navigation is perf
|
|
|
119
122
|
|
|
120
123
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
121
124
|
|
|
122
|
-
For overlay animations,
|
|
125
|
+
For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array. The transition waits for the first item group to finish its transition.
|
|
126
|
+
<br/>
|
|
127
|
+
When `wait` is `false`, both item groups must contain the same number of items for reverse delays to work correctly. Both groups will then receive the same delay durations when reversing a staggered enter transition.
|
|
128
|
+
|
|
123
129
|
|
|
124
|
-
If mirror is set to true, the same number of div elements specified by `overlayCount` are added to the `.overlay-wrapper` with the class `mirror-item`. The transitionend dont wait for mirror items.
|
|
125
|
-
|
|
126
130
|
*At the moment, it only supports duration and delay in seconds.*
|
|
127
131
|
|
|
128
132
|
To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
@@ -130,7 +134,7 @@ To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
|
130
134
|
```ts
|
|
131
135
|
import { useTransitionContext } from "page-transition"
|
|
132
136
|
|
|
133
|
-
const {overlayWrapper, overlayItems} = useTransitionContext()
|
|
137
|
+
const { overlayWrapper, overlayItems } = useTransitionContext()
|
|
134
138
|
|
|
135
139
|
```
|
|
136
140
|
|
|
@@ -142,7 +146,7 @@ options
|
|
|
142
146
|
|
|
143
147
|
```ts
|
|
144
148
|
transitionProperty: "opacity"
|
|
145
|
-
|
|
149
|
+
|
|
146
150
|
```
|
|
147
151
|
|
|
148
152
|
```css
|
|
@@ -169,7 +173,7 @@ options
|
|
|
169
173
|
|
|
170
174
|
```ts
|
|
171
175
|
transitionProperty: "clip-path"
|
|
172
|
-
|
|
176
|
+
items: [1, 0]
|
|
173
177
|
```
|
|
174
178
|
|
|
175
179
|
```css
|
|
@@ -204,7 +208,7 @@ options
|
|
|
204
208
|
|
|
205
209
|
```ts
|
|
206
210
|
transitionProperty: "clip-path"
|
|
207
|
-
|
|
211
|
+
items: [10, 0]
|
|
208
212
|
```
|
|
209
213
|
|
|
210
214
|
```scss
|
|
@@ -249,8 +253,7 @@ options
|
|
|
249
253
|
|
|
250
254
|
```ts
|
|
251
255
|
transitionProperty: "clip-path"
|
|
252
|
-
|
|
253
|
-
mirror: true
|
|
256
|
+
items: [10, 10]
|
|
254
257
|
```
|
|
255
258
|
|
|
256
259
|
```scss
|
|
@@ -290,8 +293,8 @@ mirror: true
|
|
|
290
293
|
}
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
|
-
// .
|
|
294
|
-
[data-transition] .
|
|
296
|
+
// .second-item
|
|
297
|
+
[data-transition] .second-item{
|
|
295
298
|
grid-row: 2;
|
|
296
299
|
background: black;
|
|
297
300
|
|
|
@@ -299,7 +302,7 @@ mirror: true
|
|
|
299
302
|
will-change: clip-path;
|
|
300
303
|
clip-path: inset(100% 0 0 0);
|
|
301
304
|
}
|
|
302
|
-
[data-transition].exit .
|
|
305
|
+
[data-transition].exit .second-item{
|
|
303
306
|
grid-row: 2;
|
|
304
307
|
clip-path: inset(0 -1px 0 -1px);
|
|
305
308
|
transition: clip-path 1.2s ease;
|
|
@@ -309,7 +312,7 @@ mirror: true
|
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
|
-
[data-transition].enter .
|
|
315
|
+
[data-transition].enter .second-item{
|
|
313
316
|
grid-row: 2;
|
|
314
317
|
clip-path: inset(100% -1px 0 -1px);
|
|
315
318
|
transition: clip-path 1.2s ease;
|
|
@@ -17,14 +17,13 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
17
17
|
const defaultOptions = {
|
|
18
18
|
transitionProperty: 'opacity',
|
|
19
19
|
wait: false,
|
|
20
|
-
|
|
21
|
-
mirror: false,
|
|
20
|
+
items: [0, 0],
|
|
22
21
|
...options
|
|
23
22
|
};
|
|
24
23
|
const container = useRef(null);
|
|
25
24
|
const overlayWrapper = useRef(null);
|
|
26
25
|
const overlayItems = useRef([]);
|
|
27
|
-
const
|
|
26
|
+
const secondItems = useRef([]);
|
|
28
27
|
const pathname = usePathname();
|
|
29
28
|
const currentPathname = useRef(pathname);
|
|
30
29
|
const mount = useRef({
|
|
@@ -41,7 +40,9 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
41
40
|
return this._lock;
|
|
42
41
|
},
|
|
43
42
|
set lock(value) {
|
|
44
|
-
if (delayStep.current === 0 ||
|
|
43
|
+
if (delayStep.current === 0 ||
|
|
44
|
+
overlayItems.current.length < 2 ||
|
|
45
|
+
defaultOptions.wait === true) {
|
|
45
46
|
if (this._lock === false)
|
|
46
47
|
this._lock = true;
|
|
47
48
|
return;
|
|
@@ -54,10 +55,9 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
54
55
|
const handleLinkClick = useRef(() => { });
|
|
55
56
|
const transitionEndHandler = useTransitionEndHandler();
|
|
56
57
|
const transitionEndData = useTransitionEndData({
|
|
57
|
-
elArray: defaultOptions.
|
|
58
|
+
elArray: defaultOptions.items[0] === 0 ? container : overlayItems,
|
|
58
59
|
transitionProperty: defaultOptions.transitionProperty,
|
|
59
|
-
|
|
60
|
-
mirrorElArray: mirrorItems
|
|
60
|
+
secondElArray: secondItems
|
|
61
61
|
});
|
|
62
62
|
const pollRafId = useRef(null);
|
|
63
63
|
const rafId = useRef(null);
|
|
@@ -132,19 +132,18 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
132
132
|
});
|
|
133
133
|
currentPathname.current = window.location.pathname;
|
|
134
134
|
reverse.current.lock = false;
|
|
135
|
-
if (delayStep.current === null && defaultOptions.
|
|
135
|
+
if (delayStep.current === null && defaultOptions.items[0] > 1) {
|
|
136
136
|
delayStep.current = defaultOptions.wait ? 0 :
|
|
137
137
|
parseDelay(transitionEndData.current.elArray);
|
|
138
138
|
}
|
|
139
139
|
if (duration.current === null && !defaultOptions.wait) {
|
|
140
|
-
duration.current = parseDuration(transitionEndData.current.elArray[0]);
|
|
141
|
-
duration.current = (duration.current ?? 0) * 1000 / 2;
|
|
140
|
+
duration.current = parseDuration(transitionEndData.current.elArray[0]) * 1000 / 3;
|
|
142
141
|
}
|
|
143
142
|
}, [pathname]);
|
|
144
143
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
145
|
-
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [_jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.
|
|
144
|
+
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [_jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
146
145
|
overlayItems.current[i] = el;
|
|
147
|
-
}, className: "overlay-item" }, i))), defaultOptions.
|
|
148
|
-
|
|
149
|
-
}, className: "
|
|
146
|
+
}, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
147
|
+
secondItems.current[i] = el;
|
|
148
|
+
}, className: "second-item" }, `mirror${i}`)))] }), children] })] }));
|
|
150
149
|
}
|
|
@@ -13,8 +13,7 @@ type TransitionProperty = 'opacity' | 'clip-path';
|
|
|
13
13
|
interface TransitionOptions {
|
|
14
14
|
transitionProperty?: TransitionProperty;
|
|
15
15
|
wait?: boolean;
|
|
16
|
-
|
|
17
|
-
mirror?: boolean;
|
|
16
|
+
items?: [number, number];
|
|
18
17
|
}
|
|
19
18
|
interface ProviderProps {
|
|
20
19
|
header?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function parseDuration(el: HTMLElement | null): number
|
|
1
|
+
export declare function parseDuration(el: HTMLElement | null): number;
|
|
@@ -10,21 +10,22 @@ export function transtionEndReverse({ transitionEndObj, transitionEndHandler, re
|
|
|
10
10
|
transitionProperty: endObj.transitionProperty,
|
|
11
11
|
delayStep: delayStep.current
|
|
12
12
|
});
|
|
13
|
-
if (endObj.
|
|
13
|
+
if (endObj.secondElArray.length === endObj.elArray.length) {
|
|
14
14
|
setDelayReverse({
|
|
15
|
-
elArray: endObj.
|
|
15
|
+
elArray: endObj.secondElArray,
|
|
16
16
|
transitionProperty: endObj.transitionProperty,
|
|
17
17
|
delayStep: delayStep.current
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
const firstEl = endObj.elArray[0];
|
|
21
21
|
const handler = (e) => {
|
|
22
|
-
console.log('transitionEndReverse handler fired');
|
|
23
22
|
if (e.propertyName !== endObj.transitionProperty ||
|
|
24
23
|
e.target !== e.currentTarget)
|
|
25
24
|
return;
|
|
26
25
|
resetDelay(endObj.elArray);
|
|
27
|
-
|
|
26
|
+
if (endObj.secondElArray.length === endObj.elArray.length) {
|
|
27
|
+
resetDelay(endObj.secondElArray);
|
|
28
|
+
}
|
|
28
29
|
reverse.current.lock = true;
|
|
29
30
|
firstEl?.removeEventListener('transitionend', handler);
|
|
30
31
|
endObj.fn?.();
|
|
@@ -100,6 +100,9 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
100
100
|
}
|
|
101
101
|
}).then(() => {
|
|
102
102
|
if (wait) {
|
|
103
|
+
if (state.current === 'idle' &&
|
|
104
|
+
currentPathname.current === basePathUrl)
|
|
105
|
+
return;
|
|
103
106
|
if (currentPathname.current === basePathUrl
|
|
104
107
|
&& state.current === 'exiting') {
|
|
105
108
|
transitionEnd({
|
|
@@ -160,8 +163,8 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
160
163
|
delayStep
|
|
161
164
|
});
|
|
162
165
|
let elArray = [];
|
|
163
|
-
if (transitionEndData.current.
|
|
164
|
-
elArray = [...transitionEndData.current.
|
|
166
|
+
if (transitionEndData.current.secondElArray.length > 0) {
|
|
167
|
+
elArray = [...transitionEndData.current.secondElArray, ...transitionEndData.current.elArray];
|
|
165
168
|
}
|
|
166
169
|
else {
|
|
167
170
|
elArray = [...transitionEndData.current.elArray];
|
|
@@ -174,7 +177,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
174
177
|
target: 0,
|
|
175
178
|
duration: duration.current ?? 0
|
|
176
179
|
}).then(() => {
|
|
177
|
-
if (
|
|
180
|
+
if (nextPage.current === currentPathname.current) {
|
|
178
181
|
transitionEnd({
|
|
179
182
|
transitionEndObj: afterExit,
|
|
180
183
|
transitionEndHandler,
|
|
@@ -158,8 +158,8 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
158
158
|
delayStep
|
|
159
159
|
});
|
|
160
160
|
let elArray = [];
|
|
161
|
-
if (transitionEndData.current.
|
|
162
|
-
elArray = [...transitionEndData.current.
|
|
161
|
+
if (transitionEndData.current.secondElArray.length > 0) {
|
|
162
|
+
elArray = [...transitionEndData.current.secondElArray, ...transitionEndData.current.elArray];
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
165
|
elArray = [...transitionEndData.current.elArray];
|
|
@@ -3,8 +3,7 @@ import type { TransitionEndData } from "../types/transitionEnd.types";
|
|
|
3
3
|
interface Props {
|
|
4
4
|
elArray: RefObject<HTMLDivElement | null | (HTMLDivElement | null)[]>;
|
|
5
5
|
transitionProperty: 'opacity' | 'clip-path';
|
|
6
|
-
|
|
7
|
-
mirrorElArray: RefObject<(HTMLDivElement | null)[]>;
|
|
6
|
+
secondElArray: RefObject<(HTMLDivElement | null)[]>;
|
|
8
7
|
}
|
|
9
|
-
export declare function useTransitionEndData({ elArray, transitionProperty,
|
|
8
|
+
export declare function useTransitionEndData({ elArray, transitionProperty, secondElArray }: Props): RefObject<TransitionEndData>;
|
|
10
9
|
export {};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
export function useTransitionEndData({ elArray, transitionProperty,
|
|
3
|
+
export function useTransitionEndData({ elArray, transitionProperty, secondElArray }) {
|
|
4
4
|
const transitionEndData = useRef({
|
|
5
5
|
elArray: [],
|
|
6
6
|
transitionProperty,
|
|
7
|
-
|
|
8
|
-
mirrorElArray: [],
|
|
7
|
+
secondElArray: [],
|
|
9
8
|
});
|
|
10
9
|
useEffect(() => {
|
|
11
10
|
transitionEndData.current = {
|
|
12
11
|
...transitionEndData.current,
|
|
13
12
|
elArray: Array.isArray(elArray.current) ?
|
|
14
13
|
elArray.current : [elArray.current],
|
|
15
|
-
|
|
14
|
+
secondElArray: secondElArray.current
|
|
16
15
|
};
|
|
17
16
|
}, []);
|
|
18
17
|
return transitionEndData;
|
|
@@ -3,8 +3,7 @@ export function useTransitionEndObj({ transitionEndData, fn }) {
|
|
|
3
3
|
const transitionEndObj = useRef({
|
|
4
4
|
elArray: [],
|
|
5
5
|
transitionProperty: transitionEndData.current.transitionProperty,
|
|
6
|
-
|
|
7
|
-
mirrorElArray: [],
|
|
6
|
+
secondElArray: [],
|
|
8
7
|
fn: null
|
|
9
8
|
});
|
|
10
9
|
useEffect(() => {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export interface TransitionEndData {
|
|
2
2
|
elArray: (HTMLDivElement | null)[];
|
|
3
3
|
transitionProperty: 'opacity' | 'clip-path';
|
|
4
|
-
|
|
5
|
-
mirrorElArray: (HTMLDivElement | null)[];
|
|
4
|
+
secondElArray: (HTMLDivElement | null)[];
|
|
6
5
|
}
|
|
7
6
|
export interface TransitionEndObj {
|
|
8
7
|
elArray: (HTMLDivElement | null)[];
|
|
9
8
|
transitionProperty: 'opacity' | 'clip-path';
|
|
10
|
-
|
|
11
|
-
mirrorElArray: (HTMLDivElement | null)[];
|
|
9
|
+
secondElArray: (HTMLDivElement | null)[];
|
|
12
10
|
fn: (() => void) | null;
|
|
13
11
|
}
|
|
14
12
|
export interface TransitionEndHandler {
|