Skip to content

Commit

Permalink
feat(module: nav-bar): add icon string support (NG-ZORRO#38)
Browse files Browse the repository at this point in the history
* feat(module: nav-bar): add icon string support

* feat(module: nav-bar): add icon string support
  • Loading branch information
nuonuoge authored and 3fuyu committed Oct 12, 2018
1 parent 0720fdc commit 4a89b0c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/nav-bar/nav-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div role="button" class="{{defaultProps.prefixCls}}-left" (click)="click($event)">
<ng-template *ngIf="!isLeftContentString" [ngTemplateOutlet]="leftContent"></ng-template>
<span *ngIf="icon" class="{{defaultProps.prefixCls}}-left-icon" aria-hidden="true">
<ng-template [ngTemplateOutlet]="icon"></ng-template>
<Icon *ngIf="isIconString" [type]="icon"></Icon>
<ng-template *ngIf="!isIconString" [ngTemplateOutlet]="icon"></ng-template>
</span>
{{isLeftContentString ? leftContent: null}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/nav-bar/nav-bar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('NavBarComponent', () => {
>
NavBar
</Navbar>
<Navbar [leftContent]="'leftContent'" [rightContent]="'rightContent'">NavBar1</Navbar>
<Navbar [icon]="'left'" [leftContent]="'leftContent'" [rightContent]="'rightContent'">NavBar1</Navbar>
<ng-template #icon>
<Icon [type]="'left'"></Icon>
Expand Down
12 changes: 9 additions & 3 deletions components/nav-bar/nav-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export class NavBarComponent {
onLeftClick: () => {}
};
navbarCls = {};
isIconString: boolean = true;
isLeftContentString: boolean = true;
isRightContentString: boolean = true;

private _icon: TemplateRef<any>;
private _icon: string | TemplateRef<any>;
private _leftContent: string | TemplateRef<any>;
private _rightContent: string | TemplateRef<any>;

Expand All @@ -25,10 +26,15 @@ export class NavBarComponent {
this._amNavbardark = this.defaultProps.mode === 'dark';
}
@Input()
get icon(): TemplateRef<any> {
get icon(): string | TemplateRef<any> {
return this._icon;
}
set icon(value: TemplateRef<any>) {
set icon(value: string | TemplateRef<any>) {
if (value instanceof TemplateRef) {
this.isIconString = false;
} else {
this.isIconString = true;
}
this._icon = value;
}
@Input()
Expand Down
3 changes: 2 additions & 1 deletion components/nav-bar/nav-bar.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IconModule } from '../icon/icon.module';
import { NavBarComponent } from './nav-bar.component';

@NgModule({
imports: [CommonModule],
imports: [CommonModule, IconModule],
exports: [NavBarComponent],
declarations: [NavBarComponent]
})
Expand Down

0 comments on commit 4a89b0c

Please sign in to comment.