-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
ribbon.component.ts
53 lines (48 loc) · 1.57 KB
/
ribbon.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
/**
* 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,
OnChanges,
SimpleChanges,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { badgePresetColors } from './preset-colors';
@Component({
selector: 'nz-ribbon',
exportAs: 'nzRibbon',
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-content></ng-content>
<div
class="ant-ribbon"
[class]="presetColor && 'ant-ribbon-color-' + presetColor"
[class.ant-ribbon-placement-end]="nzPlacement === 'end'"
[class.ant-ribbon-placement-start]="nzPlacement === 'start'"
[style.background-color]="!presetColor && nzColor"
>
<ng-container *nzStringTemplateOutlet="nzText">{{ nzText }}</ng-container>
<div class="ant-ribbon-corner" [style.color]="!presetColor && nzColor"></div>
</div>
`,
host: { class: 'ant-ribbon-wrapper' }
})
export class NzRibbonComponent implements OnChanges {
@Input() nzColor: string | undefined;
@Input() nzPlacement: 'start' | 'end' = 'end';
@Input() nzText: string | TemplateRef<void> | null = null;
presetColor: string | null = null;
constructor() {}
ngOnChanges(changes: SimpleChanges): void {
const { nzColor } = changes;
if (nzColor) {
this.presetColor = this.nzColor && badgePresetColors.indexOf(this.nzColor) !== -1 ? this.nzColor : null;
}
}
}