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' ;
6
10
7
11
type CodeProps = {
8
- [ key : string ] : any
9
- }
10
- const Code : FC < CodeProps > = ( p ) => < code className = { styles . inlineCode } { ...p } />
12
+ [ key : string ] : unknown ;
13
+ } ;
11
14
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
+ } ) => (
13
34
< div className = { styles . container } >
14
35
< div className = { styles . card } >
15
36
< h1 >
@@ -30,8 +51,10 @@ const Home: NextPage = () => (
30
51
loader = { uploadcareLoader }
31
52
alt = "Vercel logo"
32
53
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 }
35
58
/>
36
59
< hr className = { styles . hr } />
37
60
< p >
@@ -43,6 +66,8 @@ const Home: NextPage = () => (
43
66
src = "https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/vercel.png"
44
67
width = { 500 }
45
68
height = { 500 }
69
+ sizes = "(max-width: 50rem) 100vw, 50rem"
70
+ className = { styles . fullWidthImage }
46
71
/>
47
72
< hr className = { styles . hr } />
48
73
< p >
@@ -53,10 +78,13 @@ const Home: NextPage = () => (
53
78
</ p >
54
79
< UploadcareImage
55
80
alt = "Vercel logo"
56
- src = "https://ucarecdn.com/c768f1c2-891a-4f54-8e1e-7242df218b51/pinewatt2Hzmz15wGikunsplash.jpg"
81
+ src = { BLUR_IMAGE_URL }
57
82
width = { 500 }
58
- height = { 500 }
83
+ height = { 333 }
59
84
placeholder = "blur"
85
+ blurDataURL = { blurDataURL }
86
+ sizes = "(max-width: 50rem) 100vw, 50rem"
87
+ className = { styles . fullWidthImage }
60
88
/>
61
89
< hr className = { styles . hr } />
62
90
< p >
@@ -67,9 +95,10 @@ const Home: NextPage = () => (
67
95
< Image
68
96
alt = "Next.js logo"
69
97
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 }
72
100
loader = { uploadcareLoader }
101
+ className = { styles . fullWidthImage }
73
102
/>
74
103
< hr className = { styles . hr } />
75
104
< p > SVGs and GIFs will be used without transformations</ p >
@@ -95,8 +124,18 @@ const Home: NextPage = () => (
95
124
< Image
96
125
alt = "A local image"
97
126
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 }
100
139
loader = { uploadcareLoader }
101
140
/>
102
141
< hr className = { styles . hr } />
@@ -107,6 +146,6 @@ const Home: NextPage = () => (
107
146
.
108
147
</ div >
109
148
</ div >
110
- )
149
+ ) ;
111
150
112
- export default Home
151
+ export default Home ;
0 commit comments