page-transition 0.1.0-beta.56 → 0.1.0-beta.57
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
|
@@ -51,6 +51,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
51
51
|
| Option | Type | Default | Required |
|
|
52
52
|
|---|---|---|---|
|
|
53
53
|
| transitionProperty | "opacity" \| "clip-path" \| "transform" | - | Yes |
|
|
54
|
+
| overlay | boolean | "false" | - |
|
|
54
55
|
| items | [number, number] | [0, 0] | - |
|
|
55
56
|
|
|
56
57
|
|
|
@@ -69,12 +70,14 @@ Components rendered outside .page-wrapper, but still inside the transition conta
|
|
|
69
70
|
|
|
70
71
|
**options.transitionProperty**
|
|
71
72
|
Defines which property transitionend waits for.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
**options.overlay**
|
|
76
|
+
Adds an element with the class `.overlay` to the transition container.
|
|
77
|
+
|
|
78
|
+
**options.items**
|
|
75
79
|
`options.items[0]`
|
|
76
|
-
Number of items in the first group. Each item receives the `.overlay-item` class.
|
|
77
|
-
<br/>
|
|
80
|
+
Number of items in the first group. Each item receives the `.overlay-item` class.
|
|
78
81
|
`options.items[1]`
|
|
79
82
|
Number of items in the second group. Each item receives the `.second-item` class.
|
|
80
83
|
|
|
@@ -118,25 +121,27 @@ Triggers the transition.
|
|
|
118
121
|
|
|
119
122
|
### CSS Mode
|
|
120
123
|
|
|
121
|
-
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
|
|
124
|
+
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`.
|
|
122
125
|
|
|
126
|
+
By default, the event is tracked on `.page-wrapper`, which contains the page's children.
|
|
123
127
|
|
|
128
|
+
If `options.overlay` is set to true, the event is tracked on `.overlay` instead. This is primarily intended for fade transitions.
|
|
124
129
|
|
|
125
|
-
|
|
130
|
+
If `options.items` specifies one or more items in the first group, the event is tracked on the last item of that group.
|
|
126
131
|
|
|
132
|
+
An `.overlay-wrapper` is available to group and position transition items. You can configure the number of items in each group using the `options.items` array.
|
|
127
133
|
|
|
134
|
+
Once the transition ends, the scroll position is restored and navigation is performed.
|
|
128
135
|
|
|
129
136
|
After navigation, the `exit` class is removed and the `enter` class is added. Once the next transitionend event fires, the enter class is removed.
|
|
130
137
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
For overlay animations, an `.overlay-wrapper` is available. You can configure the number of overlay items using the options.items array.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
138
|
```tsx
|
|
138
139
|
<div data-transition>
|
|
139
140
|
{outside}
|
|
141
|
+
{
|
|
142
|
+
options.overlay &&
|
|
143
|
+
<div className="overlay"/>
|
|
144
|
+
}
|
|
140
145
|
{
|
|
141
146
|
(options.items[0] > 0 || options.items[1] > 0) &&
|
|
142
147
|
<div className="overlay-wrapper">
|
|
@@ -150,12 +155,13 @@ For overlay animations, an `.overlay-wrapper` is available. You can configure th
|
|
|
150
155
|
```
|
|
151
156
|
|
|
152
157
|
|
|
153
|
-
To access the page wrapper, overlay wrapper and
|
|
158
|
+
To access the page wrapper, overlay, overlay wrapper, and their respective items, use `useTransitionContext`.
|
|
154
159
|
```ts
|
|
155
160
|
import { useTransitionContext } from "page-transition"
|
|
156
161
|
|
|
157
162
|
const {
|
|
158
|
-
pageWrapper,
|
|
163
|
+
pageWrapper,
|
|
164
|
+
overlay,
|
|
159
165
|
overlayWrapper,
|
|
160
166
|
overlayItems,
|
|
161
167
|
secondItems
|
|
@@ -170,21 +176,27 @@ options
|
|
|
170
176
|
|
|
171
177
|
```ts
|
|
172
178
|
transitionProperty: "opacity"
|
|
179
|
+
overlay: true
|
|
173
180
|
|
|
174
181
|
```
|
|
175
182
|
|
|
176
183
|
```css
|
|
177
|
-
[data-transition] .
|
|
184
|
+
[data-transition] .overlay{
|
|
185
|
+
position: fixed;
|
|
186
|
+
z-index: 98;
|
|
187
|
+
inset: 0;
|
|
188
|
+
background: white;
|
|
189
|
+
|
|
190
|
+
opacity: 0;
|
|
178
191
|
will-change: opacity;
|
|
179
|
-
opacity: 1;
|
|
180
192
|
}
|
|
181
|
-
[data-transition].exit .
|
|
182
|
-
opacity:
|
|
193
|
+
[data-transition].exit .overlay{
|
|
194
|
+
opacity: 1;
|
|
183
195
|
transition: opacity 0.4s ease;
|
|
184
196
|
|
|
185
197
|
}
|
|
186
|
-
[data-transition].enter .
|
|
187
|
-
opacity:
|
|
198
|
+
[data-transition].enter .overlay{
|
|
199
|
+
opacity: 0;
|
|
188
200
|
transition: opacity 0.5s ease;
|
|
189
201
|
}
|
|
190
202
|
```
|
|
@@ -197,19 +209,28 @@ options
|
|
|
197
209
|
|
|
198
210
|
```ts
|
|
199
211
|
transitionProperty: "clip-path"
|
|
212
|
+
overlay: true
|
|
200
213
|
items: [1, 0]
|
|
201
214
|
```
|
|
202
215
|
|
|
203
216
|
```css
|
|
204
|
-
[data-transition] .
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
[data-transition] .overlay{
|
|
218
|
+
position: fixed;
|
|
219
|
+
z-index: 98;
|
|
220
|
+
inset: 0;
|
|
221
|
+
background: white;
|
|
222
|
+
|
|
209
223
|
opacity: 0;
|
|
224
|
+
will-change: opacity;
|
|
210
225
|
}
|
|
211
|
-
[data-transition].
|
|
212
|
-
|
|
226
|
+
[data-transition].exit .overlay{
|
|
227
|
+
opacity: 1;
|
|
228
|
+
transition: opacity 0.4s ease;
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
[data-transition].enter .overlay{
|
|
232
|
+
opacity: 0;
|
|
233
|
+
transition: opacity 0.5s ease;
|
|
213
234
|
}
|
|
214
235
|
|
|
215
236
|
[data-transition] .overlay-wrapper{
|
|
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import type { TransitionProperty } from "../types/transitionPropertys.types";
|
|
3
3
|
interface TransitionOptions {
|
|
4
4
|
transitionProperty: TransitionProperty;
|
|
5
|
+
overlay?: boolean;
|
|
5
6
|
items?: [number, number];
|
|
6
7
|
}
|
|
7
8
|
interface ProviderProps {
|
|
@@ -18,6 +18,7 @@ export function CssTransitionProvider({ outside, scroll, options, children }) {
|
|
|
18
18
|
};
|
|
19
19
|
const container = useRef(null);
|
|
20
20
|
const pageWrapper = useRef(null);
|
|
21
|
+
const overlay = useRef(null);
|
|
21
22
|
const overlayWrapper = useRef(null);
|
|
22
23
|
const overlayItems = useRef([]);
|
|
23
24
|
const secondItems = useRef([]);
|
|
@@ -33,8 +34,11 @@ export function CssTransitionProvider({ outside, scroll, options, children }) {
|
|
|
33
34
|
const resolveUseFn = useRef(null);
|
|
34
35
|
const handleLinkClick = useRef(() => { });
|
|
35
36
|
const transitionEndHandler = useTransitionEndHandler();
|
|
37
|
+
const elArray = defaultOptions.items[0] === 0 &&
|
|
38
|
+
!defaultOptions.overlay ?
|
|
39
|
+
pageWrapper : defaultOptions.items[0] > 0 ? overlayItems : overlay;
|
|
36
40
|
const transitionEndData = useTransitionEndData({
|
|
37
|
-
elArray
|
|
41
|
+
elArray,
|
|
38
42
|
transitionProperty: defaultOptions.transitionProperty,
|
|
39
43
|
secondElArray: secondItems
|
|
40
44
|
});
|
|
@@ -94,8 +98,16 @@ export function CssTransitionProvider({ outside, scroll, options, children }) {
|
|
|
94
98
|
});
|
|
95
99
|
currentPathname.current = window.location.pathname;
|
|
96
100
|
}, [pathname]);
|
|
97
|
-
const value = useMemo(() => ({
|
|
98
|
-
|
|
101
|
+
const value = useMemo(() => ({
|
|
102
|
+
handleLinkClick,
|
|
103
|
+
pageWrapper,
|
|
104
|
+
overlay,
|
|
105
|
+
overlayWrapper,
|
|
106
|
+
overlayItems,
|
|
107
|
+
secondItems
|
|
108
|
+
}), []);
|
|
109
|
+
return (_jsx(TransitionContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [outside, defaultOptions.overlay &&
|
|
110
|
+
_jsx("div", { ref: overlay, className: "overlay" }), (defaultOptions.items[0] > 0 || defaultOptions.items[1] > 0) &&
|
|
99
111
|
_jsxs("div", { ref: overlayWrapper, className: "overlay-wrapper", children: [defaultOptions.items[0] > 0 && Array.from({ length: defaultOptions.items[0] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
100
112
|
overlayItems.current[i] = el;
|
|
101
113
|
}, className: "overlay-item" }, i))), defaultOptions.items[1] > 0 && Array.from({ length: defaultOptions.items[1] }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
@@ -5,6 +5,7 @@ interface ContextProps {
|
|
|
5
5
|
resolveFn?: RefObject<(() => void) | null>;
|
|
6
6
|
state?: RefObject<'idle' | 'exiting' | 'entering'>;
|
|
7
7
|
pageWrapper?: RefObject<HTMLDivElement | null>;
|
|
8
|
+
overlay?: RefObject<HTMLDivElement | null>;
|
|
8
9
|
overlayWrapper?: RefObject<HTMLDivElement | null>;
|
|
9
10
|
overlayItems?: RefObject<(HTMLDivElement | null)[]>;
|
|
10
11
|
secondItems?: RefObject<(HTMLDivElement | null)[]>;
|
|
@@ -13,6 +14,7 @@ export declare const TransitionContext: import("react").Context<ContextProps | n
|
|
|
13
14
|
export declare function useTransitionContext(): ContextProps;
|
|
14
15
|
interface TransitionOptions {
|
|
15
16
|
transitionProperty: TransitionProperty;
|
|
17
|
+
overlay?: boolean;
|
|
16
18
|
items?: [number, number];
|
|
17
19
|
}
|
|
18
20
|
interface BaseProps {
|