Skip to content

Commit 1281eff

Browse files
authored
Merge pull request #220 from youda97/bannerToNotification
Add notification component and deprecate banner
2 parents 262b2f2 + 0f7d214 commit 1281eff

16 files changed

+673
-97
lines changed

src/banner/banner-content.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Deprecated in favour of `NotificationContent` (to be removed in v3.0).
3+
*
4+
* @deprecated
5+
*/
16
export interface BannerContent {
27
type: string;
38
title: string;

src/banner/banner.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import { NotificationContent } from "./banner-content.interface";
1313
import { I18n } from "./../i18n/i18n.module";
1414

1515
/**
16+
* Deprecated in favour of `InlineNotification` (to be removed in v3.0).
1617
* Banner messages are displayed toward the top of the UI and do not interrupt user’s work.
1718
*
1819
* @export
1920
* @class Banner
21+
* @deprecated
2022
*/
2123
@Component({
2224
selector: "ibm-banner",
@@ -75,7 +77,9 @@ export class Banner implements OnInit {
7577

7678
@ViewChild("banner") banner;
7779

78-
constructor(protected bannerService: BannerService, protected i18n: I18n) {}
80+
constructor(protected bannerService: BannerService, protected i18n: I18n) {
81+
console.warn("`ibm-banner` has been deprecated in favour of `ibm-inline-notification`");
82+
}
7983

8084
ngOnInit() {
8185
if (!this.bannerObj.closeLabel) {

src/banner/banner.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import { I18nModule } from "./../i18n/i18n.module";
1010

1111
export { BannerService } from "./banner.service";
1212
export { Banner } from "./banner.component";
13-
export { Toast } from "./toast.component";
1413

14+
/**
15+
* Deprecated in favour of `NotificationModule` (to be removed in v3.0).
16+
*
17+
* @deprecated
18+
*/
1519
@NgModule({
1620
declarations: [
1721
Toast,

src/banner/banner.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import {
1010
} from "@angular/core";
1111

1212
import { BannerContent, NotificationContent, ToastContent } from "./banner-content.interface";
13-
import { Banner, Toast } from "./banner.module";
13+
import { Banner } from "./banner.module";
14+
import { Toast } from "./toast.component";
1415

1516
/**
17+
* Deprecated in favour of `NotificationService` (to be removed in v3.0).
1618
* Provides a way to use the banner component.
1719
*
1820
* Banners are displayed toward the top of the UI and do not interrupt the user’s work.
1921
*
2022
* @export
2123
* @class BannerService
24+
* @deprecated
2225
*/
2326
@Injectable()
2427
export class BannerService implements OnDestroy {
@@ -43,6 +46,7 @@ export class BannerService implements OnDestroy {
4346
private injector: Injector,
4447
private componentFactoryResolver: ComponentFactoryResolver,
4548
private applicationRef: ApplicationRef) {
49+
console.warn("`BannerService` has been deprecated in favour of `NotificationService`");
4650
}
4751

4852
/**

src/banner/banner.stories.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/banner/toast.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { ToastContent } from "./banner-content.interface";
55
import { Banner } from "./banner.component";
66

77
/**
8+
* Deprecated in favour of `ToastNotification` (to be removed in v3.0).
89
* Banner messages are displayed toward the top of the UI and do not interrupt user’s work.
910
*
1011
* @export
1112
* @class Banner
13+
* @deprecated
1214
*/
1315
@Component({
1416
selector: "ibm-toast",
@@ -52,6 +54,8 @@ export class Toast extends Banner implements OnInit {
5254
@Input() bannerObj: ToastContent;
5355

5456
ngOnInit() {
57+
console.warn("`ibm-toast` has been deprecated in favour of `ibm-toast-notification`");
58+
5559
if (!this.bannerObj.closeLabel) {
5660
this.bannerObj.closeLabel = this.i18n.get().BANNER.CLOSE_BUTTON;
5761
}

src/i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
"MODAL": {
7070
"CLOSE": "Close modal"
7171
},
72+
"NOTIFICATION": {
73+
"CLOSE_BUTTON": "Close alert notification"
74+
},
7275
"OVERFLOW_MENU": {
7376
"OVERFLOW": "Overflow"
7477
},

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export * from "./progress-indicator/progress-indicator.module";
2525
export * from "./i18n/i18n.module";
2626
export * from "./pagination/pagination.module";
2727
export * from "./loading/loading.module";
28+
export * from "./notification/notification.module";
2829
export * from "./toggle/toggle.module";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface NotificationContent {
2+
type: string;
3+
title: string;
4+
target?: string;
5+
duration?: number;
6+
smart?: boolean;
7+
closeLabel?: string;
8+
message: string;
9+
}
10+
11+
export interface ToastContent extends NotificationContent {
12+
subtitle: string;
13+
caption: string;
14+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { TestBed } from "@angular/core/testing";
2+
3+
import { StaticIconModule } from "./../icon/static-icon.module";
4+
5+
import { Notification, NotificationService } from "./notification.module";
6+
import { I18nModule } from "../i18n/i18n.module";
7+
8+
9+
describe("Notification", () => {
10+
beforeEach(() => {
11+
TestBed.configureTestingModule({
12+
declarations: [Notification],
13+
providers: [NotificationService],
14+
imports: [
15+
StaticIconModule,
16+
I18nModule
17+
]
18+
});
19+
});
20+
21+
it("should work", () => {
22+
const fixture = TestBed.createComponent(Notification);
23+
expect(fixture.componentInstance instanceof Notification).toBe(true);
24+
});
25+
26+
it("should render info notification", () => {
27+
const fixture = TestBed.createComponent(Notification);
28+
fixture.componentInstance.notificationObj = {
29+
type: "info",
30+
title: "sample",
31+
message: "sample message"
32+
};
33+
fixture.detectChanges();
34+
35+
expect(fixture.nativeElement.classList.contains("bx--inline-notification--info")).toBeTruthy();
36+
});
37+
38+
it("should render danger notification", () => {
39+
const fixture = TestBed.createComponent(Notification);
40+
fixture.componentInstance.notificationObj = {
41+
type: "error",
42+
title: "sample",
43+
message: "sample message"
44+
};
45+
fixture.detectChanges();
46+
47+
expect(fixture.nativeElement.classList.contains("bx--inline-notification--error")).toBeTruthy();
48+
});
49+
50+
it("should render info warning notification", () => {
51+
const fixture = TestBed.createComponent(Notification);
52+
fixture.componentInstance.notificationObj = {
53+
type: "warning",
54+
title: "sample",
55+
message: "sample message"
56+
};
57+
fixture.detectChanges();
58+
59+
expect(fixture.nativeElement.classList.contains("bx--inline-notification--warning")).toBeTruthy();
60+
});
61+
62+
it("should render info success notification", () => {
63+
const fixture = TestBed.createComponent(Notification);
64+
fixture.componentInstance.notificationObj = {
65+
type: "success",
66+
title: "sample",
67+
message: "sample message"
68+
};
69+
fixture.detectChanges();
70+
71+
expect(fixture.nativeElement.classList.contains("bx--inline-notification--success")).toBeTruthy();
72+
});
73+
74+
it("should display correct message", () => {
75+
const fixture = TestBed.createComponent(Notification);
76+
fixture.componentInstance.notificationObj = {
77+
type: "success",
78+
title: "sample",
79+
message: "sample message"
80+
};
81+
fixture.detectChanges();
82+
83+
let p = fixture.nativeElement.querySelector(".bx--inline-notification__subtitle");
84+
85+
expect(p.innerHTML.trim()).toEqual("sample message");
86+
});
87+
88+
it("should emit change when close button is clicked", () => {
89+
const fixture = TestBed.createComponent(Notification);
90+
fixture.componentInstance.notificationObj = {
91+
type: "success",
92+
title: "sample",
93+
message: "sample message"
94+
};
95+
fixture.detectChanges();
96+
97+
spyOn(fixture.componentInstance.close, "emit");
98+
99+
let button = fixture.nativeElement.querySelector(".bx--inline-notification__close-button");
100+
101+
button.click();
102+
expect(fixture.componentInstance.close.emit).toHaveBeenCalled();
103+
});
104+
105+
it("should emit change when notification is closed programmatically", () => {
106+
const fixture = TestBed.createComponent(Notification);
107+
fixture.componentInstance.notificationObj = {
108+
type: "info",
109+
title: "sample",
110+
message: "sample message"
111+
};
112+
fixture.detectChanges();
113+
114+
fixture.componentInstance.destroy();
115+
116+
expect(fixture.componentInstance);
117+
});
118+
});

0 commit comments

Comments
 (0)