rsnext/examples/image-legacy-component/pages/index.tsx
Steven e2f16f96c2
Update next/image docs and examples (#41434)
This PR updates the docs for the following code change:

- #41399

There are a few updates here:

- [x] Update docs
- [x] Update links to docs inside component
- [x] Update examples
- [x] Fix corner cases in codemod
2022-10-17 10:41:35 -04:00

142 lines
4.2 KiB
TypeScript

import styles from '../styles.module.css'
import Image from 'next/legacy/image'
import Link from 'next/link'
import ViewSource from '../components/view-source'
import vercel from '../public/vercel.png'
import type { PropsWithChildren } from 'react'
const Code = (props: PropsWithChildren<{}>) => (
<code className={styles.inlineCode} {...props} />
)
const Index = () => (
<div className={styles.container}>
<ViewSource pathname="pages/index.tsx" />
<div className={styles.card}>
<h1>Image Component with Next.js</h1>
<p>
This page demonstrates the usage of the{' '}
<a href="https://nextjs.org/docs/api-reference/next/legacy/image">
next/legacy/image
</a>{' '}
component with live examples.
</p>
<p>
This component is designed to{' '}
<a href="https://nextjs.org/docs/basic-features/image-optimization">
automatically optimize
</a>{' '}
images on-demand as the browser requests them.
</p>
<hr className={styles.hr} />
<h2 id="layout">Layout</h2>
<p>
External images must be configured in <Code>next.config.js</Code> using
the <Code>remotePatterns</Code> property.
</p>
<p>
Select a layout below and try resizing the window or rotating your
device to see how the image reacts.
</p>
<ul>
<li>
<Link href="/layout-intrinsic">
<a>layout="intrinsic"</a>
</Link>
</li>
<li>
<Link href="/layout-responsive">
<a>layout="responsive"</a>
</Link>
</li>
<li>
<Link href="/layout-fixed">
<a>layout="fixed"</a>
</Link>
</li>
<li>
<Link href="/layout-fill">
<a>layout="fill"</a>
</Link>
</li>
<li>
<Link href="/background">
<a>background demo</a>
</Link>
</li>
</ul>
<hr className={styles.hr} />
<h2 id="placeholder">Placeholder</h2>
<p>
The <Code>placeholder</Code> property tells the image what to do while
loading.
</p>
<p>
You can optionally enable a blur-up placeholder while the high
resolution image loads.
</p>
<p>
Try it out below (you may need to disable cache in dev tools to see the
effect if you already visited):
</p>
<ul>
<li>
<Link href="/placeholder">
<a>placeholder="blur"</a>
</Link>
</li>
<li>
<Link href="/shimmer">
<a>placeholder="blur" with animated shimmer blurDataURL</a>
</Link>
</li>
<li>
<Link href="/color">
<a>placeholder="blur" with solid color blurDataURL</a>
</Link>
</li>
</ul>
<hr className={styles.hr} />
<h2 id="internal">Internal Image</h2>
<p>
The following is an example of a reference to an internal image from the{' '}
<Code>public</Code> directory.
</p>
<p>
This image is intentionally large so you have to scroll down to the next
image.
</p>
<Image alt="Vercel logo" src={vercel} width={1000} height={1000} />
<hr className={styles.hr} />
<h2 id="external">External Image</h2>
<p>
The following is an example of a reference to an external image at{' '}
<Code>assets.vercel.com</Code>.
</p>
<p>
External images must be configured in <Code>next.config.js</Code> using
the <Code>remotePatterns</Code> property.
</p>
<Image
alt="Next.js logo"
src="https://assets.vercel.com/image/upload/v1538361091/repositories/next-js/next-js-bg.png"
width={1200}
height={400}
/>
<hr className={styles.hr} />
<h2 id="more">Learn More</h2>
<p>
You can optionally configure a cloud provider, device sizes, and more!
</p>
<p>
Checkout the{' '}
<a href="https://nextjs.org/docs/basic-features/image-optimization">
Image Optimization documentation
</a>{' '}
to learn more.
</p>
</div>
</div>
)
export default Index