Skip to content

Commit

Permalink
Merge branch 'canary' into add-route-events-types
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris authored Sep 29, 2020
2 parents 1cc71c3 + c731c63 commit af88d8b
Show file tree
Hide file tree
Showing 138 changed files with 779 additions and 346 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
packages/next-env/**/*.d.ts
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
packages/next-env/**/*.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ And the AMP version of your page will include a link to the HTML page:
<link rel="canonical" href="/about" />
```

When [`exportTrailingSlash`](/docs/api-reference/next.config.js/exportPathMap.md#0cf7d6666b394c5d8d08a16a933e86ea) is enabled the exported pages for `pages/about.js` would be:
When [`trailingSlash`](/docs/api-reference/next.config.js/trailing-slash.md) is enabled the exported pages for `pages/about.js` would be:

- `out/about/index.html` - HTML page
- `out/about.amp/index.html` - AMP page
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: A custom asset prefix allows you serve static assets from a CDN. Le

# CDN Support with Asset Prefix

> **Attention**: [Deploying to Vercel](docs/deployment.md) automatically configures a global CDN for your Next.js project.
> **Attention**: [Deploying to Vercel](/docs/deployment.md) automatically configures a global CDN for your Next.js project.
> You do not need to manually setup an Asset Prefix.
> **Note**: Next.js 9.5+ added support for a customizable [Base Path](docs/api-reference/next.config.js/basepath.md), which is better
> **Note**: Next.js 9.5+ added support for a customizable [Base Path](/docs/api-reference/next.config.js/basepath.md), which is better
> suited for hosting your application on a sub-path like `/docs`.
> We do not suggest you use a custom Asset Prefix for this use case.
Expand Down
1 change: 0 additions & 1 deletion docs/api-reference/next.config.js/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description: Learn to add and access environment variables in your Next.js appli
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-env-from-next-config-js">With env</a></li>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-now-env">With Now env</a></li>
</ul>
</details>

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/exportPathMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The returned object is a map of pages where the `key` is the `pathname` and the

It is possible to configure Next.js to export pages as `index.html` files and require trailing slashes, `/about` becomes `/about/index.html` and is routable via `/about/`. This was the default behavior prior to Next.js 9.

To switch back and add a trailing slash, open `next.config.js` and enable the `exportTrailingSlash` config:
To switch back and add a trailing slash, open `next.config.js` and enable the `trailingSlash` config:

```js
module.exports = {
Expand Down
9 changes: 2 additions & 7 deletions docs/api-routes/api-middlewares.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,18 @@ For better type-safety, it is not recommended to extend the `req` and `res` obje
```ts
// utils/cookies.ts

import { serialize } from 'cookie'
import { serialize, CookieSerializeOptions } from 'cookie'
import { NextApiResponse } from 'next'

/**
* This sets `cookie` using the `res` object
*/

type Options = {
expires?: Date
maxAge?: number
}

export const setCookie = (
res: NextApiResponse,
name: string,
value: unknown,
options: Options = {}
options: CookieSerializeOptions = {}
) => {
const stringValue =
typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value)
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ You can revert to the previous behavior by creating a `next.config.js` with the
```js
// next.config.js
module.exports = {
exportTrailingSlash: true,
trailingSlash: true,
}
```

Expand Down
3 changes: 1 addition & 2 deletions errors/no-document-viewport-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ The viewport tag should be handled by `next/head` in `pages/_app.js`.

Set your viewport `meta` tag in `pages/_app.js` instead:

```jsx
```tsx
// pages/_app.js
import React from 'react'
import Head from 'next/head'

function MyApp({ Component, pageProps }) {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-algolia-react-instantsearch/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# With Algolia React InstantSearch example

The goal of this example is to illustrate how you can use [Algolia React InstantSearch](https://community.algolia.com/react-instantsearch/) to perform your search with a Server-rendered application developed with Next.js. It also illustrates how you can keep in sync the Url with the search.
The goal of this example is to illustrate how you can use [Algolia React InstantSearch](https://community.algolia.com/react-instantsearch/) to perform your search in an application developed with Next.js. It also illustrates how you can keep in sync the Url with the search.

## How to use

Expand Down
34 changes: 34 additions & 0 deletions examples/with-chakra-ui-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
27 changes: 27 additions & 0 deletions examples/with-chakra-ui-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Example app with [chakra-ui](https://github.com/chakra-ui/chakra-ui) and Typescript

This example features how to use [chakra-ui](https://github.com/chakra-ui/chakra-ui) as the component library within a Next.js app with typescript.

Next.js and chakra-ui have built-in TypeScript declarations, so we'll get autocompletion for their modules straight away.

We are connecting the Next.js `_app.js` with `chakra-ui`'s Provider and theme so the pages can have app-wide dark/light mode. We are also creating some components which shows the usage of `chakra-ui`'s style props.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-chakra-ui-typescript)

## How to use

### Using `create-next-app`

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-chakra-ui-typescript with-chakra-ui-typescript-app
# or
yarn create next-app --example with-chakra-ui-typescript with-chakra-ui-typescript-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
2 changes: 2 additions & 0 deletions examples/with-chakra-ui-typescript/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
23 changes: 23 additions & 0 deletions examples/with-chakra-ui-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "with-chakra-ui-typescript",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@chakra-ui/core": "^1.0.0-rc.3",
"@chakra-ui/icons": "^1.0.0-rc.3",
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/node": "^14.6.0",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"typescript": "4.0.2"
},
"license": "MIT"
}
31 changes: 31 additions & 0 deletions examples/with-chakra-ui-typescript/src/components/CTA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Link as ChakraLink, Button } from '@chakra-ui/core'

import { Container } from './Container'

export const CTA = () => (
<Container
flexDirection="row"
position="fixed"
bottom="0"
width="100%"
maxWidth="48rem"
py={2}
>
<ChakraLink isExternal href="https://chakra-ui.com" flexGrow={1} mx={2}>
<Button width="100%" variant="outline" colorScheme="green">
chakra-ui
</Button>
</ChakraLink>

<ChakraLink
isExternal
href="https://github.com/vercel/next.js/blob/canary/examples/with-chakra-ui-typescript"
flexGrow={3}
mx={2}
>
<Button width="100%" variant="solid" colorScheme="green">
View Repo
</Button>
</ChakraLink>
</Container>
)
19 changes: 19 additions & 0 deletions examples/with-chakra-ui-typescript/src/components/Container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Flex, useColorMode, FlexProps } from '@chakra-ui/core'

export const Container = (props: FlexProps) => {
const { colorMode } = useColorMode()

const bgColor = { light: 'gray.50', dark: 'gray.900' }

const color = { light: 'black', dark: 'white' }
return (
<Flex
direction="column"
alignItems="center"
justifyContent="flex-start"
bg={bgColor[colorMode]}
color={color[colorMode]}
{...props}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useColorMode, Switch } from '@chakra-ui/core'

export const DarkModeSwitch = () => {
const { colorMode, toggleColorMode } = useColorMode()
const isDark = colorMode === 'dark'
return (
<Switch
position="fixed"
top="1rem"
right="1rem"
color="green"
isChecked={isDark}
onChange={toggleColorMode}
/>
)
}
5 changes: 5 additions & 0 deletions examples/with-chakra-ui-typescript/src/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Flex, FlexProps } from '@chakra-ui/core'

export const Footer = (props: FlexProps) => (
<Flex as="footer" py="8rem" {...props} />
)
11 changes: 11 additions & 0 deletions examples/with-chakra-ui-typescript/src/components/Hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Flex, Heading } from '@chakra-ui/core'

export const Hero = ({ title }: { title: string }) => (
<Flex justifyContent="center" alignItems="center" height="100vh">
<Heading fontSize="6vw">{title}</Heading>
</Flex>
)

Hero.defaultProps = {
title: 'with-chakra-ui-typescript',
}
13 changes: 13 additions & 0 deletions examples/with-chakra-ui-typescript/src/components/Main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Stack, StackProps } from '@chakra-ui/core'

export const Main = (props: StackProps) => (
<Stack
spacing="1.5rem"
width="100%"
maxWidth="48rem"
mt="-45vh"
pt="8rem"
px="1rem"
{...props}
/>
)
14 changes: 14 additions & 0 deletions examples/with-chakra-ui-typescript/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChakraProvider } from '@chakra-ui/core'

import theme from '../theme'
import { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider resetCSS theme={theme}>
<Component {...pageProps} />
</ChakraProvider>
)
}

export default MyApp
56 changes: 56 additions & 0 deletions examples/with-chakra-ui-typescript/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
Link as ChakraLink,
Text,
Code,
List,
ListIcon,
ListItem,
} from '@chakra-ui/core'
import { CheckCircleIcon, LinkIcon } from '@chakra-ui/icons'

import { Hero } from '../components/Hero'
import { Container } from '../components/Container'
import { Main } from '../components/Main'
import { DarkModeSwitch } from '../components/DarkModeSwitch'
import { CTA } from '../components/CTA'
import { Footer } from '../components/Footer'

const Index = () => (
<Container height="100vh">
<Hero />
<Main>
<Text>
Example repository of <Code>Next.js</Code> + <Code>chakra-ui</Code> +{' '}
<Code>typescript</Code>.
</Text>

<List spacing={3} my={0}>
<ListItem>
<ListIcon as={CheckCircleIcon} color="green.500" />
<ChakraLink
isExternal
href="https://chakra-ui.com"
flexGrow={1}
mr={2}
>
Chakra UI <LinkIcon />
</ChakraLink>
</ListItem>
<ListItem>
<ListIcon as={CheckCircleIcon} color="green.500" />
<ChakraLink isExternal href="https://nextjs.org" flexGrow={1} mr={2}>
Next.js <LinkIcon />
</ChakraLink>
</ListItem>
</List>
</Main>

<DarkModeSwitch />
<Footer>
<Text>Next ❤️ Chakra</Text>
</Footer>
<CTA />
</Container>
)

export default Index
17 changes: 17 additions & 0 deletions examples/with-chakra-ui-typescript/src/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { theme as chakraTheme } from '@chakra-ui/core'

const fonts = { ...chakraTheme.fonts, mono: `'Menlo', monospace` }

const breakpoints = ['40em', '52em', '64em']

const theme = {
...chakraTheme,
colors: {
...chakraTheme.colors,
black: '#16161D',
},
fonts,
breakpoints,
}

export default theme
Loading

0 comments on commit af88d8b

Please sign in to comment.