Skip to content

docs(nextjs-pages): create NextJS example with pages router #4583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ scripts
shared
packages/cra-template
CodeGen.tsx
examples

4 changes: 4 additions & 0 deletions examples/nextjs-pages/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
35 changes: 35 additions & 0 deletions examples/nextjs-pages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
55 changes: 55 additions & 0 deletions examples/nextjs-pages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## UI5 Web Components React - Next.js Pages Router Example

This example shows how to use the [Next.js](https://nextjs.org/) Pages Router with UI5 Web Components for React.
It includes the required adjustments in `src/pages/_app.tsx` and `src/pages/_document.tsx` as well as a very simple Todo
App.

## How to use this template

```bash
npx degit SAP/ui5-webcomponents-react/examples/nextjs-pages#main my-project
cd my-project
```

## Getting Started

First, install the node_modules:

```bash
npm install
# or
yarn install
# or
pnpm install
```

Then, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `src/pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed
on [http://localhost:3000/api/todods](http://localhost:3000/api/todos). This endpoint can be edited
in `src/pages/api/todos.ts`.

The `src/pages/api` directory is mapped to `/api/*`. Files in this directory are treated
as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions
are welcome!
11 changes: 11 additions & 0 deletions examples/nextjs-pages/components/AppShell/AppShell.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.appShell {
height: 100vh;
width: 100vw;
overflow: hidden;
}

.scrollContainer {
height: calc(100vh - var(--_ui5_shellbar_root_height));
overflow-y: auto;
position: relative;
}
30 changes: 30 additions & 0 deletions examples/nextjs-pages/components/AppShell/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js';
import { Button, ShellBar } from '@ui5/webcomponents-react/ssr';
import { useRouter } from 'next/router';
import { ReactNode } from 'react';
import classes from './AppShell.module.css';

export function AppShell(props: { children: ReactNode }) {
const router = useRouter();
return (
<>
<div className={classes.appShell}>
<ShellBar
primaryTitle={'UI5 Web Components for React Examples'}
secondaryTitle={'NextJS - Pages Router'}
startButton={
router.asPath !== '/' && (
<Button
icon={navBackIcon}
onClick={() => {
router.back();
}}
/>
)
}
/>
<div className={classes.scrollContainer}>{props.children}</div>
</div>
</>
);
}
6 changes: 6 additions & 0 deletions examples/nextjs-pages/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true
};

module.exports = nextConfig;
Loading