page-transition 0.1.0-beta.57 → 0.1.0-beta.59

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
- ![Version](https://img.shields.io/badge/v_0.1.0--beta.56-000000) ![70.7 KB](https://img.shields.io/badge/70.7_KB-1677FF)
13
+ ![Version](https://img.shields.io/badge/v_0.1.0--beta.58-000000) ![82.1 KB](https://img.shields.io/badge/82.1_KB-1677FF)
14
14
 
15
15
  `npm install page-transition@beta`
16
16
 
@@ -102,7 +102,7 @@ options={{
102
102
  | href | string | - | Yes |
103
103
  | className | string | - | - |
104
104
  | scroll | boolean | true | - |
105
- | prefetch | "auto" \| null | null | - |
105
+ | prefetch | boolean \| "auto" \| null | null | - |
106
106
  | onClick | (e: React.MouseEvent)=>void | - | - |
107
107
 
108
108
  **Prop Descriptions**
@@ -111,7 +111,17 @@ TransitionLink uses the Next.js Link component internally. For details about nav
111
111
  **Description**
112
112
  Triggers the transition.
113
113
 
114
- *Must be used within the TransitionProvider*
114
+ *Must be used within the TransitionProvider*
115
+
116
+ `css`
117
+ ```tsx
118
+ import {TransitionLink} from "page-transition/css"
119
+
120
+ ```
121
+ `manual`
122
+ ```tsx
123
+ import {TransitionLink} from "page-transition/manual"
124
+ ```
115
125
 
116
126
  ```tsx
117
127
  <TransitionLink href={"/home"}>
@@ -155,9 +165,9 @@ After navigation, the `exit` class is removed and the `enter` class is added. On
155
165
  ```
156
166
 
157
167
 
158
- To access the page wrapper, overlay, overlay wrapper, and their respective items, use `useTransitionContext`.
168
+ To access the page wrapper, overlay, overlay wrapper, and their respective items, use `useCssContext`.
159
169
  ```ts
160
- import { useTransitionContext } from "page-transition"
170
+ import { useCssContext } from "page-transition"
161
171
 
162
172
  const {
163
173
  pageWrapper,
@@ -165,7 +175,7 @@ const {
165
175
  overlayWrapper,
166
176
  overlayItems,
167
177
  secondItems
168
- } = useTransitionContext()
178
+ } = useCssContext()
169
179
  ```
170
180
 
171
181
  #### CSS/SCSS Examples
@@ -387,7 +397,7 @@ items: [10, 10]
387
397
 
388
398
  ### Manual Mode
389
399
 
390
- In manual mode, you can control the transition using `useTransitionContext`.
400
+ In manual mode, you can control the transition using `useManualContext`.
391
401
 
392
402
 
393
403
  After triggering the navigation, `state.current` is set to `exiting`. You can then call `resolveFn.current()` to proceed with the navigation.
@@ -398,8 +408,8 @@ Once `state.current` is set to `entering`, the navigation has occurred. After th
398
408
 
399
409
 
400
410
  ```ts
401
- import { useTransitionContext } from "page-transition"
411
+ import { useManualContext } from "page-transition"
402
412
 
403
- const { resolveFn, state } = useTransitionContext()
413
+ const { resolveFn, state } = useManualContext()
404
414
 
405
415
  ```
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import Link from "next/link";
3
- import { useTransitionContext } from "../context/TransitionContext";
3
+ import { useCssContext } from "../../context/CssContext";
4
4
  export function TransitionLink({ href, className, prefetch, onClick, children }) {
5
- const { handleLinkClick } = useTransitionContext();
5
+ const { handleLinkClick } = useCssContext();
6
6
  return (_jsx(Link, { href: href, onClick: (e) => {
7
7
  onClick?.(e);
8
8
  handleLinkClick.current(e, href);
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from "react";
2
+ interface Props {
3
+ href: string;
4
+ className?: string;
5
+ prefetch?: boolean;
6
+ onClick?: (e: React.MouseEvent) => void;
7
+ children: ReactNode;
8
+ }
9
+ export declare function TransitionLink({ href, className, prefetch, onClick, children }: Props): import("react").JSX.Element;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Link from "next/link";
3
+ import { useManualContext } from "../../context/ManualContext";
4
+ export function TransitionLink({ href, className, prefetch, onClick, children }) {
5
+ const { handleLinkClick } = useManualContext();
6
+ return (_jsx(Link, { href: href, onClick: (e) => {
7
+ onClick?.(e);
8
+ handleLinkClick.current(e, href);
9
+ }, className: className, prefetch: prefetch, children: children }));
10
+ }
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from "react";
2
+ interface ContextProps {
3
+ handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
4
+ pageWrapper?: RefObject<HTMLDivElement | null>;
5
+ overlay?: RefObject<HTMLDivElement | null>;
6
+ overlayWrapper?: RefObject<HTMLDivElement | null>;
7
+ overlayItems?: RefObject<(HTMLDivElement | null)[]>;
8
+ secondItems?: RefObject<(HTMLDivElement | null)[]>;
9
+ }
10
+ export declare const CssContext: import("react").Context<ContextProps | null>;
11
+ export declare function useCssContext(): ContextProps;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { createContext, useContext } from "react";
3
+ export const CssContext = createContext(null);
4
+ export function useCssContext() {
5
+ const context = useContext(CssContext);
6
+ if (!context)
7
+ throw new Error('useCssContext in Provider!');
8
+ return context;
9
+ }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { TransitionContext } from "./TransitionContext";
3
+ import { CssContext } from "./CssContext";
4
4
  import { useRef, useMemo, useEffect } from "react";
5
5
  import { usePathname } from "next/navigation";
6
6
  import { useTransitionEndHandler } from "../hooks/useTransitionEndHandler";
@@ -106,7 +106,7 @@ export function CssTransitionProvider({ outside, scroll, options, children }) {
106
106
  overlayItems,
107
107
  secondItems
108
108
  }), []);
109
- return (_jsx(TransitionContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [outside, defaultOptions.overlay &&
109
+ return (_jsx(CssContext.Provider, { value: value, children: _jsxs("div", { ref: container, "data-transition": true, children: [outside, defaultOptions.overlay &&
110
110
  _jsx("div", { ref: overlay, className: "overlay" }), (defaultOptions.items[0] > 0 || defaultOptions.items[1] > 0) &&
111
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) => {
112
112
  overlayItems.current[i] = el;
@@ -0,0 +1,9 @@
1
+ import type { RefObject } from "react";
2
+ interface ContextProps {
3
+ handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
4
+ resolveFn?: RefObject<(() => void) | null>;
5
+ state?: RefObject<'idle' | 'exiting' | 'entering'>;
6
+ }
7
+ export declare const ManualContext: import("react").Context<ContextProps | null>;
8
+ export declare function useManualContext(): ContextProps;
9
+ export {};
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { createContext, useContext } from "react";
3
+ export const ManualContext = createContext(null);
4
+ export function useManualContext() {
5
+ const context = useContext(ManualContext);
6
+ if (!context)
7
+ throw new Error('useManualContext in Provider!');
8
+ return context;
9
+ }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { TransitionContext } from "./TransitionContext";
3
+ import { ManualContext } from "./ManualContext";
4
4
  import { useEffect, useRef, useMemo } from "react";
5
5
  import { usePathname } from "next/navigation";
6
6
  import { usePopState } from "../hooks/manual/usePopState";
@@ -40,5 +40,5 @@ export function ManualTransitionProvider({ scroll, children }) {
40
40
  currentPathname.current = window.location.pathname;
41
41
  }, [pathname]);
42
42
  const value = useMemo(() => ({ handleLinkClick, resolveFn, state }), []);
43
- return (_jsx(TransitionContext.Provider, { value: value, children: children }));
43
+ return (_jsx(ManualContext.Provider, { value: value, children: children }));
44
44
  }
@@ -0,0 +1,23 @@
1
+ import type { ReactNode } from "react";
2
+ import type { TransitionProperty } from "../types/transitionPropertys.types";
3
+ interface TransitionOptions {
4
+ transitionProperty: TransitionProperty;
5
+ overlay?: boolean;
6
+ items?: [number, number];
7
+ }
8
+ interface BaseProps {
9
+ scroll?: 'auto' | 'top';
10
+ children: ReactNode;
11
+ }
12
+ type ModeProps = {
13
+ mode?: 'css';
14
+ outside?: ReactNode;
15
+ options: TransitionOptions;
16
+ } | {
17
+ mode: 'manual';
18
+ outside?: never;
19
+ options?: never;
20
+ };
21
+ type ProviderProps = BaseProps & ModeProps;
22
+ export declare function TransitionProvider(props: ProviderProps): import("react").JSX.Element;
23
+ export {};
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { CssTransitionProvider } from "./CssTransitionProvider";
4
+ import { ManualTransitionProvider } from "./ManualTransitionProvider";
5
+ export function TransitionProvider(props) {
6
+ const { scroll = 'auto', children } = props;
7
+ return (props.mode === 'manual' ?
8
+ _jsx(ManualTransitionProvider, { scroll: scroll, children: children }) :
9
+ _jsx(CssTransitionProvider, { scroll: scroll, outside: props.outside, options: props.options, children: children }));
10
+ }
package/dist/css.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { TransitionLink } from "./components/css/TransitionLink";
package/dist/css.js ADDED
@@ -0,0 +1 @@
1
+ export { TransitionLink } from "./components/css/TransitionLink";
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { TransitionProvider, useTransitionContext } from "./context/TransitionContext";
2
- export { TransitionLink } from "./components/TransitionLink";
1
+ export { TransitionProvider } from "./context/TransitionProvider";
2
+ export { useCssContext } from "./context/CssContext";
3
+ export { useManualContext } from "./context/ManualContext";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  "use client";
2
- export { TransitionProvider, useTransitionContext } from "./context/TransitionContext";
3
- export { TransitionLink } from "./components/TransitionLink";
2
+ export { TransitionProvider } from "./context/TransitionProvider";
3
+ export { useCssContext } from "./context/CssContext";
4
+ export { useManualContext } from "./context/ManualContext";
@@ -0,0 +1 @@
1
+ export { TransitionLink } from "./components/manual/TransitionLink";
package/dist/manual.js ADDED
@@ -0,0 +1 @@
1
+ export { TransitionLink } from "./components/manual/TransitionLink";
package/package.json CHANGED
@@ -1,11 +1,25 @@
1
1
  {
2
2
  "name": "page-transition",
3
- "version": "0.1.0-beta.57",
3
+ "version": "0.1.0-beta.59",
4
4
  "description": "A page transition library for the Next.js App Router.",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./css": {
15
+ "types": "./dist/css.d.ts",
16
+ "default": "./dist/css.js"
17
+ },
18
+ "./manual": {
19
+ "types": "./dist/manual.d.ts",
20
+ "default": "./dist/manual.js"
21
+ }
22
+ },
9
23
  "main": "./dist/index.js",
10
24
  "types": "./dist/index.d.ts",
11
25
  "scripts": {
@@ -1,35 +0,0 @@
1
- import type { ReactNode, RefObject } from "react";
2
- import type { TransitionProperty } from "../types/transitionPropertys.types";
3
- interface ContextProps {
4
- handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
5
- resolveFn?: RefObject<(() => void) | null>;
6
- state?: RefObject<'idle' | 'exiting' | 'entering'>;
7
- pageWrapper?: RefObject<HTMLDivElement | null>;
8
- overlay?: RefObject<HTMLDivElement | null>;
9
- overlayWrapper?: RefObject<HTMLDivElement | null>;
10
- overlayItems?: RefObject<(HTMLDivElement | null)[]>;
11
- secondItems?: RefObject<(HTMLDivElement | null)[]>;
12
- }
13
- export declare const TransitionContext: import("react").Context<ContextProps | null>;
14
- export declare function useTransitionContext(): ContextProps;
15
- interface TransitionOptions {
16
- transitionProperty: TransitionProperty;
17
- overlay?: boolean;
18
- items?: [number, number];
19
- }
20
- interface BaseProps {
21
- scroll?: 'auto' | 'top';
22
- children: ReactNode;
23
- }
24
- type ModeProps = {
25
- mode?: 'css';
26
- outside?: ReactNode;
27
- options: TransitionOptions;
28
- } | {
29
- mode: 'manual';
30
- outside?: never;
31
- options?: never;
32
- };
33
- type ProviderProps = BaseProps & ModeProps;
34
- export declare function TransitionProvider(props: ProviderProps): import("react").JSX.Element;
35
- export {};
@@ -1,18 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, useContext } from "react";
4
- import { CssTransitionProvider } from "./CssTransitionProvider";
5
- import { ManualTransitionProvider } from "./ManualTransitionProvider";
6
- export const TransitionContext = createContext(null);
7
- export function useTransitionContext() {
8
- const context = useContext(TransitionContext);
9
- if (!context)
10
- throw new Error('useTransitionContext in Provider!');
11
- return context;
12
- }
13
- export function TransitionProvider(props) {
14
- const { scroll = 'auto' } = props;
15
- return (props.mode === 'manual' ?
16
- _jsx(ManualTransitionProvider, { scroll: scroll, children: props.children }) :
17
- _jsx(CssTransitionProvider, { outside: props.outside, scroll: scroll, options: props.options, children: props.children }));
18
- }