Skip to content

Commit 8422f23

Browse files
Add NextUI example (vercel#38209)
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Balázs Orbán <[email protected]>
1 parent 88ac118 commit 8422f23

18 files changed

+430
-0
lines changed

examples/with-next-ui/.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

examples/with-next-ui/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# NextUI Example
2+
3+
This example shows how to use Next.js along with [NextUI](https://nextui.org/) of React. This is intended to show the integration of this UI toolkit with the Framework.
4+
5+
## Deploy your own
6+
7+
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
8+
9+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-next-ui)
10+
11+
## How to use
12+
13+
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:
14+
15+
```bash
16+
npx create-next-app --example with-next-ui with-next-ui-app
17+
# or
18+
yarn create next-app --example with-next-ui with-next-ui-app
19+
# or
20+
pnpm create next-app --example with-next-ui with-next-ui-app
21+
```
22+
23+
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface SvgProp {
2+
fill?: string
3+
size?: number
4+
height?: number
5+
width?: number
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Checkbox } from '@nextui-org/react'
2+
3+
const CustomCheckbox = () => {
4+
return (
5+
<Checkbox.Group
6+
label="Select cities"
7+
orientation="horizontal"
8+
color="secondary"
9+
defaultValue={['buenos-aires']}
10+
>
11+
<Checkbox value="buenos-aires">Buenos Aires</Checkbox>
12+
<Checkbox value="sydney">Sydney</Checkbox>
13+
<Checkbox value="london">London</Checkbox>
14+
<Checkbox value="tokyo">Tokyo</Checkbox>
15+
</Checkbox.Group>
16+
)
17+
}
18+
19+
export default CustomCheckbox
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Collapse, Text } from '@nextui-org/react'
2+
3+
const CustomCollapse = () => {
4+
return (
5+
<Collapse.Group>
6+
<Collapse title="Option A">
7+
<Text>
8+
I have had my invitation to this world's festival, and thus my life
9+
has been blessed.
10+
</Text>
11+
</Collapse>
12+
<Collapse title="Option B">
13+
<Text>
14+
In the meanwhile I smile and I sing all alone. In the meanwhile the
15+
air is filling with the perfume of promise.
16+
</Text>
17+
</Collapse>
18+
<Collapse title="Option C">
19+
<Text>
20+
I came out on the chariot of the first gleam of light, and pursued my
21+
voyage through the wildernesses of worlds leaving my track on many a
22+
star and planet.
23+
</Text>
24+
</Collapse>
25+
</Collapse.Group>
26+
)
27+
}
28+
29+
export default CustomCollapse
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SvgProp } from '../common/interface'
2+
3+
export const Mail = ({ fill, size, height, width, ...props }: SvgProp) => {
4+
return (
5+
<svg
6+
width={size || width || 24}
7+
height={size || height || 24}
8+
viewBox="0 0 24 24"
9+
{...props}
10+
>
11+
<g
12+
fill="none"
13+
stroke={fill}
14+
strokeLinecap="round"
15+
strokeLinejoin="round"
16+
strokeWidth={1.5}
17+
>
18+
<path d="M12 20.5H7c-3 0-5-1.5-5-5v-7c0-3.5 2-5 5-5h10c3 0 5 1.5 5 5v3" />
19+
<path d="M17 9l-3.13 2.5a3.166 3.166 0 01-3.75 0L7 9M19.21 14.77l-3.539 3.54a1.232 1.232 0 00-.3.59l-.19 1.35a.635.635 0 00.76.76l1.35-.19a1.189 1.189 0 00.59-.3l3.54-3.54a1.365 1.365 0 000-2.22 1.361 1.361 0 00-2.211.01zM18.7 15.28a3.185 3.185 0 002.22 2.22" />
20+
</g>
21+
</svg>
22+
)
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { SvgProp } from '../common/interface'
2+
3+
export const Password = ({ fill, size, height, width, ...props }: SvgProp) => {
4+
return (
5+
<svg
6+
width={size || width || 24}
7+
height={size || height || 24}
8+
viewBox="0 0 24 24"
9+
{...props}
10+
>
11+
<g fill={fill}>
12+
<path d="M18.75 8v2.1a12.984 12.984 0 00-1.5-.1V8c0-3.15-.89-5.25-5.25-5.25S6.75 4.85 6.75 8v2a12.984 12.984 0 00-1.5.1V8c0-2.9.7-6.75 6.75-6.75S18.75 5.1 18.75 8z" />
13+
<path d="M18.75 10.1a12.984 12.984 0 00-1.5-.1H6.75a12.984 12.984 0 00-1.5.1C2.7 10.41 2 11.66 2 15v2c0 4 1 5 5 5h10c4 0 5-1 5-5v-2c0-3.34-.7-4.59-3.25-4.9zM8.71 16.71A1.052 1.052 0 018 17a1 1 0 01-.38-.08 1.032 1.032 0 01-.33-.21A1.052 1.052 0 017 16a1 1 0 01.08-.38 1.155 1.155 0 01.21-.33 1.032 1.032 0 01.33-.21 1 1 0 011.09.21 1.155 1.155 0 01.21.33A1 1 0 019 16a1.052 1.052 0 01-.29.71zm4.21-.33a1.155 1.155 0 01-.21.33A1.052 1.052 0 0112 17a1.033 1.033 0 01-.71-.29 1.155 1.155 0 01-.21-.33A1 1 0 0111 16a1.033 1.033 0 01.29-.71 1.047 1.047 0 011.42 0A1.033 1.033 0 0113 16a1 1 0 01-.08.38zm3.79.33a1.014 1.014 0 01-1.42 0 1.014 1.014 0 010-1.42 1.047 1.047 0 011.42 0c.04.05.08.1.12.16a.556.556 0 01.09.17.636.636 0 01.06.18 1.5 1.5 0 01.02.2 1.052 1.052 0 01-.29.71z" />
14+
</g>
15+
</svg>
16+
)
17+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Table } from '@nextui-org/react'
2+
3+
const CustomTable = () => {
4+
return (
5+
<Table
6+
aria-label="Example table with static content"
7+
css={{
8+
height: 'auto',
9+
minWidth: '100%',
10+
}}
11+
>
12+
<Table.Header>
13+
<Table.Column>NAME</Table.Column>
14+
<Table.Column>ROLE</Table.Column>
15+
<Table.Column>STATUS</Table.Column>
16+
</Table.Header>
17+
<Table.Body>
18+
<Table.Row key="1">
19+
<Table.Cell>Tony Reichert</Table.Cell>
20+
<Table.Cell>CEO</Table.Cell>
21+
<Table.Cell>Active</Table.Cell>
22+
</Table.Row>
23+
<Table.Row key="2">
24+
<Table.Cell>Zoey Lang</Table.Cell>
25+
<Table.Cell>Technical Lead</Table.Cell>
26+
<Table.Cell>Paused</Table.Cell>
27+
</Table.Row>
28+
<Table.Row key="3">
29+
<Table.Cell>Jane Fisher</Table.Cell>
30+
<Table.Cell>Senior Developer</Table.Cell>
31+
<Table.Cell>Active</Table.Cell>
32+
</Table.Row>
33+
<Table.Row key="4">
34+
<Table.Cell>William Howard</Table.Cell>
35+
<Table.Cell>Community Manager</Table.Cell>
36+
<Table.Cell>Vacation</Table.Cell>
37+
</Table.Row>
38+
</Table.Body>
39+
</Table>
40+
)
41+
}
42+
43+
export default CustomTable

examples/with-next-ui/next.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('next').NextConfig} */
2+
3+
const nextConfig = {
4+
reactStrictMode: false,
5+
swcMinify: true,
6+
}
7+
8+
module.exports = nextConfig

