page-transition 0.1.0-beta.4 → 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.
@@ -1,5 +1,10 @@
1
1
  import type { ReactNode } from "react";
2
- export declare function TransitionLink({ href, children }: {
2
+ interface Props {
3
3
  href: string;
4
+ className?: string;
5
+ prefetch?: boolean;
6
+ onClick?: (e: React.MouseEvent) => void;
4
7
  children: ReactNode;
5
- }): import("react").JSX.Element;
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
- }, children: children }));
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: 'opacity' | 'clip-path';
4
- overlayCount: number;
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
- transitionProperty: 'opacity',
16
- overlayCount: 0
17
- }, children }) {
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: options.overlayCount === 0 ? container : overlayItems,
49
- transitionProperty: options.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: options.overlayCount }).map((_, i) => (_jsx("div", { ref: (el) => {
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: TransitionProperty;
15
- overlayCount: number;
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 }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-transition",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "A page transition library for the Next.js App Router.",
5
5
  "license": "MIT",
6
6
  "files": [