page-transition 0.1.0-beta.46 → 0.1.0-beta.47
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
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
|
|
|
@@ -59,7 +59,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
59
59
|
Select the transition mode.
|
|
60
60
|
|
|
61
61
|
**header**
|
|
62
|
-
The component rendered outside the
|
|
62
|
+
The component rendered outside the .page-wrapper.
|
|
63
63
|
|
|
64
64
|
**options.transitionProperty**
|
|
65
65
|
Defines which property transitionend waits for.
|
|
@@ -100,8 +100,9 @@ options={{
|
|
|
100
100
|
TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
|
|
101
101
|
|
|
102
102
|
**Description**
|
|
103
|
-
Triggers the transition.
|
|
103
|
+
Triggers the transition.
|
|
104
104
|
|
|
105
|
+
*Must be used within the TransitionProvider*
|
|
105
106
|
|
|
106
107
|
```tsx
|
|
107
108
|
<TransitionLink href={"/home"}>
|
|
@@ -111,13 +112,14 @@ Triggers the transition.
|
|
|
111
112
|
|
|
112
113
|
### CSS Mode
|
|
113
114
|
|
|
114
|
-
The `TransitionProvider` uses a container with a `data-transition` attribute. When navigation starts, it adds the
|
|
115
|
+
The `TransitionProvider` uses a container with a `data-transition` attribute. When navigation starts, it adds the exit class and waits for the transitionend event of the configured transition property. By default, this is the `.page-wrapper` containing the page's children. If options.items is configured, the event is instead tracked on the last item of the first group.
|
|
115
116
|
|
|
116
117
|
Once the transition ends, the scroll position is restored and navigation is performed.
|
|
117
118
|
|
|
118
119
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
119
120
|
|
|
120
|
-
For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array.
|
|
121
|
+
For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array.
|
|
122
|
+
<br/>
|
|
121
123
|
<br/>
|
|
122
124
|
To access the overlay wrapper and its items, use `useTransitionContext`.
|
|
123
125
|
|
|
@@ -140,16 +142,16 @@ transitionProperty: "opacity"
|
|
|
140
142
|
```
|
|
141
143
|
|
|
142
144
|
```css
|
|
143
|
-
[data-transition]{
|
|
145
|
+
[data-transition] .page-wrapper{
|
|
144
146
|
will-change: opacity;
|
|
145
147
|
opacity: 1;
|
|
146
148
|
}
|
|
147
|
-
[data-transition].exit{
|
|
149
|
+
[data-transition].exit .page-wrapper{
|
|
148
150
|
opacity: 0;
|
|
149
151
|
transition: opacity 0.4s ease;
|
|
150
152
|
|
|
151
153
|
}
|
|
152
|
-
[data-transition].enter{
|
|
154
|
+
[data-transition].enter .page-wrapper{
|
|
153
155
|
opacity: 1;
|
|
154
156
|
transition: opacity 0.5s ease;
|
|
155
157
|
}
|
|
@@ -316,6 +318,7 @@ items: [10, 10]
|
|
|
316
318
|
```
|
|
317
319
|
</details>
|
|
318
320
|
|
|
321
|
+
|
|
319
322
|
### Manual Mode
|
|
320
323
|
|
|
321
324
|
In manual mode, you can control the transition using `useTransitionContext`.
|
|
@@ -17,6 +17,7 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
17
17
|
...options
|
|
18
18
|
};
|
|
19
19
|
const container = useRef(null);
|
|
20
|
+
const pageWrapper = useRef(null);
|
|
20
21
|
const overlayWrapper = useRef(null);
|
|
21
22
|
const overlayItems = useRef([]);
|
|
22
23
|
const secondItems = useRef([]);
|
|
@@ -33,7 +34,7 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
33
34
|
const handleLinkClick = useRef(() => { });
|
|
34
35
|
const transitionEndHandler = useTransitionEndHandler();
|
|
35
36
|
const transitionEndData = useTransitionEndData({
|
|
36
|
-
elArray: defaultOptions.items[0] === 0 ?
|
|
37
|
+
elArray: defaultOptions.items[0] === 0 ? pageWrapper : overlayItems,
|
|
37
38
|
transitionProperty: defaultOptions.transitionProperty,
|
|
38
39
|
secondElArray: secondItems
|
|
39
40
|
});
|
|
@@ -94,9 +95,9 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
94
95
|
currentPathname.current = window.location.pathname;
|
|
95
96
|
}, [pathname]);
|
|
96
97
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
97
|
-
return (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
return (_jsx(TransitionContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [header, _jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
99
|
+
overlayItems.current[i] = el;
|
|
100
|
+
}, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
101
|
+
secondItems.current[i] = el;
|
|
102
|
+
}, className: "second-item" }, `mirror${i}`)))] }), _jsx("div", { ref: pageWrapper, className: "page-wrapper", children: children })] }) }));
|
|
102
103
|
}
|
|
@@ -20,5 +20,5 @@ interface ProviderProps {
|
|
|
20
20
|
options: TransitionOptions;
|
|
21
21
|
children: ReactNode;
|
|
22
22
|
}
|
|
23
|
-
export declare function TransitionProvider({ header, mode, options, children
|
|
23
|
+
export declare function TransitionProvider({ header, mode, options, children }: ProviderProps): import("react").JSX.Element;
|
|
24
24
|
export {};
|
|
@@ -10,7 +10,7 @@ export function useTransitionContext() {
|
|
|
10
10
|
throw new Error('useTransitionContext in Provider!');
|
|
11
11
|
return context;
|
|
12
12
|
}
|
|
13
|
-
export function TransitionProvider({ header, mode = 'css', options, children
|
|
13
|
+
export function TransitionProvider({ header, mode = 'css', options, children }) {
|
|
14
14
|
return (mode === 'css' ?
|
|
15
15
|
_jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
|
|
16
16
|
_jsx(ManualTransitionProvider, { children: children }));
|