page-transition 0.1.0-beta.3 → 0.1.0-beta.5
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 +13 -6
- package/dist/components/TransitionLink.d.ts +7 -2
- package/dist/components/TransitionLink.js +3 -2
- package/dist/context/CssTransitionProvider.d.ts +2 -2
- package/dist/context/CssTransitionProvider.js +10 -8
- package/dist/context/TransitionContext.d.ts +2 -2
- package/dist/context/TransitionContext.js +1 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,9 +78,16 @@ options={{
|
|
|
78
78
|
### `TransitionLink`
|
|
79
79
|
#### Props
|
|
80
80
|
|
|
81
|
-
|Prop|
|
|
82
|
-
|
|
83
|
-
| href | string | - |
|
|
81
|
+
|Prop|Type|Default|Required
|
|
82
|
+
|---|---|---|---|
|
|
83
|
+
| href | string | - | Yes |
|
|
84
|
+
| className | string | - | - |
|
|
85
|
+
| scroll | boolean | true | - |
|
|
86
|
+
| prefetch | "auto" \| null | null | - |
|
|
87
|
+
| onClick | (e: React.MouseEvent)=>void | - | - |
|
|
88
|
+
|
|
89
|
+
**Prop Descriptions**
|
|
90
|
+
TransitionLink uses the Next.js Link component internally. For details about navigation behavior and supported props, refer to the official Next.js documentation.
|
|
84
91
|
|
|
85
92
|
**Description**
|
|
86
93
|
Triggers the transition.
|
|
@@ -196,10 +203,10 @@ overlayCount: 10
|
|
|
196
203
|
background: black;
|
|
197
204
|
transition: none;
|
|
198
205
|
will-change: clip-path;
|
|
199
|
-
clip-path: inset(100%
|
|
206
|
+
clip-path: inset(100% -1px 0 -1px);
|
|
200
207
|
}
|
|
201
208
|
[data-transition].exit .overlay-item{
|
|
202
|
-
clip-path: inset(0
|
|
209
|
+
clip-path: inset(0 -1px 0 -1px);
|
|
203
210
|
transition: clip-path 1.0s ease;
|
|
204
211
|
@for $i from 0 to 10{
|
|
205
212
|
&:nth-child(#{$i+1}){
|
|
@@ -208,7 +215,7 @@ overlayCount: 10
|
|
|
208
215
|
}
|
|
209
216
|
}
|
|
210
217
|
[data-transition].enter .overlay-item{
|
|
211
|
-
clip-path: inset(0
|
|
218
|
+
clip-path: inset(0 -1px 100% -1px);
|
|
212
219
|
transition: clip-path 1.0s ease;
|
|
213
220
|
@for $i from 0 to 10{
|
|
214
221
|
&:nth-child(#{$i+1}){
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
interface Props {
|
|
3
3
|
href: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
prefetch?: boolean;
|
|
6
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
4
7
|
children: ReactNode;
|
|
5
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export declare function TransitionLink({ href, className, prefetch, onClick, children }: Props): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import Link from "next/link";
|
|
3
3
|
import { useTransitionContext } from "../context/TransitionContext";
|
|
4
|
-
export function TransitionLink({ href, children }) {
|
|
4
|
+
export function TransitionLink({ href, className, prefetch, onClick, children }) {
|
|
5
5
|
const { handleLinkClick } = useTransitionContext();
|
|
6
6
|
return (_jsx(Link, { href: href, onClick: (e) => {
|
|
7
7
|
handleLinkClick.current(e, href);
|
|
8
|
-
|
|
8
|
+
onClick?.(e);
|
|
9
|
+
}, className: className, prefetch: prefetch, children: children }));
|
|
9
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
interface TransitionOptions {
|
|
3
|
-
transitionProperty
|
|
4
|
-
overlayCount
|
|
3
|
+
transitionProperty?: 'opacity' | 'clip-path';
|
|
4
|
+
overlayCount?: number;
|
|
5
5
|
}
|
|
6
6
|
interface ProviderProps {
|
|
7
7
|
header?: ReactNode;
|
|
@@ -11,22 +11,24 @@ import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
|
|
|
11
11
|
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
12
12
|
import { usePopState } from "../hooks/usePopState";
|
|
13
13
|
import { parseDelay } from "../functions/parseDelay";
|
|
14
|
-
export function CssTransitionProvider({ header, options
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export function CssTransitionProvider({ header, options, children }) {
|
|
15
|
+
const defaultOptions = {
|
|
16
|
+
transitionProperty: 'opacity',
|
|
17
|
+
overlayCount: 0,
|
|
18
|
+
...options
|
|
19
|
+
};
|
|
18
20
|
const container = useRef(null);
|
|
19
21
|
const overlayWrapper = useRef(null);
|
|
20
22
|
const overlayItems = useRef([]);
|
|
21
23
|
const pathname = usePathname();
|
|
22
24
|
const currentPathname = useRef(pathname);
|
|
23
|
-
const resolveUseFn = useRef(null);
|
|
24
25
|
const mount = useRef({
|
|
25
26
|
mounted: false,
|
|
26
27
|
initPathname: pathname
|
|
27
28
|
});
|
|
28
29
|
const state = useRef('idle');
|
|
29
30
|
const useUse = useRef(false);
|
|
31
|
+
const resolveUseFn = useRef(null);
|
|
30
32
|
const reverse = useRef({
|
|
31
33
|
_lock: true,
|
|
32
34
|
get lock() {
|
|
@@ -45,8 +47,8 @@ export function CssTransitionProvider({ header, options = {
|
|
|
45
47
|
const handleLinkClick = useRef(() => { });
|
|
46
48
|
const transitionEndHandler = useTransitionEndHandler();
|
|
47
49
|
const transitionEndData = useTransitionEndData({
|
|
48
|
-
elArray:
|
|
49
|
-
transitionProperty:
|
|
50
|
+
elArray: defaultOptions.overlayCount === 0 ? container : overlayItems,
|
|
51
|
+
transitionProperty: defaultOptions.transitionProperty
|
|
50
52
|
});
|
|
51
53
|
usePopState({
|
|
52
54
|
container,
|
|
@@ -104,7 +106,7 @@ export function CssTransitionProvider({ header, options = {
|
|
|
104
106
|
reverse.current.lock = false;
|
|
105
107
|
}, [pathname]);
|
|
106
108
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
107
|
-
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [_jsx("div", { ref: overlayWrapper, className: "overlay-wrapper", children: Array.from({ length:
|
|
109
|
+
return (_jsxs(TransitionContext.Provider, { value: value, children: [header, _jsxs("div", { ref: container, "data-transition": true, children: [_jsx("div", { ref: overlayWrapper, className: "overlay-wrapper", children: Array.from({ length: defaultOptions.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
|
|
108
110
|
overlayItems.current[i] = el;
|
|
109
111
|
}, className: "overlay-item" }, i))) }), children] })] }));
|
|
110
112
|
}
|
|
@@ -11,8 +11,8 @@ export declare function useTransitionContext(): ContextProps;
|
|
|
11
11
|
type Mode = 'css' | 'manual';
|
|
12
12
|
type TransitionProperty = 'opacity' | 'clip-path';
|
|
13
13
|
interface TransitionOptions {
|
|
14
|
-
transitionProperty
|
|
15
|
-
overlayCount
|
|
14
|
+
transitionProperty?: TransitionProperty;
|
|
15
|
+
overlayCount?: number;
|
|
16
16
|
}
|
|
17
17
|
interface ProviderProps {
|
|
18
18
|
header?: ReactNode;
|
|
@@ -10,10 +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
|
|
14
|
-
transitionProperty: 'opacity',
|
|
15
|
-
overlayCount: 0
|
|
16
|
-
}, children, }) {
|
|
13
|
+
export function TransitionProvider({ header, mode = 'css', options, children, }) {
|
|
17
14
|
return (mode === 'css' ?
|
|
18
15
|
_jsx(CssTransitionProvider, { header: header, options: options, children: children }) :
|
|
19
16
|
_jsx(ManualTransitionProvider, { children: children }));
|