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

refactor(module:alert & card): refactor card & refactor template outlet #2532

Merged
merged 1 commit into from
Nov 26, 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
27 changes: 14 additions & 13 deletions components/alert/nz-alert.component.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<div [ngClass]="outerClassMap" *ngIf="display" [@fadeAnimation] (@fadeAnimation.done)="onFadeAnimationDone()">
<div *ngIf="display"
class="ant-alert"
[class.ant-alert-success]="nzType === 'success'"
[class.ant-alert-info]="nzType === 'info'"
[class.ant-alert-warning]="nzType === 'warning'"
[class.ant-alert-error]="nzType === 'error'"
[class.ant-alert-no-icon]="!nzShowIcon"
[class.ant-alert-banner]="nzBanner"
[class.ant-alert-with-description]="!!nzDescription"
[@fadeAnimation]
(@fadeAnimation.done)="onFadeAnimationDone()">
<ng-container *ngIf="nzShowIcon">
<i class="ant-alert-icon" [ngClass]="nzIconType" *ngIf="nzIconType; else iconTemplate"></i>
<ng-template #iconTemplate>
<i nz-icon class="ant-alert-icon" [type]="iconType" [theme]="iconTheme"></i>
</ng-template>
</ng-container>
<span class="ant-alert-message" *ngIf="nzMessage">
<ng-container *ngIf="isMessageString; else messageTemplate">{{ nzMessage }}</ng-container>
<ng-template #messageTemplate>
<ng-template [ngTemplateOutlet]="nzMessage"></ng-template>
</ng-template>
<ng-container *nzStringTemplateOutlet="nzMessage">{{ nzMessage }}</ng-container>
</span>
<span class="ant-alert-description" *ngIf="nzDescription">
<ng-container *ngIf="isDescriptionString; else descriptionTemplate">{{ nzDescription }}</ng-container>
<ng-template #descriptionTemplate>
<ng-template [ngTemplateOutlet]="nzDescription"></ng-template>
</ng-template>
<ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container>
</span>
<a *ngIf="nzCloseable || nzCloseText"
class="ant-alert-close-icon"
Expand All @@ -24,10 +28,7 @@
<i nz-icon type="close" class="anticon-close"></i>
</ng-template>
<ng-container *ngIf="nzCloseText; else closeDefaultTemplate">
<ng-container *ngIf="isCloseTextString; else closeTextTemplate">{{ nzCloseText }}</ng-container>
<ng-template #closeTextTemplate>
<ng-template [ngTemplateOutlet]="nzCloseText"></ng-template>
</ng-template>
<ng-container *nzStringTemplateOutlet="nzCloseText">{{ nzCloseText }}</ng-container>
</ng-container>
</a>
</div>
147 changes: 33 additions & 114 deletions components/alert/nz-alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import {
Component,
EventEmitter,
Input,
OnInit,
OnChanges,
Output,
SimpleChanges,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { fadeAnimation } from '../core/animation/fade-animations';
import { NgClassType } from '../core/types/ng-class';
import { toBoolean } from '../core/util/convert';
import { InputBoolean } from '../core/util/convert';

@Component({
selector : 'nz-alert',
Expand All @@ -25,108 +26,21 @@ import { toBoolean } from '../core/util/convert';
}`
]
})
export class NzAlertComponent implements OnInit {
export class NzAlertComponent implements OnChanges {
display = true;
isTypeSet = false;
isShowIconSet = false;
prefixClass = 'ant-alert';
isDescriptionString: boolean;
isMessageString: boolean;
isCloseTextString: boolean;
outerClassMap: NgClassType;
iconType: string;
iconTheme: string;
@Output()
readonly nzOnClose: EventEmitter<boolean> = new EventEmitter();
@Input()
nzIconType: NgClassType;
private _banner = false;
private _closeable = false;
private _showIcon = false;
private _type = 'info';
private _description: string | TemplateRef<void>;
private _message: string | TemplateRef<void>;
private _closeText: string | TemplateRef<void>;

@Input()
set nzDescription(value: string | TemplateRef<void>) {
this.isDescriptionString = !(value instanceof TemplateRef);
this._description = value;
this.updateOuterClassMap();
this.updateIconClassMap();
}

get nzDescription(): string | TemplateRef<void> {
return this._description;
}

@Input()
set nzCloseText(value: string | TemplateRef<void>) {
this.isCloseTextString = !(value instanceof TemplateRef);
this._closeText = value;
}

get nzCloseText(): string | TemplateRef<void> {
return this._closeText;
}

@Input()
set nzMessage(value: string | TemplateRef<void>) {
this.isMessageString = !(value instanceof TemplateRef);
this._message = value;
}

get nzMessage(): string | TemplateRef<void> {
return this._message;
}

@Input()
set nzType(value: string) {
this._type = value;
this.isTypeSet = true;
this.updateOuterClassMap();
this.updateIconClassMap();
}

get nzType(): string {
return this._type;
}

@Input()
set nzBanner(value: boolean) {
this._banner = toBoolean(value);
if (!this.isTypeSet) {
this.nzType = 'warning';
}
if (!this.isShowIconSet) {
this.nzShowIcon = true;
}
this.updateOuterClassMap();
}

get nzBanner(): boolean {
return this._banner;
}

@Input()
set nzCloseable(value: boolean) {
this._closeable = toBoolean(value);
}

get nzCloseable(): boolean {
return this._closeable;
}

@Input()
set nzShowIcon(value: boolean) {
this._showIcon = toBoolean(value);
this.isShowIconSet = true;
this.updateOuterClassMap();
}

get nzShowIcon(): boolean {
return this._showIcon;
}
iconType = 'info-circle';
iconTheme = 'fill';
@Output() readonly nzOnClose: EventEmitter<boolean> = new EventEmitter();
@Input() @InputBoolean() nzCloseable = false;
@Input() @InputBoolean() nzShowIcon = false;
@Input() @InputBoolean() nzBanner = false;
@Input() nzCloseText: string | TemplateRef<void>;
@Input() nzIconType: NgClassType;
@Input() nzMessage: string | TemplateRef<void>;
@Input() nzDescription: string | TemplateRef<void>;
@Input() nzType = 'info';

closeAlert(): void {
this.display = false;
Expand All @@ -138,16 +52,6 @@ export class NzAlertComponent implements OnInit {
}
}

updateOuterClassMap(): void {
this.outerClassMap = {
[ `${this.prefixClass}` ] : true,
[ `${this.prefixClass}-${this.nzType}` ] : true,
[ `${this.prefixClass}-no-icon` ] : !this.nzShowIcon,
[ `${this.prefixClass}-banner` ] : this.nzBanner,
[ `${this.prefixClass}-with-description` ]: !!this.nzDescription
};
}

updateIconClassMap(): void {
switch (this.nzType) {
case 'error':
Expand All @@ -170,8 +74,23 @@ export class NzAlertComponent implements OnInit {
}
}

ngOnInit(): void {
this.updateIconClassMap();
this.updateOuterClassMap();
ngOnChanges(changes: SimpleChanges): void {
if (changes.nzShowIcon) {
this.isShowIconSet = true;
}
if (changes.nzDescription || changes.nzType) {
this.updateIconClassMap();
}
if (changes.nzType) {
this.isTypeSet = true;
}
if (changes.nzBanner) {
if (!this.isTypeSet) {
this.nzType = 'warning';
}
if (!this.isShowIconSet) {
this.nzShowIcon = true;
}
}
}
}
3 changes: 2 additions & 1 deletion components/alert/nz-alert.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NzAddOnModule } from '../core/addon/addon.module';
import { NzIconModule } from '../icon/nz-icon.module';

import { NzAlertComponent } from './nz-alert.component';

@NgModule({
declarations: [ NzAlertComponent ],
exports : [ NzAlertComponent ],
imports : [ CommonModule, NzIconModule ]
imports : [ CommonModule, NzIconModule, NzAddOnModule ]
})
export class NzAlertModule {
}
10 changes: 2 additions & 8 deletions components/card/nz-card-meta.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
</div>
<div class="ant-card-meta-detail" *ngIf="nzTitle || nzDescription">
<div class="ant-card-meta-title" *ngIf="nzTitle">
<ng-container *ngIf="isTitleString; else titleTemplate">{{ nzTitle }}</ng-container>
<ng-template #titleTemplate>
<ng-template [ngTemplateOutlet]="nzTitle"></ng-template>
</ng-template>
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container>
</div>
<div class="ant-card-meta-description" *ngIf="nzDescription">
<ng-container *ngIf="isDescriptionString; else descriptionTemplate">{{ nzDescription }}</ng-container>
<ng-template #descriptionTemplate>
<ng-template [ngTemplateOutlet]="nzDescription"></ng-template>
</ng-template>
<ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container>
</div>
</div>
27 changes: 2 additions & 25 deletions components/card/nz-card-meta.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,7 @@ import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulati
}
})
export class NzCardMetaComponent {
isDescriptionString: boolean;
isTitleString: boolean;

@Input()
set nzTitle(value: string | TemplateRef<void>) {
this.isTitleString = !(value instanceof TemplateRef);
this._title = value;
}

get nzTitle(): string | TemplateRef<void> {
return this._title;
}

@Input()
set nzDescription(value: string | TemplateRef<void>) {
this.isDescriptionString = !(value instanceof TemplateRef);
this._description = value;
}

get nzDescription(): string | TemplateRef<void> {
return this._description;
}

@Input() nzTitle: string | TemplateRef<void>;
@Input() nzDescription: string | TemplateRef<void>;
@Input() nzAvatar: TemplateRef<void>;
private _title: string | TemplateRef<void>;
private _description: string | TemplateRef<void>;
}
12 changes: 3 additions & 9 deletions components/card/nz-card.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<ng-template #titleTemplate>
<ng-template [ngTemplateOutlet]="nzTitle"></ng-template>
</ng-template>
<ng-template #extraTemplate>
<ng-template [ngTemplateOutlet]="nzExtra"></ng-template>
</ng-template>
<div class="ant-card-head" *ngIf="nzTitle||nzExtra||tab">
<div class="ant-card-head" *ngIf="nzTitle || nzExtra || tab">
<div class="ant-card-head-wrapper">
<div class="ant-card-head-title" *ngIf="nzTitle">
<ng-container *ngIf="isTitleString; else titleTemplate">{{ nzTitle }}</ng-container>
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container>
</div>
<div class="ant-card-extra" *ngIf="nzExtra">
<ng-container *ngIf="isExtraString; else extraTemplate">{{ nzExtra }}</ng-container>
<ng-container *nzStringTemplateOutlet="nzExtra">{{ nzExtra }}</ng-container>
</div>
</div>
<ng-container *ngIf="tab">
Expand Down
50 changes: 10 additions & 40 deletions components/card/nz-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ChangeDetectionStrategy,
Component,
ContentChild,
HostBinding,
Input,
TemplateRef,
ViewEncapsulation
Expand All @@ -22,52 +21,23 @@ import { NzCardTabComponent } from './nz-card-tab.component';
}
` ],
host : {
'[class.ant-card]' : 'true',
'[class.ant-card-loading]': 'nzLoading'
'[class.ant-card]' : 'true',
'[class.ant-card-loading]' : 'nzLoading',
'[class.ant-card-bordered]' : 'nzBordered',
'[class.ant-card-hoverable]' : 'nzHoverable',
'[class.ant-card-type-inner]' : `nzType === 'inner'`,
'[class.ant-card-contain-tabs]': '!!tab'
}
})
export class NzCardComponent {
@Input() @InputBoolean() @HostBinding('class.ant-card-bordered') nzBordered = true;
@Input() @InputBoolean() nzBordered = true;
@Input() @InputBoolean() nzLoading = false;
@Input() @InputBoolean() @HostBinding('class.ant-card-hoverable') nzHoverable = false;
@Input() @InputBoolean() nzHoverable = false;
@Input() nzBodyStyle: { [ key: string ]: string };
@Input() nzCover: TemplateRef<void>;
@Input() nzActions: Array<TemplateRef<void>> = [];
@Input() nzType: string;
@Input() nzTitle: string | TemplateRef<void>;
@Input() nzExtra: string | TemplateRef<void>;
@ContentChild(NzCardTabComponent) tab: NzCardTabComponent;
isTitleString: boolean;
isExtraString: boolean;

@Input()
set nzTitle(value: string | TemplateRef<void>) {
this.isTitleString = !(value instanceof TemplateRef);
this._title = value;
}

get nzTitle(): string | TemplateRef<void> {
return this._title;
}

@Input()
set nzExtra(value: string | TemplateRef<void>) {
this.isExtraString = !(value instanceof TemplateRef);
this._extra = value;
}

get nzExtra(): string | TemplateRef<void> {
return this._extra;
}

@HostBinding('class.ant-card-type-inner')
get isInner(): boolean {
return this.nzType === 'inner';
}

@HostBinding('class.ant-card-contain-tabs')
get isTabs(): boolean {
return !!this.tab;
}

private _title: string | TemplateRef<void>;
private _extra: string | TemplateRef<void>;
}
Loading