sn-alert 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ng-package.json +7 -0
- package/package.json +28 -0
- package/src/lib/sn-alert.component.spec.ts +48 -0
- package/src/lib/sn-alert.component.ts +33 -0
- package/src/lib/sn-alert.html +16 -0
- package/src/lib/sn-alert.scss +32 -0
- package/src/public-api.ts +1 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +8 -0
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sn-alert",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "SnAlert is an Angular 21 standalone alert/notification banner component",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Swapnil Nakate",
|
|
7
|
+
"email": "nakate.swapnil7@gmail.com",
|
|
8
|
+
"url": "https://swapnilnakate.in"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@angular/common": "^21.0.0",
|
|
12
|
+
"@angular/core": "^21.0.0"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tslib": "^2.3.0"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/swapnilnakate7/sn-ui/issues",
|
|
20
|
+
"email": "nakate.swapnil7@gmail.com"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"url": "https://github.com/swapnilnakate7/sn-ui",
|
|
24
|
+
"type": "git",
|
|
25
|
+
"directory": "projects/sn-alert"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT"
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { SnAlertComponent } from './sn-alert.component';
|
|
3
|
+
|
|
4
|
+
describe('SnAlertComponent', () => {
|
|
5
|
+
let component: SnAlertComponent;
|
|
6
|
+
let fixture: ComponentFixture<SnAlertComponent>;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
await TestBed.configureTestingModule({
|
|
10
|
+
imports: [SnAlertComponent],
|
|
11
|
+
}).compileComponents();
|
|
12
|
+
|
|
13
|
+
fixture = TestBed.createComponent(SnAlertComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should default scheme to "info"', () => {
|
|
23
|
+
expect(component.scheme).toBe('info');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should be visible by default', () => {
|
|
27
|
+
expect(component._visible).toBeTrue();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should hide and emit dismissed when dismiss() is called', () => {
|
|
31
|
+
let emitted = false;
|
|
32
|
+
component.dismissed.subscribe(() => (emitted = true));
|
|
33
|
+
component.dismiss();
|
|
34
|
+
expect(component._visible).toBeFalse();
|
|
35
|
+
expect(emitted).toBeTrue();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return correct icon for each scheme', () => {
|
|
39
|
+
component.scheme = 'success';
|
|
40
|
+
expect(component.icon).toBe('✓');
|
|
41
|
+
component.scheme = 'danger';
|
|
42
|
+
expect(component.icon).toBe('✗');
|
|
43
|
+
component.scheme = 'warn';
|
|
44
|
+
expect(component.icon).toBe('⚠');
|
|
45
|
+
component.scheme = 'info';
|
|
46
|
+
expect(component.icon).toBe('ℹ');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, Output, booleanAttribute } from '@angular/core';
|
|
2
|
+
import { CommonModule, NgClass } from '@angular/common';
|
|
3
|
+
|
|
4
|
+
@Component({
|
|
5
|
+
selector: 'sn-alert',
|
|
6
|
+
standalone: true,
|
|
7
|
+
imports: [CommonModule, NgClass],
|
|
8
|
+
templateUrl: './sn-alert.html',
|
|
9
|
+
styleUrl: 'sn-alert.scss',
|
|
10
|
+
})
|
|
11
|
+
export class SnAlertComponent {
|
|
12
|
+
@Input() scheme: string = 'info';
|
|
13
|
+
@Input() title: string = '';
|
|
14
|
+
@Input({ transform: booleanAttribute }) dismissible: boolean = false;
|
|
15
|
+
@Output() dismissed = new EventEmitter<void>();
|
|
16
|
+
|
|
17
|
+
_visible: boolean = true;
|
|
18
|
+
|
|
19
|
+
get icon(): string {
|
|
20
|
+
switch (this.scheme) {
|
|
21
|
+
case 'success': return '✓';
|
|
22
|
+
case 'danger': return '✗';
|
|
23
|
+
case 'warn': return '⚠';
|
|
24
|
+
case 'info': return 'ℹ';
|
|
25
|
+
default: return 'ℹ';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
dismiss(): void {
|
|
30
|
+
this._visible = false;
|
|
31
|
+
this.dismissed.emit();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@if (_visible) {
|
|
2
|
+
<div class="sn-alert" [ngClass]="'scheme-' + scheme" role="alert">
|
|
3
|
+
<span class="sn-alert-icon">{{ icon }}</span>
|
|
4
|
+
<div class="sn-alert-body">
|
|
5
|
+
@if (title) {
|
|
6
|
+
<strong class="sn-alert-title">{{ title }}</strong>
|
|
7
|
+
}
|
|
8
|
+
<div class="sn-alert-message">
|
|
9
|
+
<ng-content></ng-content>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
@if (dismissible) {
|
|
13
|
+
<button class="sn-alert-dismiss" (click)="dismiss()" aria-label="Dismiss">✕</button>
|
|
14
|
+
}
|
|
15
|
+
</div>
|
|
16
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
.sn-alert {
|
|
6
|
+
@apply flex items-start gap-3 p-4 rounded-lg border;
|
|
7
|
+
|
|
8
|
+
&.scheme-info { @apply bg-blue-50 border-blue-300 text-blue-800; }
|
|
9
|
+
&.scheme-success { @apply bg-green-50 border-green-300 text-green-800; }
|
|
10
|
+
&.scheme-warn { @apply bg-yellow-50 border-yellow-300 text-yellow-800; }
|
|
11
|
+
&.scheme-danger { @apply bg-red-50 border-red-300 text-red-800; }
|
|
12
|
+
|
|
13
|
+
.sn-alert-icon {
|
|
14
|
+
@apply flex-shrink-0 text-lg font-bold;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sn-alert-body {
|
|
18
|
+
@apply flex-1 min-w-0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.sn-alert-title {
|
|
22
|
+
@apply block font-semibold mb-1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.sn-alert-message {
|
|
26
|
+
@apply text-sm;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.sn-alert-dismiss {
|
|
30
|
+
@apply flex-shrink-0 ml-auto -mr-1 -mt-1 p-1 rounded opacity-70 hover:opacity-100 cursor-pointer bg-transparent border-none text-inherit text-lg leading-none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/sn-alert.component';
|