-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
card.component.ts
executable file
·131 lines (121 loc) · 4.74 KB
/
card.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* 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 { Direction, Directionality } from '@angular/cdk/bidi';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ContentChild,
ContentChildren,
Input,
OnDestroy,
OnInit,
Optional,
QueryList,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { BooleanInput, NgStyleInterface, NzSizeDSType } from 'ng-zorro-antd/core/types';
import { InputBoolean } from 'ng-zorro-antd/core/util';
import { NzCardGridDirective } from './card-grid.directive';
import { NzCardTabComponent } from './card-tab.component';
const NZ_CONFIG_MODULE_NAME: NzConfigKey = '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',
'[class.ant-card-loading]': 'nzLoading',
'[class.ant-card-bordered]': 'nzBorderless === false && 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',
'[class.ant-card-rtl]': `dir === 'rtl'`
}
})
export class NzCardComponent implements OnDestroy, OnInit {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
static ngAcceptInputType_nzBordered: BooleanInput;
static ngAcceptInputType_nzBorderless: BooleanInput;
static ngAcceptInputType_nzLoading: BooleanInput;
static ngAcceptInputType_nzHoverable: BooleanInput;
@Input() @WithConfig() @InputBoolean() nzBordered: boolean = true;
@Input() @WithConfig() @InputBoolean() nzBorderless: boolean = false;
@Input() @InputBoolean() nzLoading = false;
@Input() @WithConfig() @InputBoolean() nzHoverable: boolean = false;
@Input() nzBodyStyle: NgStyleInterface | null = null;
@Input() nzCover?: TemplateRef<void>;
@Input() nzActions: Array<TemplateRef<void>> = [];
@Input() nzType: string | 'inner' | null = null;
@Input() @WithConfig() nzSize: NzSizeDSType = 'default';
@Input() nzTitle?: string | TemplateRef<void>;
@Input() nzExtra?: string | TemplateRef<void>;
@ContentChild(NzCardTabComponent, { static: false }) listOfNzCardTabComponent?: NzCardTabComponent;
@ContentChildren(NzCardGridDirective) listOfNzCardGridDirective!: QueryList<NzCardGridDirective>;
dir: Direction = 'ltr';
private destroy$ = new Subject();
constructor(
public nzConfigService: NzConfigService,
private cdr: ChangeDetectorRef,
@Optional() private directionality: Directionality
) {
this.nzConfigService
.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.cdr.markForCheck();
});
}
ngOnInit(): void {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
this.cdr.detectChanges();
});
this.dir = this.directionality.value;
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}