Skip to content

Commit 4894ad6

Browse files
authored
Merge pull request #9 from cal-smith/master
feat(toast): add toast banner
2 parents f4a616c + 29fc8d8 commit 4894ad6

File tree

10 files changed

+90
-37
lines changed

10 files changed

+90
-37
lines changed

.npmrc

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"repository": {
4848
"type": "git",
49-
"url": "[email protected]:ibm/carbon-components-angular.git"
49+
"url": "[email protected]:IBM/carbon-components-angular.git"
5050
},
5151
"license": "Apache-2",
5252
"author": "IBM",

scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ if [[ $TRAVIS_BRANCH == "master" ]]; then
2424
git init
2525
git add .
2626
git commit -m "Deploy to GitHub Pages"
27-
git push --force "[email protected]:ibm/carbon-components-angular.git" master:gh-pages > /dev/null 2>&1
27+
git push --force "[email protected]:IBM/carbon-components-angular.git" master:gh-pages > /dev/null 2>&1
2828
exit 0;
2929
fi

scripts/prepush.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
[email protected]:ibm/carbon-components-angular.git
5+
[email protected]:IBM/carbon-components-angular.git
66

77
npm run lint
88

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export interface BannerContent {
2+
type: string;
3+
title: string;
4+
target?: string;
5+
duration?: number;
6+
smart?: boolean;
7+
}
8+
9+
export interface NotificationContent extends BannerContent {
10+
message: string;
11+
}
12+
13+
export interface ToastContent extends NotificationContent {
14+
subtitle: string;
15+
caption: string;
16+
}

src/banner/banner.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@angular/core";
99

1010
import { BannerService } from "./banner.service";
11+
import { NotificationContent } from "./banner-content.interface";
1112

1213
/**
1314
* Banner messages are displayed toward the top of the UI and do not interrupt user’s work.
@@ -20,15 +21,15 @@ import { BannerService } from "./banner.service";
2021
template: `
2122
<div
2223
#banner
23-
class="bx--inline-notification bx--inline-notification--{{bannerObj['type']}}"
24+
class="bx--inline-notification bx--inline-notification--{{bannerObj.type}}"
2425
role="alert">
2526
<div class="bx--inline-notification__details">
2627
<svg class="bx--inline-notification__icon" width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
2728
<path d="M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16zM3.293 4.707l8 8 1.414-1.414-8-8-1.414 1.414z" fill-rule="evenodd"/>
2829
</svg>
2930
<div class="bx--inline-notification__text-wrapper">
30-
<p [innerHTML]="bannerObj['title']" class="bx--inline-notification__title"></p>
31-
<p [innerHTML]="bannerObj['message']" class="bx--inline-notification__subtitle"></p>
31+
<p [innerHTML]="bannerObj.title" class="bx--inline-notification__title"></p>
32+
<p [innerHTML]="bannerObj.message" class="bx--inline-notification__subtitle"></p>
3233
</div>
3334
</div>
3435
<button
@@ -51,16 +52,14 @@ import { BannerService } from "./banner.service";
5152
})
5253
export class Banner {
5354
/**
54-
* Can have `type` and `message` members.
55+
* Can have `type`, `title`, and `message` members.
5556
*
5657
* `type` can be one of `"info"`, `"warning"`, `"danger"`, `"success"`
5758
*
5859
* `message` is message for banner to display
5960
*
60-
* @type {Object}
61-
* @memberof Banner
6261
*/
63-
@Input() bannerObj: Object;
62+
@Input() bannerObj: NotificationContent;
6463

