Skip to content

Commit 8deeabf

Browse files
committed
refactor(alert): dismissible getter for backward compatibility
1 parent 2fa6d83 commit 8deeabf

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

projects/coreui-angular/src/lib/alert/alert.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@if (visible || !hide()) {
2-
@if (dismissible()) {
2+
@if (dismissible) {
33
<ng-container *ngTemplateOutlet="templates()?.['alertButtonCloseTemplate'] || defaultAlertButtonCloseTemplate" />
44
}
55
<ng-content />

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
Component,
44
computed,
55
contentChildren,
6-
effect,
76
input,
7+
linkedSignal,
88
output,
99
signal,
1010
TemplateRef
@@ -70,7 +70,22 @@ export class AlertComponent {
7070
* @return boolean
7171
* @default false
7272
*/
73-
readonly dismissible = input(false, { transform: booleanAttribute });
73+
readonly dismissibleInput = input(false, { transform: booleanAttribute, alias: 'dismissible' });
74+
75+
readonly #dismissible = linkedSignal({
76+
source: () => this.dismissibleInput(),
77+
computation: (value) => {
78+
return value;
79+
}
80+
});
81+
82+
set dismissible(value: boolean) {
83+
this.#dismissible.set(value);
84+
}
85+
86+
get dismissible() {
87+
return this.#dismissible();
88+
}
7489

7590
/**
7691
* Adds animation for dismissible alert.
@@ -84,23 +99,24 @@ export class AlertComponent {
8499
*/
85100
readonly visibleInput = input(true, { transform: booleanAttribute, alias: 'visible' });
86101

87-
readonly #visibleInputEffect = effect(() => {
88-
this.visible = this.visibleInput();
102+
readonly #visible = linkedSignal({
103+
source: () => this.visibleInput(),
104+
computation: (value) => {
105+
return value;
106+
}
89107
});
90108

91109
set visible(value: boolean) {
92-
if (this.#visible !== value) {
93-
this.#visible = value;
110+
if (this.#visible() !== value) {
111+
this.#visible.set(value);
94112
this.visibleChange.emit(value);
95113
}
96114
}
97115

98116
get visible() {
99-
return this.#visible;
117+
return this.#visible();
100118
}
101119

102-
#visible: boolean = true;
103-
104120
readonly hide = signal<boolean>(false);
105121

106122
/**
@@ -129,7 +145,7 @@ export class AlertComponent {
129145
const variant = this.variant();
130146
return {
131147
alert: true,
132-
'alert-dismissible': this.dismissible(),
148+
'alert-dismissible': this.dismissible,
133149
fade: this.fade(),
134150
show: !this.hide(),
135151
[`alert-${color}`]: !!color && variant !== 'solid',

0 commit comments

Comments
 (0)