-
Notifications
You must be signed in to change notification settings - Fork 103
docs: add NextJS app router example #4714
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
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1cefa13
docs(nextjs-app): bootstrap app
MarcusNotheis 8ebaa3c
add more use client directives
MarcusNotheis 9975562
fix pages shellbar
MarcusNotheis cab2c01
add webcomponents react to nextjs app example
MarcusNotheis 115cd65
Update withWebComponent.tsx
MarcusNotheis 3a0e6c9
chore: add action for testing examples
MarcusNotheis 6a5a004
fix eslint errors
MarcusNotheis 210d279
Update examples.yml
MarcusNotheis 0c0615e
Merge branch 'main' into docs/nextjs-app-example
Lukas742 e6cf5b7
Merge branch 'main' into docs/nextjs-app-example
MarcusNotheis 61b78d6
update webcomponents
MarcusNotheis ffb7832
Update README.md
Lukas742 de3ab26
Apply suggestions from code review
MarcusNotheis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ jobs: | |
strategy: | ||
matrix: | ||
path: | ||
- nextjs-app | ||
- nextjs-pages | ||
- vite-ts | ||
fail-fast: false | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"root": true, | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## UI5 Web Components React - Next.js App Router Example | ||
|
||
This example shows how to use the [Next.js](https://nextjs.org/) App Router with UI5 Web Components for React. | ||
|
||
## How to use this template | ||
|
||
```bash | ||
npx degit SAP/ui5-webcomponents-react/examples/nextjs-app#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 `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use client'; | ||
|
||
import { useServerInsertedHTML } from 'next/navigation'; | ||
import { useEffect, useState } from 'react'; | ||
import { createGenerateId, JssProvider, SheetsRegistry } from 'react-jss'; | ||
|
||
export function CssRegistry({ children }: { children: React.ReactNode }) { | ||
const [registry] = useState(() => new SheetsRegistry()); | ||
const generateId = createGenerateId(); | ||
|
||
useServerInsertedHTML(() => { | ||
return ( | ||
<> | ||
<style id="server-side-styles">{registry.toString()}</style> | ||
</> | ||
); | ||
}); | ||
|
||
useEffect(() => { | ||
const style = document.getElementById('server-side-styles'); | ||
if (style) { | ||
style.parentNode?.removeChild(style); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<JssProvider registry={registry} generateId={generateId}> | ||
{children} | ||
</JssProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client'; | ||
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js'; | ||
import { Button, ShellBar } from '@ui5/webcomponents-react'; | ||
import '@ui5/webcomponents-react/dist/Assets.js'; | ||
import { usePathname, useRouter } from 'next/navigation'; | ||
|
||
export function AppShell() { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
|
||
return ( | ||
<> | ||
<ShellBar | ||
primaryTitle={'UI5 Web Components for React Examples'} | ||
secondaryTitle={'NextJS - App Router'} | ||
startButton={ | ||
pathname !== '/' && ( | ||
<Button | ||
icon={navBackIcon} | ||
onClick={() => { | ||
router.back(); | ||
}} | ||
/> | ||
) | ||
} | ||
/> | ||
</> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client'; | ||
|
||
import { Todo } from '@/app/mockData/todos'; | ||
import { List, ListItemType, ListPropTypes, StandardListItem, ValueState } from '@ui5/webcomponents-react'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
interface TodoListProps { | ||
items: Todo[]; | ||
} | ||
|
||
export function TodoList({ items }: TodoListProps) { | ||
const router = useRouter(); | ||
const handleTodoClick: ListPropTypes['onItemClick'] = (event) => { | ||
router.push(`/todos/${event.detail.item.dataset.id}`); | ||
}; | ||
|
||
return ( | ||
<List onItemClick={handleTodoClick}> | ||
{items.map((todo) => { | ||
return ( | ||
<StandardListItem | ||
key={todo.id} | ||
data-id={todo.id} | ||
type={ListItemType.Navigation} | ||
additionalText={`${!todo.completed ? 'Not ' : ''}Completed`} | ||
additionalTextState={todo.completed ? ValueState.Success : ValueState.None} | ||
> | ||
{todo.title} | ||
</StandardListItem> | ||
); | ||
})} | ||
</List> | ||
); | ||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
:not(:defined) { | ||
MarcusNotheis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
display: none; | ||
} | ||
|
||
html, | ||
body { | ||
max-width: 100vw; | ||
overflow-x: hidden; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.appShell { | ||
height: 100vh; | ||
width: 100vw; | ||
overflow: hidden; | ||
} | ||
|
||
.appScrollContainer { | ||
height: calc(100vh - 3.25rem); | ||
width: 100vw; | ||
overflow-y: auto; | ||
position: relative; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AppShell } from '@/app/components/AppShell'; | ||
import { CssRegistry } from '@/app/CssRegistry'; | ||
import { ThemeProvider } from '@ui5/webcomponents-react'; | ||
import './globals.css'; | ||
|
||
export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<script | ||
data-ui5-config | ||
type="application/json" | ||
dangerouslySetInnerHTML={{ | ||
__html: JSON.stringify({ | ||
theme: 'sap_horizon' | ||
}) | ||
}} | ||
/> | ||
</head> | ||
<body> | ||
<div className="appShell"> | ||
<CssRegistry> | ||
<ThemeProvider> | ||
<AppShell /> | ||
<div className="appScrollContainer">{children}</div> | ||
</ThemeProvider> | ||
</CssRegistry> | ||
</div> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.container { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BusyIndicator, BusyIndicatorSize } from '@ui5/webcomponents-react'; | ||
import classes from './loading.module.css'; | ||
|
||
export default function HomeLoading() { | ||
return ( | ||
<div className={classes.container}> | ||
<BusyIndicator active size={BusyIndicatorSize.Large} delay={0} /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.