Skip to content

Commit 9b8feb1

Browse files
docs(nextjs-pages): create NextJS example with pages router (#4583)
Part of #4091 --------- Co-authored-by: Lukas Harbarth <[email protected]>
1 parent 4ff8571 commit 9b8feb1

File tree

18 files changed

+4699
-0
lines changed

18 files changed

+4699
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ scripts
1717
shared
1818
packages/cra-template
1919
CodeGen.tsx
20+
examples
2021

examples/nextjs-pages/.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "next/core-web-vitals"
4+
}

examples/nextjs-pages/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

examples/nextjs-pages/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## UI5 Web Components React - Next.js Pages Router Example
2+
3+
This example shows how to use the [Next.js](https://nextjs.org/) Pages Router with UI5 Web Components for React.
4+
It includes the required adjustments in `src/pages/_app.tsx` and `src/pages/_document.tsx` as well as a very simple Todo
5+
App.
6+
7+
## How to use this template
8+
9+
```bash
10+
npx degit SAP/ui5-webcomponents-react/examples/nextjs-pages#main my-project
11+
cd my-project
12+
```
13+
14+
## Getting Started
15+
16+
First, install the node_modules:
17+
18+
```bash
19+
npm install
20+
# or
21+
yarn install
22+
# or
23+
pnpm install
24+
```
25+
26+
Then, run the development server:
27+
28+
```bash
29+
npm run dev
30+
# or
31+
yarn dev
32+
# or
33+
pnpm dev
34+
```
35+
36+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
37+
38+
You can start editing the page by modifying `src/pages/index.tsx`. The page auto-updates as you edit the file.
39+
40+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed
41+
on [http://localhost:3000/api/todods](http://localhost:3000/api/todos). This endpoint can be edited
42+
in `src/pages/api/todos.ts`.
43+
44+
The `src/pages/api` directory is mapped to `/api/*`. Files in this directory are treated
45+
as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
46+
47+
## Learn More
48+
49+
To learn more about Next.js, take a look at the following resources:
50+
51+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
52+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
53+
54+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions
55+
are welcome!
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.appShell {
2+
height: 100vh;
3+
width: 100vw;
4+
overflow: hidden;
5+
}
6+
7+
.scrollContainer {
8+
height: calc(100vh - var(--_ui5_shellbar_root_height));
9+
overflow-y: auto;
10+
position: relative;
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js';
2+
import { Button, ShellBar } from '@ui5/webcomponents-react/ssr';
3+
import { useRouter } from 'next/router';
4+
import { ReactNode } from 'react';
5+
import classes from './AppShell.module.css';
6+
7+
export function AppShell(props: { children: ReactNode }) {
8+
const router = useRouter();
9+
return (
10+
<>
11+
<div className={classes.appShell}>
12+
<ShellBar
13+
primaryTitle={'UI5 Web Components for React Examples'}
14+
secondaryTitle={'NextJS - Pages Router'}
15+
startButton={
16+
router.asPath !== '/' && (
17+
<Button
18+
icon={navBackIcon}
19+
onClick={() => {
20+
router.back();
21+
}}
22+
/>
23+
)
24+
}
25+
/>
26+
<div className={classes.scrollContainer}>{props.children}</div>
27+
</div>
28+
</>
29+
);
30+
}

examples/nextjs-pages/next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true
4+
};
5+
6+
module.exports = nextConfig;

0 commit comments

Comments
 (0)