forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(module:empty): refactor (NG-ZORRO#4726)
* chore(module:empty): refactor feat(module:empty): add no description feature refactor(module:empty): remove empty service fix(module:empty): fix spec fix: fix spec import path * fix: fix empty content detection is triggered too late * test: skip falsy value test * chore: remove redundant type check
- Loading branch information
Wendell
authored
Feb 12, 2020
1 parent
6d2a80e
commit 048902e
Showing
22 changed files
with
342 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { InjectionToken, TemplateRef, Type } from '@angular/core'; | ||
|
||
export type NzEmptySize = 'normal' | 'small' | ''; | ||
|
||
// tslint:disable-next-line:no-any | ||
export type NzEmptyCustomContent = Type<any> | TemplateRef<any> | string; | ||
|
||
export const NZ_EMPTY_COMPONENT_NAME = new InjectionToken<string>('nz-empty-component-name'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: 2 | ||
order: 3 | ||
title: | ||
zh-CN: 全局化配置 | ||
en-US: Default Config | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: 1 | ||
order: 2 | ||
title: | ||
zh-CN: 自定义 | ||
en-US: Customize | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 4 | ||
title: | ||
zh-CN: 无描述 | ||
en-US: No description | ||
--- | ||
|
||
## zh-CN | ||
|
||
无描述展示。 | ||
|
||
## en-US | ||
|
||
Simplest Usage with no description. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-empty-description', | ||
template: ` | ||
<nz-empty [nzNotFoundContent]="null"></nz-empty> | ||
` | ||
}) | ||
export class NzDemoEmptyDescriptionComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 1 | ||
title: | ||
zh-CN: 选择图片 | ||
en-US: Chose image | ||
--- | ||
|
||
## zh-CN | ||
|
||
可以通过设置 `nzNotFoundImage` 为 `simple` 选择另一种风格的图片。 | ||
|
||
## en-US | ||
|
||
You can choose another style of `image` by setting `simple` to `nzNotFoundImage`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-empty-simple', | ||
template: ` | ||
<nz-empty nzNotFoundImage="simple"></nz-empty> | ||
` | ||
}) | ||
export class NzDemoEmptySimpleComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Input, | ||
OnChanges, | ||
OnDestroy, | ||
OnInit, | ||
SimpleChanges, | ||
TemplateRef, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
|
||
import { NzI18nService } from 'ng-zorro-antd/i18n'; | ||
|
||
const NzEmptyDefaultImages = ['default', 'simple'] as const; | ||
type NzEmptyNotFoundImageType = typeof NzEmptyDefaultImages[number] | null | string | TemplateRef<void>; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
selector: 'nz-empty', | ||
exportAs: 'nzEmpty', | ||
styles: ['nz-empty { display: block; }'], | ||
template: ` | ||
<div class="ant-empty-image"> | ||
<ng-container *ngIf="!isImageBuildIn"> | ||
<ng-container *nzStringTemplateOutlet="nzNotFoundImage"> | ||
<img [src]="nzNotFoundImage" [alt]="isContentString ? nzNotFoundContent : 'empty'" /> | ||
</ng-container> | ||
</ng-container> | ||
<nz-empty-default *ngIf="isImageBuildIn && nzNotFoundImage !== 'simple'"></nz-empty-default> | ||
<nz-empty-simple *ngIf="isImageBuildIn && nzNotFoundImage === 'simple'"></nz-empty-simple> | ||
</div> | ||
<p class="ant-empty-description" *ngIf="nzNotFoundContent !== null"> | ||
<ng-container *nzStringTemplateOutlet="nzNotFoundContent"> | ||
{{ isContentString ? nzNotFoundContent : locale['description'] }} | ||
</ng-container> | ||
</p> | ||
<div class="ant-empty-footer" *ngIf="nzNotFoundFooter"> | ||
<ng-container *nzStringTemplateOutlet="nzNotFoundFooter"> | ||
{{ nzNotFoundFooter }} | ||
</ng-container> | ||
</div> | ||
`, | ||
host: { | ||
class: 'ant-empty' | ||
} | ||
}) | ||
export class NzEmptyComponent implements OnChanges, OnInit, OnDestroy { | ||
@Input() nzNotFoundImage: NzEmptyNotFoundImageType = 'default'; | ||
@Input() nzNotFoundContent: string | TemplateRef<void> | null; | ||
@Input() nzNotFoundFooter: string | TemplateRef<void>; | ||
|
||
isContentString = false; | ||
isImageBuildIn = true; | ||
locale: { [key: string]: string } = {}; | ||
|
||
private readonly destroy$ = new Subject<void>(); | ||
|
||
constructor(private i18n: NzI18nService, private cdr: ChangeDetectorRef) {} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
const { nzNotFoundContent, nzNotFoundImage } = changes; | ||
|
||
if (nzNotFoundContent) { | ||
const content = nzNotFoundContent.currentValue; | ||
this.isContentString = typeof content === 'string'; | ||
} | ||
|
||
if (nzNotFoundImage) { | ||
const image = nzNotFoundImage.currentValue || 'default'; | ||
this.isImageBuildIn = NzEmptyDefaultImages.findIndex(i => i === image) > -1; | ||
} | ||
} | ||
|
||
ngOnInit(): void { | ||
this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(() => { | ||
this.locale = this.i18n.getLocaleData('Empty'); | ||
this.cdr.markForCheck(); | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.