Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
900afdc2
Unverified
Commit
900afdc2
authored
Oct 27, 2020
by
Yamagishi Kazutoshi
Committed by
GitHub
Oct 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support number quality on Image Component (#18224)
Co-authored-by:
Tim Neutkens
<
timneutkens@me.com
>
parent
080b91f9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
15 deletions
+27
-15
image.tsx
packages/next/client/image.tsx
+15
-15
valid.tsx
test/integration/image-component/typescript/pages/valid.tsx
+12
-0
No files found.
packages/next/client/image.tsx
View file @
900afdc2
...
@@ -26,7 +26,7 @@ type ImageProps = Omit<
...
@@ -26,7 +26,7 @@ type ImageProps = Omit<
'src'
|
'srcSet'
|
'ref'
|
'width'
|
'height'
|
'loading'
'src'
|
'srcSet'
|
'ref'
|
'width'
|
'height'
|
'loading'
>
&
{
>
&
{
src
:
string
src
:
string
quality
?:
string
quality
?:
number
|
string
priority
?:
boolean
priority
?:
boolean
loading
?:
LoadingValue
loading
?:
LoadingValue
unoptimized
?:
boolean
unoptimized
?:
boolean
...
@@ -104,8 +104,8 @@ function getDeviceSizes(width: number | undefined): number[] {
...
@@ -104,8 +104,8 @@ function getDeviceSizes(width: number | undefined): number[] {
function
computeSrc
(
function
computeSrc
(
src
:
string
,
src
:
string
,
unoptimized
:
boolean
,
unoptimized
:
boolean
,
width
:
number
|
undefined
,
width
?:
number
,
quality
?:
string
quality
?:
number
):
string
{
):
string
{
if
(
unoptimized
)
{
if
(
unoptimized
)
{
return
src
return
src
...
@@ -118,7 +118,7 @@ function computeSrc(
...
@@ -118,7 +118,7 @@ function computeSrc(
type
CallLoaderProps
=
{
type
CallLoaderProps
=
{
src
:
string
src
:
string
width
:
number
width
:
number
quality
?:
string
quality
?:
number
}
}
function
callLoader
(
loaderProps
:
CallLoaderProps
)
{
function
callLoader
(
loaderProps
:
CallLoaderProps
)
{
...
@@ -129,8 +129,8 @@ function callLoader(loaderProps: CallLoaderProps) {
...
@@ -129,8 +129,8 @@ function callLoader(loaderProps: CallLoaderProps) {
type
SrcSetData
=
{
type
SrcSetData
=
{
src
:
string
src
:
string
unoptimized
:
boolean
unoptimized
:
boolean
width
:
number
|
undefined
width
?:
number
quality
:
string
|
undefined
quality
?:
number
}
}
function
generateSrcSet
({
function
generateSrcSet
({
...
@@ -155,7 +155,7 @@ type PreloadData = {
...
@@ -155,7 +155,7 @@ type PreloadData = {
unoptimized
:
boolean
unoptimized
:
boolean
width
:
number
|
undefined
width
:
number
|
undefined
sizes
?:
string
sizes
?:
string
quality
?:
string
quality
?:
number
}
}
function
generatePreload
({
function
generatePreload
({
...
@@ -251,8 +251,10 @@ export default function Image({
...
@@ -251,8 +251,10 @@ export default function Image({
}
}
},
[
thisEl
,
lazy
])
},
[
thisEl
,
lazy
])
let
widthInt
=
getInt
(
width
)
const
widthInt
=
getInt
(
width
)
let
heightInt
=
getInt
(
height
)
const
heightInt
=
getInt
(
height
)
const
qualityInt
=
getInt
(
quality
)
let
divStyle
:
React
.
CSSProperties
|
undefined
let
divStyle
:
React
.
CSSProperties
|
undefined
let
imgStyle
:
React
.
CSSProperties
|
undefined
let
imgStyle
:
React
.
CSSProperties
|
undefined
let
wrapperStyle
:
React
.
CSSProperties
|
undefined
let
wrapperStyle
:
React
.
CSSProperties
|
undefined
...
@@ -305,12 +307,12 @@ export default function Image({
...
@@ -305,12 +307,12 @@ export default function Image({
}
}
// Generate attribute values
// Generate attribute values
const
imgSrc
=
computeSrc
(
src
,
unoptimized
,
widthInt
,
quality
)
const
imgSrc
=
computeSrc
(
src
,
unoptimized
,
widthInt
,
quality
Int
)
const
imgSrcSet
=
generateSrcSet
({
const
imgSrcSet
=
generateSrcSet
({
src
,
src
,
width
:
widthInt
,
width
:
widthInt
,
unoptimized
,
unoptimized
,
quality
,
quality
:
qualityInt
,
})
})
let
imgAttributes
:
let
imgAttributes
:
...
@@ -352,7 +354,7 @@ export default function Image({
...
@@ -352,7 +354,7 @@ export default function Image({
width
:
widthInt
,
width
:
widthInt
,
unoptimized
,
unoptimized
,
sizes
,
sizes
,
quality
,
quality
:
qualityInt
,
})
})
:
''
}
:
''
}
<
img
<
img
...
@@ -442,7 +444,5 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
...
@@ -442,7 +444,5 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
}
}
}
}
return
`
${
root
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
return
`
${
root
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
quality
||
75
}
`
quality
||
'75'
}
`
}
}
test/integration/image-component/typescript/pages/valid.tsx
View file @
900afdc2
...
@@ -22,6 +22,18 @@ const Page = () => {
...
@@ -22,6 +22,18 @@ const Page = () => {
src=
"https://via.placeholder.com/100"
src=
"https://via.placeholder.com/100"
unsized
unsized
></
Image
>
></
Image
>
<
Image
id=
"quality-num"
src=
"https://via.placeholder.com/500"
quality=
{
80
}
unsized
></
Image
>
<
Image
id=
"quality-str"
src=
"https://via.placeholder.com/500"
quality=
"80"
unsized
></
Image
>
<
p
id=
"stubtext"
>
This is valid usage of the Image component
</
p
>
<
p
id=
"stubtext"
>
This is valid usage of the Image component
</
p
>
</
div
>
</
div
>
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment