Adding Typescript and Mantine example (#36294)

## 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 `yarn lint`
This commit is contained in:
Mohamed Achaq 2022-04-27 12:36:04 +00:00 committed by GitHub
parent f2c3ef8318
commit fca1071941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 385 additions and 0 deletions

35
examples/with-mantine/.gitignore vendored Normal file
View file

@ -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*
.pnpm-debug.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo

View file

@ -0,0 +1,23 @@
# TypeScript & Mantine Next.js example
This is a simple project that shows the usage of Next.js with TypeScript and Mantine.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-typescript-mantine)
[![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-typescript-mantine&project-name=with-typescript-mantine&repository-name=with-typescript-mantine)
## How to use it?
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-mantine with-mantine-app
# or
yarn create next-app --example with-mantine with-mantine-app
# or
pnpm create next-app -- --example with-mantine with-mantine-app
```
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)).

View file

@ -0,0 +1,52 @@
import { Anchor, Text } from '@mantine/core'
type Props = {
title: string
description: string
link: string
}
const Card = (props: Props) => {
return (
<Anchor
href={props.link}
target="_blank"
sx={{
border: '1px solid #eaeaea',
margin: '1rem',
padding: '1.5rem',
borderRadius: '10px',
textAlign: 'left',
color: 'black',
maxWidth: '300px',
transition: 'all 0.3s ease-in-out',
'&:hover': {
borderColor: '#0070f3',
color: '#0070f3',
},
}}
>
<Text
component="h2"
sx={{
fontSize: '1.5rem',
fontWeight: 'bold',
textAlign: 'left',
}}
>
{props.title}
</Text>
<Text
component="p"
sx={{
fontSize: '1rem',
textAlign: 'left',
}}
>
{props.description}
</Text>
</Anchor>
)
}
export default Card

View file

@ -0,0 +1,28 @@
import { Box } from '@mantine/core'
import { ReactNode } from 'react'
type Props = {
children: ReactNode
}
const Grid = (props: Props) => {
return (
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(2, minmax(200px, 1fr))',
gridGap: '1rem',
justifyContent: 'center',
alignItems: 'center',
'@media (max-width: 800px)': {
gridTemplateColumns: 'repeat(1, minmax(200px, 1fr))',
gridGap: '0.2rem',
},
}}
>
{props.children}
</Box>
)
}
export default Grid

5
examples/with-mantine/next-env.d.ts vendored Normal file
View file

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

View file

@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}
module.exports = nextConfig

View file

@ -0,0 +1,23 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@mantine/core": "^4.1.4",
"@mantine/hooks": "^4.1.4",
"@mantine/next": "^4.1.4",
"next": "latest",
"react": "18.0.0",
"react-dom": "18.0.0"
},
"devDependencies": {
"@types/node": "17.0.25",
"@types/react": "18.0.5",
"@types/react-dom": "18.0.1",
"prettier": "2.6.2",
"typescript": "4.6.3"
}
}

View file

@ -0,0 +1,26 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
import { MantineProvider } from '@mantine/core'
function MyApp({ Component, pageProps }: AppProps) {
return (
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{
colorScheme: 'light',
breakpoints: {
xs: 500,
sm: 800,
md: 1000,
lg: 1200,
xl: 1400,
},
}}
>
<Component {...pageProps} />
</MantineProvider>
)
}
export default MyApp

View file

@ -0,0 +1,20 @@
import { createGetInitialProps } from '@mantine/next'
import Document, { Head, Html, Main, NextScript } from 'next/document'
const getInitialProps = createGetInitialProps()
export default class _Document extends Document {
static getInitialProps = getInitialProps
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

View file

@ -0,0 +1,123 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import { Box, Code, Text } from '@mantine/core'
import Card from '../components/Card'
import Grid from '../components/Grid'
const Home: NextPage = () => {
return (
<Box
component="main"
sx={{
paddingLeft: '2rem',
paddingRight: '2rem',
}}
>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<Box
component="main"
sx={{
minHeight: '100vh',
display: 'flex',
paddingTop: '2rem',
paddingBottom: '2rem',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text
sx={{
color: '#0070f3',
fontSize: '2rem',
'@media (min-width: 800px)': {
fontSize: '3rem',
},
fontWeight: 'bold',
textAlign: 'center',
}}
>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</Text>
<Text
sx={{
color: 'black',
fontSize: '0.9rem',
'@media (min-width: 700px)': {
fontSize: '1.2rem',
},
padding: '1rem',
textAlign: 'center',
}}
>
Get started by editing{' '}
<Code
sx={{
color: 'black',
fontSize: '0.8rem',
textAlign: 'center',
}}
>
pages/index.tsx
</Code>
</Text>
<Grid>
<Card
title="Documentation &rarr;"
description="Find in-depth information about Next.js features and API."
link="https://nextjs.org/docs"
/>
<Card
title="Learn &rarr;"
description="Learn about Next.js in an interactive course with quizzes!"
link="https://nextjs.org/learn"
/>
<Card
title="Examples &rarr;"
description="Discover and deploy boilerplate example Next.js projects."
link="https://nextjs.org/examples"
/>
<Card
title="Deploy &rarr;"
description="Instantly deploy your Next.js site to a public URL with Vercel."
link="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
/>
</Grid>
</Box>
<Box
component="footer"
sx={{
display: 'flex',
flex: '1',
paddingTop: '2rem',
paddingBottom: '2rem',
borderTop: '1px solid #eaeaea',
justifyContent: 'center',
alignItems: 'center',
}}
>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<Box component="span" sx={{ height: '1rem', marginLeft: '1.5rem' }}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</Box>
</a>
</Box>
</Box>
)
}
export default Home

View file

@ -0,0 +1,4 @@
module.exports = {
singleQuote: true,
semi: false,
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,16 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}

View file

@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}