Skip to content

Commit 31cda7f

Browse files
chore: support Next 13 (#17)
* chore: add .nvmrc file * chore: add support for Next.js v13 * chore: replace @testing-library/react-hooks with @testing-library/react * fix: package start command * chore: convert demo to TS * refactor: port to typescript * chore: dedupe lock file * fix: makeContextualHref types * chore: replace compile script with build * chore: include only dist in package
1 parent 961801b commit 31cda7f

26 files changed

+6901
-18075
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ demo/out
1717
!.prettierrc
1818
!.travis.yml
1919
!.github
20+
!.nvmrc

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

babel.config.js

-25
This file was deleted.

demo/.babelrc

-3
This file was deleted.

demo/components/Grid.js renamed to demo/components/Grid.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import React from 'react';
12
import styles from './Grid.module.css';
23

3-
export default function Grid({ small, children }) {
4+
export default function Grid({
5+
small,
6+
children,
7+
}: {
8+
small?: boolean;
9+
children: React.ReactNode;
10+
}) {
411
return (
512
<div className={styles.wrapper}>
613
<div

demo/components/InitialStateGrid.js renamed to demo/components/InitialStateGrid.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Grid from './Grid';
22
import SquaredLink from './SquaredLink';
3-
import { backgroundColors } from 'demo/pages/index';
3+
import { backgroundColors } from '../pages/index';
44

55
const InitialStateGrid = () => {
66
return (

demo/components/Post.js renamed to demo/components/Post.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import styles from './styles.module.css';
22
import PostGrid from './PostGrid';
33

4-
const Post = ({ id, pathname, pageState, showPostGrid }) => {
4+
const Post = ({
5+
id,
6+
pathname,
7+
pageState,
8+
showPostGrid,
9+
}: {
10+
id: string;
11+
pathname: string;
12+
pageState?: string;
13+
showPostGrid?: boolean;
14+
}) => {
515
return (
616
<div className={styles.post}>
717
<h2>I am the post {id}</h2>

demo/components/PostGrid.js renamed to demo/components/PostGrid.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Grid from './Grid';
22
import SquaredLink from './SquaredLink';
3-
import { useContextualRouting } from 'src';
3+
import { useContextualRouting } from '../../dist';
44
export const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
55

6-
export default function PostGrid({ small }) {
6+
export default function PostGrid({ small }: { small?: boolean }) {
77
const { makeContextualHref } = useContextualRouting();
88

99
return (

demo/components/SquaredLink.js

-19
This file was deleted.

demo/components/SquaredLink.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import Link from 'next/link';
3+
import styles from './SquaredLink.module.css';
4+
5+
export default function SquaredLink({
6+
href,
7+
as,
8+
style,
9+
children,
10+
}: {
11+
href: string;
12+
as?: string;
13+
style?: React.CSSProperties;
14+
children: React.ReactNode;
15+
}) {
16+
return (
17+
<Link className={styles.postCard} href={href} as={as} style={style}>
18+
{children}
19+
</Link>
20+
);
21+
}

demo/global.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
html,
2+
body {
3+
padding: 0;
4+
margin: 0;
5+
}

demo/index-styles.module.css renamed to demo/index.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.background {
2-
height: 100%;
2+
height: 100vh;
33
transition: background ease 0.3s;
44
}
55

demo/next-env.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

demo/pages/_app.js renamed to demo/pages/_app.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import 'demo/styles.css';
2+
import '../global.css';
33

44
export default function App({ Component, pageProps }) {
55
return <Component {...pageProps} />;

demo/pages/index.js renamed to demo/pages/index.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import styles from 'demo/index-styles.module.css';
1+
import styles from '../index.module.css';
22
import { useRouter } from 'next/router';
33
import Modal from 'react-modal';
4-
import Post from 'demo/components/Post';
5-
import PostGrid from 'demo/components/PostGrid';
6-
import InitialStateGrid from 'demo/components/InitialStateGrid';
7-
import { useContextualRouting } from '../../src';
4+
import Post from '../components/Post';
5+
import PostGrid from '../components/PostGrid';
6+
import InitialStateGrid from '../components/InitialStateGrid';
7+
import { useContextualRouting } from '../../dist';
88
export const backgroundColors = {
99
1: '#9b55b7',
1010
2: '#e77e22',
1111
3: '#2c97dd',
12-
};
12+
} as const;
1313

1414
Modal.setAppElement('#__next');
1515

1616
const Index = () => {
1717
const router = useRouter();
18-
const pageState = router.query.state;
18+
const pageState = Array.isArray(router.query.state)
19+
? undefined
20+
: router.query.state;
21+
const postId = Array.isArray(router.query.postId)
22+
? undefined
23+
: router.query.postId;
1924
const { returnHref } = useContextualRouting();
2025

2126
return (
@@ -35,7 +40,7 @@ const Index = () => {
3540
}}
3641
>
3742
<Post
38-
id={router.query.postId}
43+
id={postId}
3944
pathname={router.pathname}
4045
pageState={pageState}
4146
showPostGrid

demo/pages/post/[postId].js renamed to demo/pages/post/[postId].tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRouter } from 'next/router';
2-
import Post from 'demo/components/Post';
3-
import { data } from 'demo/components/PostGrid';
2+
import Post from '../../components/Post';
3+
import { data } from '../../components/PostGrid';
44

55
const PostPage = ({ id }) => {
66
const router = useRouter();

demo/tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": false,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": true,
10+
"incremental": true,
11+
"esModuleInterop": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"jsx": "preserve"
17+
},
18+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19+
"exclude": ["node_modules"]
20+
}

0 commit comments

Comments
 (0)