Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
900afdc2
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
900afdc2
编写于
10月 27, 2020
作者:
Y
Yamagishi Kazutoshi
提交者:
GitHub
10月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support number quality on Image Component (#18224)
Co-authored-by:
N
Tim Neutkens
<
timneutkens@me.com
>
上级
080b91f9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
15 deletion
+27
-15
packages/next/client/image.tsx
packages/next/client/image.tsx
+15
-15
test/integration/image-component/typescript/pages/valid.tsx
test/integration/image-component/typescript/pages/valid.tsx
+12
-0
未找到文件。
packages/next/client/image.tsx
浏览文件 @
900afdc2
...
...
@@ -26,7 +26,7 @@ type ImageProps = Omit<
'
src
'
|
'
srcSet
'
|
'
ref
'
|
'
width
'
|
'
height
'
|
'
loading
'
>
&
{
src
:
string
quality
?:
string
quality
?:
number
|
string
priority
?:
boolean
loading
?:
LoadingValue
unoptimized
?:
boolean
...
...
@@ -104,8 +104,8 @@ function getDeviceSizes(width: number | undefined): number[] {
function
computeSrc
(
src
:
string
,
unoptimized
:
boolean
,
width
:
number
|
undefined
,
quality
?:
string
width
?:
number
,
quality
?:
number
):
string
{
if
(
unoptimized
)
{
return
src
...
...
@@ -118,7 +118,7 @@ function computeSrc(
type
CallLoaderProps
=
{
src
:
string
width
:
number
quality
?:
string
quality
?:
number
}
function
callLoader
(
loaderProps
:
CallLoaderProps
)
{
...
...
@@ -129,8 +129,8 @@ function callLoader(loaderProps: CallLoaderProps) {
type
SrcSetData
=
{
src
:
string
unoptimized
:
boolean
width
:
number
|
undefined
quality
:
string
|
undefined
width
?:
number
quality
?:
number
}
function
generateSrcSet
({
...
...
@@ -155,7 +155,7 @@ type PreloadData = {
unoptimized
:
boolean
width
:
number
|
undefined
sizes
?:
string
quality
?:
string
quality
?:
number
}
function
generatePreload
({
...
...
@@ -251,8 +251,10 @@ export default function Image({
}
},
[
thisEl
,
lazy
])
let
widthInt
=
getInt
(
width
)
let
heightInt
=
getInt
(
height
)
const
widthInt
=
getInt
(
width
)
const
heightInt
=
getInt
(
height
)
const
qualityInt
=
getInt
(
quality
)
let
divStyle
:
React
.
CSSProperties
|
undefined
let
imgStyle
:
React
.
CSSProperties
|
undefined
let
wrapperStyle
:
React
.
CSSProperties
|
undefined
...
...
@@ -305,12 +307,12 @@ export default function Image({
}
// Generate attribute values
const
imgSrc
=
computeSrc
(
src
,
unoptimized
,
widthInt
,
quality
)
const
imgSrc
=
computeSrc
(
src
,
unoptimized
,
widthInt
,
quality
Int
)
const
imgSrcSet
=
generateSrcSet
({
src
,
width
:
widthInt
,
unoptimized
,
quality
,
quality
:
qualityInt
,
})
let
imgAttributes
:
...
...
@@ -352,7 +354,7 @@ export default function Image({
width
:
widthInt
,
unoptimized
,
sizes
,
quality
,
quality
:
qualityInt
,
})
:
''
}
<
img
...
...
@@ -442,7 +444,5 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
}
}
return
`
${
root
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
quality
||
'
75
'
}
`
return
`
${
root
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
quality
||
75
}
`
}
test/integration/image-component/typescript/pages/valid.tsx
浏览文件 @
900afdc2
...
...
@@ -22,6 +22,18 @@ const Page = () => {
src
=
"https://via.placeholder.com/100"
unsized
></
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
>
</
div
>
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录