Skip to content

Commit

Permalink
feat(module: list): renderHeader&renderFooter support String and Temp… (
Browse files Browse the repository at this point in the history
  • Loading branch information
3fuyu authored and fisherspy committed Mar 1, 2019
1 parent 1d53a15 commit 546b38d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions components/calendar/calendar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ describe('CalendarComponent', () => {
component.state.show = true;
component.state.showShortcut = true;
const disableDay = new Date().getDate() + '';
component.state.now = new Date();
fixture.detectChanges();
calendarEle.nativeElement.querySelectorAll('calendarshortcutpanel .item')[3].click();
calendarEle.nativeElement.querySelectorAll('calendarshortcutpanel .item')[2].click();
Expand Down
4 changes: 2 additions & 2 deletions components/list/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ A single and continuous block content is vertically arranged to display current

Properties | Descrition | Type | Default
-----------|------------|------|--------
| renderHeader | list heder | (): void | <span> </span> |
| renderFooter | list footer | (): void | <span> </span> |
| renderHeader | list heder | String/TemplateRef/Function | <span> </span> |
| renderFooter | list footer | String/TemplateRef/Function | <span> </span> |

### List.Item

Expand Down
4 changes: 2 additions & 2 deletions components/list/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ subtitle: 列表

属性 | 说明 | 类型 | 默认值
----|-----|------|------
| renderHeader | list heder | (): void ||
| renderFooter | list footer | (): void ||
| renderHeader | list heder | String/TemplateRef/Function ||
| renderFooter | list footer | String/TemplateRef/Function ||

### List.Item

Expand Down
21 changes: 16 additions & 5 deletions components/list/list.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<div *ngIf="renderHeader" class="{{defaultProps.prefixCls}}-header">
{{renderHeader()}}
<div *ngIf="renderHeader && renderHeaderType === 'string'"
class="{{defaultProps.prefixCls}}-header"
[innerHTML]="renderHeader">
</div>
<div *ngIf="renderHeader && renderHeaderType === 'function'"
class="{{defaultProps.prefixCls}}-header">{{renderHeader()}}
</div>
<ng-template *ngIf="renderHeader && renderHeaderType === 'templateRef'" [ngTemplateOutlet]="renderHeader">
</ng-template>
<div class="{{defaultProps.prefixCls}}-body">
<ng-content></ng-content>
</div>
<div *ngIf="renderFooter" class="{{defaultProps.prefixCls}}-footer">
{{renderFooter()}}
<div *ngIf="renderFooter && renderFooterType === 'string'"
class="{{defaultProps.prefixCls}}-footer"
[innerHTML]="renderFooter">
</div>
<div *ngIf="renderFooter && renderFooterType === 'function'"
class="{{defaultProps.prefixCls}}-footer">{{renderFooter()}}
</div>

<ng-template *ngIf="renderFooter && renderFooterType === 'templateRef'" [ngTemplateOutlet]="renderFooter">
</ng-template>
22 changes: 19 additions & 3 deletions components/list/list.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewEncapsulation, Input, HostBinding } from '@angular/core';
import { Component, ViewEncapsulation, Input, HostBinding, TemplateRef } from '@angular/core';

@Component({
selector: 'List, nzm-list',
Expand All @@ -10,6 +10,9 @@ export class List {
prefixCls: 'am-list'
};

renderHeaderType: string = '';
renderFooterType: string = '';

private _renderHeader: any = '';
private _renderFooter: any = '';
private _className: string = '';
Expand All @@ -22,14 +25,27 @@ export class List {
get renderHeader() {
return this._renderHeader;
}
set renderHeader(value) {
set renderHeader(value: string | Function | TemplateRef<any>) {
if (value instanceof TemplateRef) {
this.renderHeaderType = 'templateRef';
} else {
this.renderHeaderType = typeof value;
}
console.log('this isi rend', this.renderHeaderType);

this._renderHeader = value;
}
@Input()
get renderFooter() {
return this._renderFooter;
}
set renderFooter(value) {
set renderFooter(value: string | Function | TemplateRef<any>) {
if (value instanceof TemplateRef) {
this.renderFooterType = 'templateRef';
} else {
this.renderFooterType = typeof value;
}

this._renderFooter = value;
}

Expand Down

0 comments on commit 546b38d

Please sign in to comment.