33 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44 */
55
6- import { Direction , Directionality } from '@angular/cdk/bidi' ;
6+ import { Directionality } from '@angular/cdk/bidi' ;
77import {
88 ChangeDetectionStrategy ,
9- ChangeDetectorRef ,
109 Component ,
11- DestroyRef ,
10+ computed ,
1211 inject ,
13- Input ,
14- OnChanges ,
15- OnInit ,
12+ input ,
1613 TemplateRef ,
1714 ViewEncapsulation
1815} from '@angular/core' ;
19- import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
2016
2117import { NzOutletModule } from 'ng-zorro-antd/core/outlet' ;
2218import { NzIconModule } from 'ng-zorro-antd/icon' ;
@@ -29,7 +25,7 @@ export type NzResultIconType = 'success' | 'error' | 'info' | 'warning';
2925export type NzExceptionStatusType = '404' | '500' | '403' ;
3026export type NzResultStatusType = NzExceptionStatusType | NzResultIconType ;
3127
32- const IconMap = {
28+ const IconMap : Record < NzResultIconType , string > = {
3329 success : 'check-circle' ,
3430 error : 'close-circle' ,
3531 info : 'exclamation-circle' ,
@@ -42,16 +38,16 @@ const ExceptionStatus = ['404', '500', '403'];
4238 exportAs : 'nzResult' ,
4339 template : `
4440 <div class="ant-result-icon">
45- @if (!isException) {
46- @if (icon) {
47- <ng-container *nzStringTemplateOutlet="icon; let icon">
41+ @if (!isException() ) {
42+ @if (icon() ) {
43+ <ng-container *nzStringTemplateOutlet="icon() ; let icon">
4844 <nz-icon [nzType]="icon" nzTheme="fill" />
4945 </ng-container>
5046 } @else {
5147 <ng-content select="[nz-result-icon]"></ng-content>
5248 }
5349 } @else {
54- @switch (nzStatus) {
50+ @switch (nzStatus() ) {
5551 @case ('404') {
5652 <nz-result-not-found />
5753 }
@@ -64,37 +60,32 @@ const ExceptionStatus = ['404', '500', '403'];
6460 }
6561 }
6662 </div>
67- @if (nzTitle) {
68- <div class="ant-result-title" *nzStringTemplateOutlet="nzTitle">
69- {{ nzTitle }}
63+ @if (nzTitle() ) {
64+ <div class="ant-result-title" *nzStringTemplateOutlet="nzTitle() ">
65+ {{ nzTitle() }}
7066 </div>
7167 } @else {
7268 <ng-content select="div[nz-result-title]"></ng-content>
7369 }
7470
75- @if (nzSubTitle) {
76- <div class="ant-result-subtitle" *nzStringTemplateOutlet="nzSubTitle">
77- {{ nzSubTitle }}
71+ @if (nzSubTitle() ) {
72+ <div class="ant-result-subtitle" *nzStringTemplateOutlet="nzSubTitle() ">
73+ {{ nzSubTitle() }}
7874 </div>
7975 } @else {
8076 <ng-content select="div[nz-result-subtitle]"></ng-content>
8177 }
8278 <ng-content select="nz-result-content, [nz-result-content]"></ng-content>
83- @if (nzExtra) {
84- <div class="ant-result-extra" *nzStringTemplateOutlet="nzExtra">
85- {{ nzExtra }}
79+ @if (nzExtra() ) {
80+ <div class="ant-result-extra" *nzStringTemplateOutlet="nzExtra() ">
81+ {{ nzExtra() }}
8682 </div>
8783 } @else {
8884 <ng-content select="div[nz-result-extra]"></ng-content>
8985 }
9086 ` ,
9187 host : {
92- class : 'ant-result' ,
93- '[class.ant-result-success]' : `nzStatus === 'success'` ,
94- '[class.ant-result-error]' : `nzStatus === 'error'` ,
95- '[class.ant-result-info]' : `nzStatus === 'info'` ,
96- '[class.ant-result-warning]' : `nzStatus === 'warning'` ,
97- '[class.ant-result-rtl]' : `dir === 'rtl'`
88+ '[class]' : 'class()'
9889 } ,
9990 imports : [
10091 NzOutletModule ,
@@ -106,44 +97,26 @@ const ExceptionStatus = ['404', '500', '403'];
10697 changeDetection : ChangeDetectionStrategy . OnPush ,
10798 encapsulation : ViewEncapsulation . None
10899} )
109- export class NzResultComponent implements OnChanges , OnInit {
110- private cdr = inject ( ChangeDetectorRef ) ;
111- private directionality = inject ( Directionality ) ;
112- private destroyRef = inject ( DestroyRef ) ;
100+ export class NzResultComponent {
101+ private readonly dir = inject ( Directionality ) . valueSignal ;
113102
114- @ Input ( ) nzIcon ?: string | TemplateRef < void > ;
115- @ Input ( ) nzTitle ?: string | TemplateRef < void > ;
116- @ Input ( ) nzStatus : NzResultStatusType = 'info' ;
117- @ Input ( ) nzSubTitle ?: string | TemplateRef < void > ;
118- @ Input ( ) nzExtra ?: string | TemplateRef < void > ;
103+ readonly nzIcon = input < string | TemplateRef < void > > ( ) ;
104+ readonly nzTitle = input < string | TemplateRef < void > > ( ) ;
105+ readonly nzSubTitle = input < string | TemplateRef < void > > ( ) ;
106+ readonly nzExtra = input < string | TemplateRef < void > > ( ) ;
107+ readonly nzStatus = input < NzResultStatusType > ( 'info' ) ;
119108
120- icon ?: string | TemplateRef < void > ;
121- isException = false ;
122- dir : Direction = 'ltr' ;
109+ protected readonly class = computed ( ( ) => {
110+ return {
111+ 'ant-result' : true ,
112+ [ `ant-result-${ this . nzStatus ( ) } ` ] : true ,
113+ 'ant-result-rtl' : this . dir ( ) === 'rtl'
114+ } ;
115+ } ) ;
123116
124- ngOnInit ( ) : void {
125- this . directionality . change ?. pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( direction => {
126- this . dir = direction ;
127- this . cdr . detectChanges ( ) ;
128- } ) ;
129-
130- this . dir = this . directionality . value ;
131- }
132-
133- ngOnChanges ( ) : void {
134- this . setStatusIcon ( ) ;
135- }
136-
137- private setStatusIcon ( ) : void {
138- const icon = this . nzIcon ;
139-
140- this . isException = ExceptionStatus . indexOf ( this . nzStatus ) !== - 1 ;
141- this . icon = icon
142- ? typeof icon === 'string'
143- ? IconMap [ icon as NzResultIconType ] || icon
144- : icon
145- : this . isException
146- ? undefined
147- : IconMap [ this . nzStatus as NzResultIconType ] ;
148- }
117+ readonly isException = computed ( ( ) => ExceptionStatus . indexOf ( this . nzStatus ( ) ) !== - 1 ) ;
118+ readonly icon = computed ( ( ) => {
119+ const icon = this . nzIcon ( ) ;
120+ return typeof icon === 'string' ? IconMap [ icon as NzResultIconType ] || icon : icon ;
121+ } ) ;
149122}
0 commit comments