forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(module:card): refactor card (NG-ZORRO#4778)
- Loading branch information
Showing
18 changed files
with
215 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-card-loading', | ||
exportAs: 'nzCardLoading', | ||
template: ` | ||
<div class="ant-card-loading-content"> | ||
<div class="ant-row" style="margin-left: -4px; margin-right: -4px;" *ngFor="let listOfClassName of listOfLoading"> | ||
<div *ngFor="let className of listOfClassName" [class]="className" style="padding-left: 4px; padding-right: 4px;"> | ||
<div class="ant-card-loading-block"></div> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
preserveWhitespaces: false, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
host: { | ||
'[class.ant-card-loading-content]': 'true' | ||
} | ||
}) | ||
export class NzCardLoadingComponent { | ||
listOfLoading: string[][] = [ | ||
['ant-col-22'], | ||
['ant-col-8', 'ant-col-15'], | ||
['ant-col-6', 'ant-col-18'], | ||
['ant-col-13', 'ant-col-9'], | ||
['ant-col-4', 'ant-col-3', 'ant-col-16'], | ||
['ant-col-8', 'ant-col-6', 'ant-col-8'] | ||
]; | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulation } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-card-meta', | ||
exportAs: 'nzCardMeta', | ||
preserveWhitespaces: false, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
template: ` | ||
<div class="ant-card-meta-avatar" *ngIf="nzAvatar"> | ||
<ng-template [ngTemplateOutlet]="nzAvatar"></ng-template> | ||
</div> | ||
<div class="ant-card-meta-detail" *ngIf="nzTitle || nzDescription"> | ||
<div class="ant-card-meta-title" *ngIf="nzTitle"> | ||
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container> | ||
</div> | ||
<div class="ant-card-meta-description" *ngIf="nzDescription"> | ||
<ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container> | ||
</div> | ||
</div> | ||
`, | ||
host: { | ||
'[class.ant-card-meta]': 'true' | ||
} | ||
}) | ||
export class NzCardMetaComponent { | ||
@Input() nzTitle: string | TemplateRef<void> | null = null; | ||
@Input() nzDescription: string | TemplateRef<void> | null = null; | ||
@Input() nzAvatar: TemplateRef<void> | null = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
ContentChild, | ||
ContentChildren, | ||
Input, | ||
OnDestroy, | ||
QueryList, | ||
TemplateRef, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
import { InputBoolean, NzConfigService, NzSizeDSType, WithConfig } from 'ng-zorro-antd/core'; | ||
import { Subject } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { NzCardGridDirective } from './card-grid.directive'; | ||
import { NzCardTabComponent } from './card-tab.component'; | ||
|
||
const NZ_CONFIG_COMPONENT_NAME = 'card'; | ||
|
||
@Component({ | ||
selector: 'nz-card', | ||
exportAs: 'nzCard', | ||
preserveWhitespaces: false, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
template: ` | ||
<div class="ant-card-head" *ngIf="nzTitle || nzExtra || listOfNzCardTabComponent"> | ||
<div class="ant-card-head-wrapper"> | ||
<div class="ant-card-head-title" *ngIf="nzTitle"> | ||
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container> | ||
</div> | ||
<div class="ant-card-extra" *ngIf="nzExtra"> | ||
<ng-container *nzStringTemplateOutlet="nzExtra">{{ nzExtra }}</ng-container> | ||
</div> | ||
</div> | ||
<ng-container *ngIf="listOfNzCardTabComponent"> | ||
<ng-template [ngTemplateOutlet]="listOfNzCardTabComponent.template"></ng-template> | ||
</ng-container> | ||
</div> | ||
<div class="ant-card-cover" *ngIf="nzCover"> | ||
<ng-template [ngTemplateOutlet]="nzCover"></ng-template> | ||
</div> | ||
<div class="ant-card-body" [ngStyle]="nzBodyStyle"> | ||
<ng-container *ngIf="!nzLoading; else loadingTemplate"> | ||
<ng-content></ng-content> | ||
</ng-container> | ||
<ng-template #loadingTemplate> | ||
<nz-card-loading></nz-card-loading> | ||
</ng-template> | ||
</div> | ||
<ul class="ant-card-actions" *ngIf="nzActions.length"> | ||
<li *ngFor="let action of nzActions" [style.width.%]="100 / nzActions.length"> | ||
<span><ng-template [ngTemplateOutlet]="action"></ng-template></span> | ||
</li> | ||
</ul> | ||
`, | ||
host: { | ||
'[class.ant-card]': 'true', | ||
'[class.ant-card-loading]': 'nzLoading', | ||
'[class.ant-card-bordered]': 'nzBordered', | ||
'[class.ant-card-hoverable]': 'nzHoverable', | ||
'[class.ant-card-small]': 'nzSize === "small"', | ||
'[class.ant-card-contain-grid]': 'listOfNzCardGridDirective && listOfNzCardGridDirective.length', | ||
'[class.ant-card-type-inner]': 'nzType === "inner"', | ||
'[class.ant-card-contain-tabs]': '!!listOfNzCardTabComponent' | ||
} | ||
}) | ||
export class NzCardComponent implements OnDestroy { | ||
@Input() @WithConfig(NZ_CONFIG_COMPONENT_NAME, true) @InputBoolean() nzBordered: boolean; | ||
@Input() @InputBoolean() nzLoading = false; | ||
@Input() @WithConfig(NZ_CONFIG_COMPONENT_NAME, false) @InputBoolean() nzHoverable: boolean; | ||
@Input() nzBodyStyle: { [key: string]: string }; | ||
@Input() nzCover: TemplateRef<void>; | ||
@Input() nzActions: Array<TemplateRef<void>> = []; | ||
@Input() nzType: string | 'inner' | null = null; | ||
@Input() @WithConfig(NZ_CONFIG_COMPONENT_NAME, 'default') nzSize: NzSizeDSType; | ||
@Input() nzTitle: string | TemplateRef<void>; | ||
@Input() nzExtra: string | TemplateRef<void>; | ||
@ContentChild(NzCardTabComponent, { static: false }) listOfNzCardTabComponent: NzCardTabComponent; | ||
@ContentChildren(NzCardGridDirective) listOfNzCardGridDirective: QueryList<NzCardGridDirective>; | ||
private destroy$ = new Subject(); | ||
|
||
constructor(public nzConfigService: NzConfigService, private cdr: ChangeDetectorRef) { | ||
this.nzConfigService | ||
.getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME) | ||
.pipe(takeUntil(this.destroy$)) | ||
.subscribe(() => { | ||
this.cdr.markForCheck(); | ||
}); | ||
} | ||
ngOnDestroy(): void { | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.