examples/with-next-ui/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "next dev",
5+
"build": "next build",
6+
"start": "next start"
7+
},
8+
"dependencies": {
9+
"@nextui-org/react": "1.0.0-beta.9",
10+
"next": "latest",
11+
"react": "18.2.0",
12+
"react-dom": "18.2.0"
13+
},
14+
"devDependencies": {
15+
"@types/node": "18.0.3",
16+
"@types/react": "18.0.15",
17+
"@types/react-dom": "18.0.6",
18+
"typescript": "4.7.4"
19+
}
20+
}

examples/with-next-ui/pages/_app.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import '../styles/globals.css'
2+
import { NextUIProvider } from '@nextui-org/react'
3+
4+
import type { AppProps } from 'next/app'
5+
6+
export default function MyApp({ Component, pageProps }: AppProps) {
7+
return (
8+
<NextUIProvider>
9+
<Component {...pageProps} />
10+
</NextUIProvider>
11+
)
12+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Document, {
2+
Html,
3+
Head,
4+
Main,
5+
NextScript,
6+
DocumentContext,
7+
DocumentInitialProps,
8+
} from 'next/document'
9+
10+
import { CssBaseline } from '@nextui-org/react'
11+
12+
import { Children } from 'react'
13+
14+
export default class MyDocument extends Document {
15+
static async getInitialProps(
16+
ctx: DocumentContext
17+
): Promise<DocumentInitialProps> {
18+
const initialProps = await Document.getInitialProps(ctx)
19+
20+
return {
21+
...initialProps,
22+
styles: Children.toArray([initialProps.styles]),
23+
}
24+
}
25+
26+
render() {
27+
return (
28+
<Html lang="en">
29+
<Head>{CssBaseline.flush()}</Head>
30+
<body>
31+
<Main />
32+
<NextScript />
33+
</body>
34+
</Html>
35+
)
36+
}
37+
}

examples/with-next-ui/pages/index.tsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Head from 'next/head'
2+
import Image from 'next/image'
3+
import styles from '../styles/Home.module.css'
4+
import dynamic from 'next/dynamic'
5+
import { Avatar, Pagination } from '@nextui-org/react'
6+
7+
const CustomCheckbox = dynamic(() => import('../components/Checkbox'))
8+
const CustomTable = dynamic(() => import('../components/Table'))
9+
const CustomCollapse = dynamic(() => import('../components/Collapse'))
10+
11+
export default function Home() {
12+
return (
13+
<div className={styles.container}>
14+
<Head>
15+
<title>NextUI Example</title>
16+
<meta name="description" content="Generated by create next app" />
17+
<link rel="icon" href="/favicon.ico" />
18+
</Head>
19+
<main className={styles.main}>
20+
<h1>
21+
<Avatar text="Hi" color="gradient" textColor={'white'} size={'xl'} />
22+
</h1>
23+
<h1 className={styles.title}>
24+
Welcome to use <a href="https://nextui.org/">NextUI!</a>
25+
</h1>
26+
{/* checkout */}
27+
<h2>Checkbox:</h2>
28+
<CustomCheckbox></CustomCheckbox>
29+
{/* table */}
30+
<h2>Table:</h2>
31+
<CustomTable></CustomTable>
32+
{/* pagination */}
33+
<h2>Pagination</h2>
34+
<Pagination total={20} initialPage={1} />
35+
{/* collapse */}
36+
<h2>Collapse</h2>
37+
<CustomCollapse></CustomCollapse>
38+
</main>
39+
<footer className={styles.footer}>
40+
<a
41+
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
42+
target="_blank"
43+
rel="noopener noreferrer"
44+
>
45+
Powered by{' '}
46+
<span className={styles.logo}>
47+
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
48+
</span>
49+
</a>
50+
</footer>
51+
</div>
52+
)
53+
}
25.3 KB
Binary file not shown.
+4
Loading

0 commit comments

Comments
 (0)