Skip to content
This repository was archived by the owner on May 11, 2020. It is now read-only.

Commit e2d09a0

Browse files
cipchkvthinkxie
authored andcommitted
feat(module:list): list empty style (NG-ZORRO#2365)
close NG-ZORRO#2362
1 parent ee31a4e commit e2d09a0

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

components/list/demo/basic.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Component } from '@angular/core';
33
@Component({
44
selector: 'nz-demo-list-basic',
55
template: `
6-
<nz-list [nzDataSource]="data" [nzRenderItem]="item" [nzItemLayout]="'horizontal'">
6+
<div style="margin-bottom: 8px;"><button nz-button (click)="change()">Switch Data</button></div>
7+
<nz-list [nzDataSource]="data" [nzRenderItem]="item" [nzItemLayout]="'horizontal'" [nzLoading]="loading">
78
<ng-template #item let-item>
89
<nz-list-item>
910
<nz-list-item-meta
@@ -20,6 +21,7 @@ import { Component } from '@angular/core';
2021
`
2122
})
2223
export class NzDemoListBasicComponent {
24+
loading = false;
2325
data = [
2426
{
2527
title: 'Ant Design Title 1'
@@ -34,4 +36,32 @@ export class NzDemoListBasicComponent {
3436
title: 'Ant Design Title 4'
3537
}
3638
];
39+
40+
change(): void {
41+
this.loading = true;
42+
if (this.data.length > 0) {
43+
setTimeout(() => {
44+
this.data = [];
45+
this.loading = false;
46+
}, 1000);
47+
} else {
48+
setTimeout(() => {
49+
this.data = [
50+
{
51+
title: 'Ant Design Title 1'
52+
},
53+
{
54+
title: 'Ant Design Title 2'
55+
},
56+
{
57+
title: 'Ant Design Title 3'
58+
},
59+
{
60+
title: 'Ant Design Title 4'
61+
}
62+
];
63+
this.loading = false;
64+
}, 1000);
65+
}
66+
}
3767
}

components/list/list.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Component, DebugElement, TemplateRef, ViewChild } from '@angular/core';
2-
import { fakeAsync, tick, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44

55
import { NzIconModule } from '../icon/nz-icon.module';
66

7+
import { NzListComponent } from './nz-list.component';
78
import { NzListModule } from './nz-list.module';
89

910
describe('list', () => {
@@ -21,6 +22,12 @@ describe('list', () => {
2122
fixture.detectChanges();
2223
});
2324

25+
afterEach(() => {
26+
if (context.comp != null) {
27+
context.comp.ngOnDestroy();
28+
}
29+
});
30+
2431
describe('[fields]', () => {
2532

2633
describe('#nzItemLayout', () => {
@@ -116,8 +123,17 @@ describe('list', () => {
116123
});
117124
});
118125

119-
it('#nzDataSource', () => {
120-
expect(dl.queryAll(By.css('nz-list-item')).length).toBe(context.data.length);
126+
describe('#nzDataSource', () => {
127+
it('should working', () => {
128+
expect(dl.queryAll(By.css('nz-list-item')).length).toBe(context.data.length);
129+
});
130+
131+
it('should be render empty text when data source is empty', () => {
132+
expect(dl.queryAll(By.css('.ant-list-empty-text')).length).toBe(0);
133+
context.data = [];
134+
fixture.detectChanges();
135+
expect(dl.queryAll(By.css('.ant-list-empty-text')).length).toBe(1);
136+
});
121137
});
122138

123139
it('#nzGrid', () => {
@@ -204,6 +220,7 @@ describe('list', () => {
204220
`
205221
})
206222
class TestListComponent {
223+
@ViewChild('comp') comp: NzListComponent;
207224
nzItemLayout = 'horizontal';
208225
nzBordered = false;
209226
nzFooter = 'footer';

components/list/nz-list.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
[ngTemplateOutletContext]="{ $implicit: item, index: index }"></ng-template>
1919
</div>
2020
</div>
21+
<div *ngIf="!nzLoading && nzDataSource.length === 0" class="ant-list-empty-text">
22+
{{locale.emptyText}}
23+
</div>
2124
</nz-spin>
2225
<ng-template [ngTemplateOutlet]="nzLoadMore"></ng-template>
2326
<ng-content></ng-content>

components/list/nz-list.component.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import {
55
ElementRef,
66
Input,
77
OnChanges,
8+
OnDestroy,
9+
OnInit,
810
TemplateRef
911
} from '@angular/core';
12+
import { Subscription } from 'rxjs';
1013

1114
import { NzUpdateHostClassService } from '../core/services/update-host-class.service';
1215
import { InputBoolean } from '../core/util/convert';
16+
import { NzI18nService } from '../i18n/nz-i18n.service';
1317

1418
import { ListSize, NzListGrid } from './interface';
1519

@@ -29,7 +33,11 @@ import { ListSize, NzListGrid } from './interface';
2933
}
3034
` ]
3135
})
32-
export class NzListComponent implements OnChanges {
36+
export class NzListComponent implements OnInit, OnChanges, OnDestroy {
37+
/* tslint:disable-next-line:no-any */
38+
locale: any = {};
39+
private i18n$: Subscription;
40+
3341
// #region fields
3442
// tslint:disable-next-line:no-any
3543
@Input() nzDataSource: any[] = [];
@@ -107,10 +115,21 @@ export class NzListComponent implements OnChanges {
107115

108116
// #endregion
109117

110-
constructor(private el: ElementRef, private cd: ChangeDetectorRef, private updateHostClassService: NzUpdateHostClassService) {
118+
constructor(private el: ElementRef, private cd: ChangeDetectorRef, private updateHostClassService: NzUpdateHostClassService, private i18n: NzI18nService) {
119+
}
120+
121+
ngOnInit(): void {
122+
this.i18n$ = this.i18n.localeChange.subscribe(() => {
123+
this.locale = this.i18n.getLocaleData('Table');
124+
this.cd.detectChanges();
125+
});
111126
}
112127

113128
ngOnChanges(): void {
114129
this._setClassMap();
115130
}
131+
132+
ngOnDestroy(): void {
133+
this.i18n$.unsubscribe();
134+
}
116135
}

components/list/nz-list.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { NgModule } from '@angular/core';
33

44
import { NzAvatarModule } from '../avatar/nz-avatar.module';
55
import { NzGridModule } from '../grid/nz-grid.module';
6+
import { NzI18nModule } from '../i18n/nz-i18n.module';
67
import { NzSpinModule } from '../spin/nz-spin.module';
78

89
import { NzListItemMetaComponent } from './nz-list-item-meta.component';
910
import { NzListItemComponent } from './nz-list-item.component';
1011
import { NzListComponent } from './nz-list.component';
1112

1213
@NgModule({
13-
imports: [ CommonModule, NzSpinModule, NzGridModule, NzAvatarModule ],
14+
imports: [ CommonModule, NzSpinModule, NzGridModule, NzAvatarModule, NzI18nModule ],
1415
declarations: [ NzListComponent, NzListItemComponent, NzListItemMetaComponent ],
1516
exports: [ NzListComponent, NzListItemComponent, NzListItemMetaComponent ]
1617
})

0 commit comments

Comments
 (0)