6564
/**
6665
* Emits on close.

src/banner/banner.module.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ import { TranslateModule } from "@ngx-translate/core";
44

55
import { StaticIconModule } from "./../icon/static-icon.module";
66

7-
import { BannerService } from "./banner.service";
87
import { Banner } from "./banner.component";
8+
import { Toast } from "./toast.component";
99

1010
export { BannerService } from "./banner.service";
1111
export { Banner } from "./banner.component";
12+
export { Toast } from "./toast.component";
1213

1314
@NgModule({
1415
declarations: [
15-
Banner
16+
Banner,
17+
Toast
1618
],
1719
exports: [
18-
Banner
20+
Banner,
21+
Toast
1922
],
20-
entryComponents: [Banner],
23+
entryComponents: [Banner, Toast],
2124
imports: [CommonModule, TranslateModule, StaticIconModule]
2225
})
2326
export class BannerModule {}

src/banner/banner.service.ts

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

1212
import { Banner } from "./banner.component";
13+
import { BannerContent, NotificationContent, ToastContent } from "./banner-content.interface";
1314

1415
/**
1516
* Provides a way to use the banner component.
@@ -84,7 +85,7 @@ export class BannerService implements OnDestroy {
8485
* @param {any} [bannerComp=null] If provided, used to resolve component factory
8586
* @memberof BannerService
8687
*/
87-
showBanner(bannerObj, bannerComp = null): Banner {
88+
showBanner(bannerObj: BannerContent | NotificationContent | ToastContent, bannerComp = null): Banner {
8889
if (!bannerComp) {
8990
this.componentFactory = this.componentFactoryResolver.resolveComponentFactory(Banner);
9091
} else {

src/banner/banner.stories.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,11 @@ storiesOf("Banner", module)
6060
}))
6161
.add("Toast", () => ({
6262
template: `
63-
<h4>Coming soon</h4>
64-
<em>Teaser ...</em>
65-
<div class="bx--toast-notification bx--toast-notification--info" role="alert">
66-
<div class="bx--toast-notification__details">
67-
<h3 class="bx--toast-notification__title">Notification title</h3>
68-
<p class="bx--toast-notification__subtitle">Subtitle text goes here.</p>
69-
<p class="bx--toast-notification__caption">Time stamp [00:00:00]</p>
70-
</div>
71-
<button class="bx--toast-notification__close-button" type="button">
72-
<svg
73-
class="bx--toast-notification-icon"
74-
aria-label="close"
75-
width="10"
76-
height="10"
77-
viewBox="0 0 10 10"
78-
xmlns="http://www.w3.org/2000/svg">
79-
<path d="M6.32 5L10 8.68 8.68 10 5 6.32 1.32 10 0 8.68 3.68 5 0 1.32 1.32 0 5 3.68 8.68 0 10 1.32 6.32 5z" fill-rule="nonzero"/>
80-
</svg>
81-
</button>
82-
</div>
63+
<ibm-toast [bannerObj]="{
64+
type: 'error',
65+
title: 'Sample banner',
66+
subtitle: 'Sample subtitle message',
67+
caption: 'Sample caption'
68+
}"></ibm-toast>
8369
`
8470
}));

src/banner/toast.component.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Component, Input } from "@angular/core";
2+
3+
import { Banner } from "./banner.component";
4+
import { BannerService } from "./banner.service";
5+
import { ToastContent } from "./banner-content.interface";
6+
7+
/**
8+
* Banner messages are displayed toward the top of the UI and do not interrupt user’s work.
9+
*
10+
* @export
11+
* @class Banner
12+
*/
13+
@Component({
14+
selector: "ibm-toast",
15+
template: `
16+
<div
17+
#banner
18+
class="bx--toast-notification bx--toast-notification--{{bannerObj['type']}}"
19+
role="alert">
20+
<div class="bx--toast-notification__details">
21+
<h3 class="bx--toast-notification__title" [innerHTML]="bannerObj.title"></h3>
22+
<p class="bx--toast-notification__subtitle" [innerHTML]="bannerObj.subtitle"></p>
23+
<p class="bx--toast-notification__caption" [innerHTML]="bannerObj.caption"></p>
24+
</div>
25+
<button class="bx--toast-notification__close-button" type="button">
26+
<svg
27+
class="bx--toast-notification-icon"
28+
aria-label="close"
29+
width="10"
30+
height="10"
31+
viewBox="0 0 10 10"
32+
xmlns="http://www.w3.org/2000/svg">
33+
<path d="M6.32 5L10 8.68 8.68 10 5 6.32 1.32 10 0 8.68 3.68 5 0 1.32 1.32 0 5 3.68 8.68 0 10 1.32 6.32 5z" fill-rule="nonzero"/>
34+
</svg>
35+
</button>
36+
</div>
37+
`,
38+
providers: [ BannerService ]
39+
})
40+
export class Toast extends Banner {
41+
/**
42+
* Can have `type`, `title`, `subtitle`, and `caption` members.
43+
*
44+
* `type` can be one of `"info"`, `"warning"`, `"danger"`, `"success"`
45+
*
46+
* `message` is message for banner to display
47+
*
48+
*/
49+
@Input() bannerObj: ToastContent;
50+
}

0 commit comments

Comments
 (0)