Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:image): add nz-image component #6572

Conversation

stygian-desolator
Copy link
Collaborator

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Application (the showcase website) / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@stygian-desolator stygian-desolator marked this pull request as draft April 2, 2021 13:25
@codecov
Copy link

codecov bot commented Apr 3, 2021

Codecov Report

Merging #6572 (46e8d36) into master (bc0e468) will decrease coverage by 0.04%.
The diff coverage is 77.33%.

❗ Current head 46e8d36 differs from pull request most recent head 91bcada. Consider uploading reports for the commit 91bcada to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6572      +/-   ##
==========================================
- Coverage   89.88%   89.83%   -0.05%     
==========================================
  Files         481      483       +2     
  Lines       15374    15438      +64     
  Branches     2343     2349       +6     
==========================================
+ Hits        13819    13869      +50     
- Misses        937      948      +11     
- Partials      618      621       +3     
Impacted Files Coverage Δ
components/core/config/config.ts 100.00% <ø> (ø)
components/image/image.module.ts 100.00% <ø> (ø)
components/select/select.component.ts 87.09% <66.66%> (ø)
components/image/image.component.ts 74.19% <74.19%> (ø)
components/image/image-loader.ts 100.00% <100.00%> (ø)
components/select/option-group.component.ts 100.00% <100.00%> (ø)
components/select/option-item-group.component.ts 100.00% <100.00%> (ø)
components/select/option-item.component.ts 93.10% <100.00%> (ø)
components/select/option.component.ts 100.00% <100.00%> (ø)
components/select/select-item.component.ts 93.33% <100.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc0e468...91bcada. Read the comment docs.

@stygian-desolator
Copy link
Collaborator Author

@hsuanxyz pls help me review this, thx~


## zh-CN

添加 `nzPreload` 可以在服务端渲染下预先加载该图片。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
添加 `nzPreload` 可以在服务端渲染下预先加载该图片。
添加 `nzPreload` 可以在服务端渲染下添加 [preload](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content)


## en-US

Adding `nzPreload` will preload the image under server-side rendering.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Adding `nzPreload` will preload the image under server-side rendering.
Using `nzPreload` will add (preload)[https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content] under server-side rendering.

|nzHeight | Height | `number\|string` | `auto` | |
|nzLoader | Loader | `NzImageLoader` | `defaultLoader` | ✅ |
|nzOptimize | Whether to optimize image loading | `boolean` | `false` | ✅ |
|nzPreload | Whether to preload image | `boolean` | `false` | ✅ |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|nzPreload | Whether to preload image | `boolean` | `false` ||
|nzPreload | Whether to add [preload](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content) (only SSR) | `boolean` | `false` ||

|nzHeight | 高度 | `number\|string` | `auto` | |
|nzLoader | 图片加载器 | `NzImageLoader` | `defaultLoader` | ✅ |
|nzOptimize | 是否优化图片加载 | `boolean` | `false` | ✅ |
|nzPreload | 是否预加载图片 | `boolean` | `false` | ✅ |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|nzPreload | 是否预加载图片 | `boolean` | `false` ||
|nzPreload | 是否添加 [preload](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content) | `boolean` | `false` ||

@Input() @WithConfig() nzOptimizeSizes: number[] = [16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840];

get width(): number {
return typeof this.nzWidth === 'number' ? this.nzWidth : parseInt(this.nzWidth, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nzWidth default value is auto will be return NaN (parseInt('auto', 10)).

Comment on lines +109 to +110
const headNode = this.document.getElementsByTagName('head')[0] as HTMLHeadElement;
this.render.appendChild(headNode, linkNode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const headNode = this.document.getElementsByTagName('head')[0] as HTMLHeadElement;
this.render.appendChild(headNode, linkNode);
this.renderer.appendChild(this.document.head, linkNode);

.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.cdr.markForCheck();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything forgot here?

@@ -69,3 +81,13 @@ Other attributes [<img\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Elem
| prev(): void | Previous image |
| next(): void | Next image |
| close(): void | Close image preview |

### NzImageLoader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More details are needed here. And we also need the built-in loaders.

...new Set(
// 2x scale is sufficient
// https://blog.twitter.com/engineering/en_us/topics/infrastructure/2019/capping-image-fidelity-on-ultra-high-resolution-devices.html
[width, width * 2].map(w => allSizes.find(p => p >= w) || allSizes[allSizes.length - 1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[width, width * 2].map(w => allSizes.find(p => p >= w) || allSizes[allSizes.length - 1])
[width, width * 2].map(w => allSizes.find(p => p >= w) || w)

}

private preload(): void {
if (isPlatformServer(this.platformId)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private genSrc(): void {
if (!this.nzOptimize) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here need to determine the svg or data

@stygian-desolator stygian-desolator marked this pull request as draft April 10, 2021 02:53
@stygian-desolator
Copy link
Collaborator Author

I submitted a new Pull Request, this will be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants