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: nav-bar): add icon string support #38

Merged
merged 2 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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