Unverified Commit e5d0a30a authored by Alex Castle's avatar Alex Castle Committed by GitHub

Modify image component examples app for static image (#25956)

Some fairly minor changes to the image-component example app. Switches all instances of images from `/public` over to use static images and adds a page with an example image with blurry placeholder enabled.
parent 9f9a3eeb
...@@ -2,6 +2,7 @@ import styles from '../styles.module.css' ...@@ -2,6 +2,7 @@ import styles from '../styles.module.css'
import Image from 'next/image' import Image from 'next/image'
import Link from 'next/link' import Link from 'next/link'
import ViewSource from '../components/view-source' import ViewSource from '../components/view-source'
import vercel from '../public/vercel.png'
const Code = (p) => <code className={styles.inlineCode} {...p} /> const Code = (p) => <code className={styles.inlineCode} {...p} />
...@@ -62,6 +63,17 @@ const Index = () => ( ...@@ -62,6 +63,17 @@ const Index = () => (
</li> </li>
</ul> </ul>
<hr className={styles.hr} /> <hr className={styles.hr} />
<h2 id="placeholder">Placeholder</h2>
<p>
Adding <Code>placeholder="blur"</Code> to an image enables a blurry
placeholder effect while that image loads.
</p>
<p>
<Link href="/background">
<a>See an example of the blurry placeholder.</a>
</Link>
</p>
<hr className={styles.hr} />
<h2 id="internal">Internal Image</h2> <h2 id="internal">Internal Image</h2>
<p> <p>
The following is an example of a reference to an interal image from the{' '} The following is an example of a reference to an interal image from the{' '}
...@@ -71,7 +83,7 @@ const Index = () => ( ...@@ -71,7 +83,7 @@ const Index = () => (
This image is intentionally large so you have to scroll down to the next This image is intentionally large so you have to scroll down to the next
image. image.
</p> </p>
<Image alt="Vercel logo" src="/vercel.png" width={1000} height={1000} /> <Image alt="Vercel logo" src={vercel} width={1000} height={1000} />
<hr className={styles.hr} /> <hr className={styles.hr} />
<h2 id="external">External Image</h2> <h2 id="external">External Image</h2>
<p> <p>
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../components/view-source'
import mountains from '../public/mountains.jpg'
const Fill = () => ( const Fill = () => (
<div> <div>
<ViewSource pathname="pages/layout-fill.js" /> <ViewSource pathname="pages/layout-fill.js" />
<h1>Image Component With Layout Fill</h1> <h1>Image Component With Layout Fill</h1>
<div style={{ position: 'relative', width: '300px', height: '500px' }}> <div style={{ position: 'relative', width: '300px', height: '500px' }}>
<Image <Image alt="Mountains" src={mountains} layout="fill" objectFit="cover" />
alt="Mountains"
src="/mountains.jpg"
layout="fill"
objectFit="cover"
/>
</div> </div>
<div style={{ position: 'relative', width: '300px', height: '500px' }}> <div style={{ position: 'relative', width: '300px', height: '500px' }}>
<Image <Image
alt="Mountains" alt="Mountains"
src="/mountains.jpg" src={mountains}
layout="fill" layout="fill"
objectFit="contain" objectFit="contain"
/> />
...@@ -24,7 +20,7 @@ const Fill = () => ( ...@@ -24,7 +20,7 @@ const Fill = () => (
<div style={{ position: 'relative', width: '300px', height: '500px' }}> <div style={{ position: 'relative', width: '300px', height: '500px' }}>
<Image <Image
alt="Mountains" alt="Mountains"
src="/mountains.jpg" src={mountains}
layout="fill" layout="fill"
objectFit="none" objectFit="none"
quality={100} quality={100}
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../components/view-source'
import mountains from '../public/mountains.jpg'
const Fixed = () => ( const Fixed = () => (
<div> <div>
...@@ -7,7 +8,7 @@ const Fixed = () => ( ...@@ -7,7 +8,7 @@ const Fixed = () => (
<h1>Image Component With Layout Fixed</h1> <h1>Image Component With Layout Fixed</h1>
<Image <Image
alt="Mountains" alt="Mountains"
src="/mountains.jpg" src={mountains}
layout="fixed" layout="fixed"
width={700} width={700}
height={475} height={475}
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../components/view-source'
import mountains from '../public/mountains.jpg'
const Intrinsic = () => ( const Intrinsic = () => (
<div> <div>
...@@ -7,7 +8,7 @@ const Intrinsic = () => ( ...@@ -7,7 +8,7 @@ const Intrinsic = () => (
<h1>Image Component With Layout Intrinsic</h1> <h1>Image Component With Layout Intrinsic</h1>
<Image <Image
alt="Mountains" alt="Mountains"
src="/mountains.jpg" src={mountains}
layout="intrinsic" layout="intrinsic"
width={700} width={700}
height={475} height={475}
......
import Image from 'next/image' import Image from 'next/image'
import ViewSource from '../components/view-source' import ViewSource from '../components/view-source'
import mountains from '../public/mountains.jpg'
const Responsive = () => ( const Responsive = () => (
<div> <div>
...@@ -7,7 +8,7 @@ const Responsive = () => ( ...@@ -7,7 +8,7 @@ const Responsive = () => (
<h1>Image Component With Layout Responsive</h1> <h1>Image Component With Layout Responsive</h1>
<Image <Image
alt="Mountains" alt="Mountains"
src="/mountains.jpg" src={mountains}
layout="responsive" layout="responsive"
width={700} width={700}
height={475} height={475}
......
import Image from 'next/image'
import ViewSource from '../components/view-source'
import mountains from '../public/mountains.jpg'
const Responsive = () => (
<div>
<ViewSource pathname="pages/layout-responsive.js" />
<h1>Image Component With Layout Responsive</h1>
<Image
alt="Mountains"
src={mountains}
layout="responsive"
placeholder="blur"
width={700}
height={475}
/>
</div>
)
export default Responsive
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