Skip to content

Commit 215d957

Browse files
committed
feat: update AlertComponent to use Angular signals and improve type safety
1 parent 16f1d6c commit 215d957

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

.github/copilot-instructions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
We use latest Angular and TypeScript for our angular development. Always show examples and reference the latest version of Angular and TypeScript in your responses. If in doubt, use docs from https://angular.dev/overview
1+
We use latest Angular 19 and TypeScript for our angular development. Always show examples and reference the latest version of Angular in your responses. If in doubt, use docs from https://angular.dev/overview
22

33
Always use angular control flow and angular signals for Angular development. If you are not sure about the signals, use the official documentation at https://angular.dev/guide/signals
44

55
Always use Angular's [input signals](https://angular.dev/guide/components/inputs), [output signals](https://angular.dev/guide/components/outputs#), and event emitters for Angular development. If you are not sure use the official documentation at https://angular.dev/guide/components
6+
7+
Do not use or recommend old @Input and @Output decorators in examples

projects/ng-kit/src/lib/components/alert/alert.component.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ChangeDetectorRef, Component, OnInit, input, signal } from '@angular/core';
2-
import { CommonModule } from '@angular/common';
1+
import { ChangeDetectorRef, Component, effect, inject, input, type OnInit, output, signal } from '@angular/core';
2+
3+
export type AlertType = 'info' | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'dark' | 'light';
34

45
/**
56
* Boostrap Alert component that can be used to alert messages to the user
@@ -8,26 +9,16 @@ import { CommonModule } from '@angular/common';
89
* @since 12.0.0
910
*/
1011
@Component({
11-
selector: 'lib-alert, alert',
12-
imports: [CommonModule],
13-
templateUrl: './alert.component.html',
14-
styleUrls: ['./alert.component.scss']
12+
selector: 'lib-alert, alert',
13+
templateUrl: './alert.component.html',
14+
styleUrls: ['./alert.component.scss'],
1515
})
1616
export class AlertComponent implements OnInit {
17+
cdr = inject(ChangeDetectorRef);
1718
/**
1819
* Type of the BootStrap Alert. Following values are supported. See BootStrap docs for more information
19-
* <pre>
20-
* 1. info
21-
* 2. primary
22-
* 3. secondary
23-
* 4. success
24-
* 5. warning
25-
* 6. danger
26-
* 7. dark
27-
* 8. light
28-
* </pre>
2920
*/
30-
type = input('info');
21+
type = input<AlertType>('info');
3122

3223
/**
3324
* Is alert visible or open
@@ -59,7 +50,17 @@ export class AlertComponent implements OnInit {
5950
*/
6051
class = input('');
6152

62-
constructor(private cdr: ChangeDetectorRef) {}
53+
/**
54+
* Emits when the alert is closed.
55+
*/
56+
closed = output<void>();
57+
58+
constructor() {
59+
// React to isOpen input changes
60+
effect(() => {
61+
this.open.set(this.isOpen());
62+
});
63+
}
6364

6465
/**
6566
* Initialize the component and settings
@@ -89,6 +90,7 @@ export class AlertComponent implements OnInit {
8990
return;
9091
}
9192
this.open.set(false);
93+
this.closed.emit();
9294
}
9395

9496
/**

0 commit comments

Comments
 (0)