Skip to content

Commit 60f0dc4

Browse files
committed
chore: update demo project
1 parent b01e93e commit 60f0dc4

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

example/next.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
/** @type {import('next').NextConfig} */
22
module.exports = {
3-
reactStrictMode: true,
4-
images: {
5-
loader: "custom"
6-
}
3+
reactStrictMode: true
74
}

example/pages/index.tsx

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
import type { NextPage } from 'next'
2-
import Image from 'next/image'
3-
import UploadcareImage, { uploadcareLoader } from '@uploadcare/nextjs-loader'
4-
import { FC } from 'react'
5-
import styles from '../styles/Home.module.css'
1+
import type { NextPage, GetStaticProps, InferGetStaticPropsType } from 'next';
2+
import Image from 'next/image';
3+
import UploadcareImage, {
4+
uploadcareLoader,
5+
getBlurDataURL
6+
} from '@uploadcare/nextjs-loader';
7+
import { FC } from 'react';
8+
import styles from '../styles/Home.module.css';
9+
import staticImportImage from '../public/static_image.png';
610

711
type CodeProps = {
8-
[key: string]: any
9-
}
10-
const Code: FC<CodeProps> = (p) => <code className={styles.inlineCode} {...p} />
12+
[key: string]: unknown;
13+
};
1114

12-
const Home: NextPage = () => (
15+
const Code: FC<CodeProps> = (p) => (
16+
<code className={styles.inlineCode} {...p} />
17+
);
18+
19+
const BLUR_IMAGE_URL =
20+
'https://ucarecdn.com/c768f1c2-891a-4f54-8e1e-7242df218b51/pinewatt2Hzmz15wGikunsplash.jpg';
21+
22+
export const getStaticProps: GetStaticProps<{ blurDataURL: string }> =
23+
async () => {
24+
const blurDataURL = await getBlurDataURL(BLUR_IMAGE_URL);
25+
26+
return {
27+
props: { blurDataURL }
28+
};
29+
};
30+
31+
const Home: NextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({
32+
blurDataURL
33+
}) => (
1334
<div className={styles.container}>
1435
<div className={styles.card}>
1536
<h1>
@@ -30,8 +51,10 @@ const Home: NextPage = () => (
3051
loader={uploadcareLoader}
3152
alt="Vercel logo"
3253
src="https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/vercel.png"
33-
width={1000}
34-
height={1000}
54+
width={500}
55+
height={500}
56+
sizes="(max-width: 50rem) 100vw, 50rem"
57+
className={styles.fullWidthImage}
3558
/>
3659
<hr className={styles.hr} />
3760
<p>
@@ -43,6 +66,8 @@ const Home: NextPage = () => (
4366
src="https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/vercel.png"
4467
width={500}
4568
height={500}
69+
sizes="(max-width: 50rem) 100vw, 50rem"
70+
className={styles.fullWidthImage}
4671
/>
4772
<hr className={styles.hr} />
4873
<p>
@@ -53,10 +78,13 @@ const Home: NextPage = () => (
5378
</p>
5479
<UploadcareImage
5580
alt="Vercel logo"
56-
src="https://ucarecdn.com/c768f1c2-891a-4f54-8e1e-7242df218b51/pinewatt2Hzmz15wGikunsplash.jpg"
81+
src={BLUR_IMAGE_URL}
5782
width={500}
58-
height={500}
83+
height={333}
5984
placeholder="blur"
85+
blurDataURL={blurDataURL}
86+
sizes="(max-width: 50rem) 100vw, 50rem"
87+
className={styles.fullWidthImage}
6088
/>
6189
<hr className={styles.hr} />
6290
<p>
@@ -67,9 +95,10 @@ const Home: NextPage = () => (
6795
<Image
6896
alt="Next.js logo"
6997
src="https://assets.vercel.com/image/upload/v1538361091/repositories/next-js/next-js.png"
70-
width={1200}
71-
height={400}
98+
width={500}
99+
height={166}
72100
loader={uploadcareLoader}
101+
className={styles.fullWidthImage}
73102
/>
74103
<hr className={styles.hr} />
75104
<p>SVGs and GIFs will be used without transformations</p>
@@ -95,8 +124,18 @@ const Home: NextPage = () => (
95124
<Image
96125
alt="A local image"
97126
src="/local_image.png"
98-
width={494}
99-
height={332}
127+
width={600}
128+
height={400}
129+
loader={uploadcareLoader}
130+
/>
131+
<hr className={styles.hr} />
132+
<p>
133+
Statically imported image will be served AS IS in Development, and
134+
converted to the absolute URL and passed to the proxy in Production
135+
</p>
136+
<Image
137+
alt="A statically imported image"
138+
src={staticImportImage}
100139
loader={uploadcareLoader}
101140
/>
102141
<hr className={styles.hr} />
@@ -107,6 +146,6 @@ const Home: NextPage = () => (
107146
.
108147
</div>
109148
</div>
110-
)
149+
);
111150

112-
export default Home
151+
export default Home;

example/public/local_image.png

6.46 KB
Loading

example/public/static_image.png

15 KB
Loading

example/styles/Home.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@
3232
border-top: 1px solid #eaeaea;
3333
margin: 1.5rem 0;
3434
}
35+
36+
.fullWidthImage {
37+
width: 100%;
38+
height: auto;
39+
}

0 commit comments

Comments
 (0)