Skip to content

Commit b44c27f

Browse files
committed
refactor(toast): use @input() transform
1 parent 4274af0 commit b44c27f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

projects/coreui-angular/src/lib/toast/toast/toast.component.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import {
2+
booleanAttribute,
23
ChangeDetectorRef,
34
Component,
45
ElementRef,
56
EventEmitter,
67
HostBinding,
78
HostListener,
89
Input,
10+
numberAttribute,
911
OnDestroy,
1012
OnInit,
1113
Output,
1214
Renderer2
1315
} from '@angular/core';
1416

1517
import { animate, state, style, transition, trigger } from '@angular/animations';
16-
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
1718

1819
import { Colors } from '../../coreui.types';
1920
import { ToasterService } from '../toaster/toaster.service';
@@ -23,7 +24,7 @@ type AnimateType = ('hide' | 'show');
2324

2425
@Component({
2526
selector: 'c-toast',
26-
template: '<ng-content></ng-content>',
27+
template: '<ng-content />',
2728
styleUrls: ['./toast.component.scss'],
2829
exportAs: 'cToast',
2930
standalone: true,
@@ -51,8 +52,6 @@ type AnimateType = ('hide' | 'show');
5152
})
5253
export class ToastComponent implements OnInit, OnDestroy {
5354

54-
static ngAcceptInputType_visible: BooleanInput;
55-
5655
public dynamic!: boolean;
5756
public placement!: TToasterPlacement;
5857

@@ -79,7 +78,7 @@ export class ToastComponent implements OnInit, OnDestroy {
7978
* Delay hiding the toast (ms).
8079
* @type number
8180
*/
82-
@Input() delay: number = 5000;
81+
@Input({ transform: numberAttribute }) delay: number = 5000;
8382

8483
/**
8584
* Apply fade transition to the toast.
@@ -91,9 +90,9 @@ export class ToastComponent implements OnInit, OnDestroy {
9190
* Toggle the visibility of component.
9291
* @type boolean
9392
*/
94-
@Input()
93+
@Input({ transform: booleanAttribute })
9594
set visible(value: boolean) {
96-
const newValue = coerceBooleanProperty(value);
95+
const newValue = value;
9796
if (this._visible !== newValue) {
9897
this._visible = newValue;
9998
newValue ? this.setTimer() : this.clearTimer();
@@ -111,7 +110,7 @@ export class ToastComponent implements OnInit, OnDestroy {
111110
/**
112111
* @ignore
113112
*/
114-
@Input() index?: number;
113+
@Input({ transform: numberAttribute }) index?: number;
115114

116115
/**
117116
* Event emitted on visibility change. [docs]

0 commit comments

Comments
 (0)