Unverified Commit 39589ff3 authored by Jason's avatar Jason Committed by GitHub

docs: Improves `generateViewport` documentation (#60396)

parent e4172ea3
...@@ -19,7 +19,7 @@ You can customize the initial viewport of the page with the static `viewport` ob ...@@ -19,7 +19,7 @@ You can customize the initial viewport of the page with the static `viewport` ob
## The `viewport` object ## The `viewport` object
To define the viewport options, export a `viewport` object from a `layout.js` or `page.js` file. To define the viewport options, export a `viewport` object from a `layout.jsx` or `page.jsx` file.
```tsx filename="layout.tsx | page.tsx" switcher ```tsx filename="layout.tsx | page.tsx" switcher
import type { Viewport } from 'next' import type { Viewport } from 'next'
...@@ -31,7 +31,7 @@ export const viewport: Viewport = { ...@@ -31,7 +31,7 @@ export const viewport: Viewport = {
export default function Page() {} export default function Page() {}
``` ```
```jsx filename="layout.js | page.js" switcher ```jsx filename="layout.jsx | page.jsx" switcher
export const viewport = { export const viewport = {
themeColor: 'black', themeColor: 'black',
} }
...@@ -67,11 +67,19 @@ export function generateViewport({ params }) { ...@@ -67,11 +67,19 @@ export function generateViewport({ params }) {
### `themeColor` ### `themeColor`
Learn more about [theme-color](https://developer.mozilla.org/docs/Web/HTML/Element/meta/name/theme-color). Learn more about [`theme-color`](https://developer.mozilla.org/docs/Web/HTML/Element/meta/name/theme-color).
**Simple theme color** **Simple theme color**
```jsx filename="layout.js | page.js" ```tsx filename="layout.tsx | page.tsx" switcher
import type { Viewport } from 'next'
export const viewport: Viewport = {
themeColor: 'black',
}
```
```jsx filename="layout.jsx | page.jsx" switcher
export const viewport = { export const viewport = {
themeColor: 'black', themeColor: 'black',
} }
...@@ -83,7 +91,18 @@ export const viewport = { ...@@ -83,7 +91,18 @@ export const viewport = {
**With media attribute** **With media attribute**
```jsx filename="layout.js | page.js" ```tsx filename="layout.tsx | page.tsx" switcher
import type { Viewport } from 'next'
export const viewport: Viewport = {
themeColor: [
{ media: '(prefers-color-scheme: light)', color: 'cyan' },
{ media: '(prefers-color-scheme: dark)', color: 'black' },
],
}
```
```jsx filename="layout.jsx | page.jsx" switcher
export const viewport = { export const viewport = {
themeColor: [ themeColor: [
{ media: '(prefers-color-scheme: light)', color: 'cyan' }, { media: '(prefers-color-scheme: light)', color: 'cyan' },
...@@ -97,16 +116,29 @@ export const viewport = { ...@@ -97,16 +116,29 @@ export const viewport = {
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black" /> <meta name="theme-color" media="(prefers-color-scheme: dark)" content="black" />
``` ```
### `width`, `initialScale`, `maximumScale` and 'userScalable' ### `width`, `initialScale`, `maximumScale` and `userScalable`
> **Good to know**: The `viewport` meta tag is automatically set with the following default values. Usually, manual configuration is unnecessary as the default is sufficient. However, the information is provided for completeness. > **Good to know**: The `viewport` meta tag is automatically set with the following default values. Usually, manual configuration is unnecessary as the default is sufficient. However, the information is provided for completeness.
```jsx filename="layout.js | page.js" ```tsx filename="layout.tsx | page.tsx" switcher
import type { Viewport } from 'next'
export const viewport: Viewport = {
width: 'device-width',
initialScale: 1,
maximumScale: 1,
userScalable: 'no',
// Also supported by less commonly used
// interactiveWidget: 'resizes-visual',
}
```
```jsx filename="layout.jsx | page.jsx" switcher
export const viewport = { export const viewport = {
width: 'device-width', width: 'device-width',
initialScale: 1, initialScale: 1,
maximumScale: 1, maximumScale: 1,
userScalable: 1, userScalable: 'no',
// Also supported by less commonly used // Also supported by less commonly used
// interactiveWidget: 'resizes-visual', // interactiveWidget: 'resizes-visual',
} }
...@@ -123,7 +155,15 @@ export const viewport = { ...@@ -123,7 +155,15 @@ export const viewport = {
Learn more about [`color-scheme`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name#:~:text=color%2Dscheme%3A%20specifies,of%20the%20following%3A). Learn more about [`color-scheme`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name#:~:text=color%2Dscheme%3A%20specifies,of%20the%20following%3A).
```jsx filename="layout.js | page.js" ```tsx filename="layout.tsx | page.tsx" switcher
import type { Viewport } from 'next'
export const viewport: Viewport = {
colorScheme: 'dark',
}
```
```jsx filename="layout.jsx | page.jsx" switcher
export const viewport = { export const viewport = {
colorScheme: 'dark', colorScheme: 'dark',
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment