Skip to content

Commit ac537e8

Browse files
committed
2 parents 645ee49 + 1f85b7c commit ac537e8

File tree

13 files changed

+169
-51
lines changed

13 files changed

+169
-51
lines changed

.storybook/manager-head.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<meta property="og:title" content="Carbon Components Angular">
2+
<meta property="og:description" content="An Angular implementation of the Carbon Design System for IBM.">
3+
<meta property="og:image" content="https://angular.carbondesignsystem.com/carbon.jpg">
4+
<meta property="og:url" content="https://angular.carbondesignsystem.com">
5+
6+
<meta name="twitter:title" content="Carbon Components Angular">
7+
<meta name="twitter:description" content="An Angular implementation of the Carbon Design System for IBM.">
8+
<meta name="twitter:image" content="https://angular.carbondesignsystem.com/carbon.jpg">
9+
<meta name="twitter:card" content="summary_large_image">

.storybook/public/carbon.jpg

164 KB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "bash scripts/build.sh",
8-
"storybook": "start-storybook -p 6006",
8+
"storybook": "start-storybook -s .storybook/public -p 6006",
99
"docs:build": "compodoc src -p tsconfig.json",
1010
"docs:server": "compodoc src -p tsconfig.json -s -w",
1111
"lint": "tslint src/**/*.ts && stylelint src/**/*.scss --config .stylelintrc.yml",
@@ -14,7 +14,7 @@
1414
"utils:add": "git subtree add --prefix=src/utils [email protected]:peretz/utils.git master --squash",
1515
"utils:update": "git subtree pull --prefix=src/utils [email protected]:peretz/utils.git master --squash",
1616
"prepush": "bash scripts/prepush.sh",
17-
"build-storybook": "build-storybook -c .storybook -o dist/docs/storybook",
17+
"build-storybook": "build-storybook -c .storybook -s .storybook/public -o dist/docs/storybook",
1818
"semantic-release": "semantic-release",
1919
"commitmsg": "commitlint -E GIT_PARAMS",
2020
"commit": "git-cz"

src/banner/banner.component.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { TranslateModule, TranslateLoader, TranslateFakeLoader } from "@ngx-tran
33

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

6-
import { Banner } from "./banner.component";
7-
import { BannerService } from "./banner.service";
6+
import { Banner, BannerService } from "./banner.module";
87

98

109
describe("Banner", () => {
@@ -32,6 +31,7 @@ describe("Banner", () => {
3231
const fixture = TestBed.createComponent(Banner);
3332
fixture.componentInstance.bannerObj = {
3433
type: "info",
34+
title: "sample",
3535
message: "sample message"
3636
};
3737
fixture.detectChanges();
@@ -44,6 +44,7 @@ describe("Banner", () => {
4444
const fixture = TestBed.createComponent(Banner);
4545
fixture.componentInstance.bannerObj = {
4646
type: "danger",
47+
title: "sample",
4748
message: "sample message"
4849
};
4950
fixture.detectChanges();
@@ -56,6 +57,7 @@ describe("Banner", () => {
5657
const fixture = TestBed.createComponent(Banner);
5758
fixture.componentInstance.bannerObj = {
5859
type: "warning",
60+
title: "sample",
5961
message: "sample message"
6062
};
6163
fixture.detectChanges();
@@ -68,6 +70,7 @@ describe("Banner", () => {
6870
const fixture = TestBed.createComponent(Banner);
6971
fixture.componentInstance.bannerObj = {
7072
type: "success",
73+
title: "sample",
7174
message: "sample message"
7275
};
7376
fixture.detectChanges();
@@ -80,6 +83,7 @@ describe("Banner", () => {
8083
const fixture = TestBed.createComponent(Banner);
8184
fixture.componentInstance.bannerObj = {
8285
type: "success",
86+
title: "sample",
8387
message: "sample message"
8488
};
8589
fixture.detectChanges();
@@ -93,6 +97,7 @@ describe("Banner", () => {
9397
const fixture = TestBed.createComponent(Banner);
9498
fixture.componentInstance.bannerObj = {
9599
type: "success",
100+
title: "sample",
96101
message: "sample message"
97102
};
98103
fixture.detectChanges();
@@ -109,6 +114,7 @@ describe("Banner", () => {
109114
const fixture = TestBed.createComponent(Banner);
110115
fixture.componentInstance.bannerObj = {
111116
type: "info",
117+
title: "sample",
112118
message: "sample message"
113119
};
114120
fixture.detectChanges();

src/banner/banner.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Banner {
7373

7474
@ViewChild("banner") banner;
7575

76-
constructor(private bannerService: BannerService) {}
76+
constructor(protected bannerService: BannerService) {}
7777

7878
/**
7979
* Emits close event.

src/banner/banner.module.ts

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

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

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

1011
export { BannerService } from "./banner.service";
1112
export { Banner } from "./banner.component";
1213
export { Toast } from "./toast.component";
1314

1415
@NgModule({
1516
declarations: [
16-
Banner,
17-
Toast
17+
Toast,
18+
Banner
1819
],
1920
exports: [
2021
Banner,
2122
Toast
2223
],
2324
entryComponents: [Banner, Toast],
24-
imports: [CommonModule, TranslateModule, StaticIconModule]
25+
imports: [CommonModule, TranslateModule, StaticIconModule],
26+
providers: [BannerService]
2527
})
2628
export class BannerModule {}

src/banner/banner.service.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
OnDestroy
1010
} from "@angular/core";
1111

12-
import { Banner } from "./banner.component";
1312
import { BannerContent, NotificationContent, ToastContent } from "./banner-content.interface";
13+
import { Banner, Toast } from "./banner.module";
1414

1515
/**
1616
* Provides a way to use the banner component.
@@ -31,15 +31,6 @@ export class BannerService implements OnDestroy {
3131
public bannerRefs = new Array<ComponentRef<any>>();
3232
public onClose: EventEmitter<any> = new EventEmitter();
3333

34-
/**
35-
* Used to create banners.
36-
*
37-
* @private
38-
* @type {ComponentFactory<any>}
39-
* @memberof BannerService
40-
*/
41-
private componentFactory: ComponentFactory<any>;
42-
4334
/**
4435
* Constructs BannerService.
4536
*
@@ -82,18 +73,14 @@ export class BannerService implements OnDestroy {
8273
* }
8374
* ```
8475
*
85-
* @param {any} [bannerComp=null] If provided, used to resolve component factory
76+
* @param {any} [bannerComp=Banner] If provided, used to resolve component factory
8677
* @memberof BannerService
8778
*/
88-
showBanner(bannerObj: BannerContent | NotificationContent | ToastContent, bannerComp = null): Banner {
89-
if (!bannerComp) {
90-
this.componentFactory = this.componentFactoryResolver.resolveComponentFactory(Banner);
91-
} else {
92-
this.componentFactory = this.componentFactoryResolver.resolveComponentFactory(bannerComp);
93-
}
79+
showBanner(bannerObj: BannerContent | NotificationContent | ToastContent, bannerComp = Banner) {
80+
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(bannerComp);
9481

95-
let bannerRef = this.componentFactory.create(this.injector);
96-
bannerRef.instance.bannerObj = bannerObj;
82+
let bannerRef = componentFactory.create(this.injector);
83+
bannerRef.instance.bannerObj = bannerObj as any; // typescript isn't being very smart here, so we type to any
9784
this.bannerRefs.push(bannerRef);
9885

9986
this.onClose = bannerRef.instance.close;
@@ -106,7 +93,7 @@ export class BannerService implements OnDestroy {
10693

10794
// get or create a container for alert list
10895
let bannerClassName = "banner-overlay";
109-
let bannerList = body.querySelector("." + bannerClassName);
96+
let bannerList = body.querySelector(`.${bannerClassName}`);
11097
if (!bannerList) {
11198
bannerList = document.createElement("div");
11299
bannerList.className = bannerClassName;
@@ -142,6 +129,10 @@ export class BannerService implements OnDestroy {
142129
return bannerRef.instance;
143130
}
144131

132+
showToast(bannerObj: BannerContent | NotificationContent | ToastContent, bannerComp = Toast) {
133+
return this.showBanner(bannerObj, bannerComp);
134+
}
135+
145136
/**
146137
* Programatically closes banner based on `bannerRef`.
147138
*

src/banner/banner.stories.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { Component } from "@angular/core";
77

88
import { TranslateModule } from "@ngx-translate/core";
99

10-
import { BannerModule, BannerService } from "../";
11-
10+
import { BannerModule, BannerService } from "./banner.module";
1211

1312
@Component({
1413
selector: "app-banner-story",
@@ -19,7 +18,6 @@ import { BannerModule, BannerService } from "../";
1918
providers: [BannerService]
2019
})
2120
class BannnerStory {
22-
2321
constructor(private bannerService: BannerService) { }
2422

2523
showBanner() {
@@ -32,11 +30,34 @@ class BannnerStory {
3230
}
3331
}
3432

33+
@Component({
34+
selector: "app-toast-story",
35+
template: `
36+
<button class="bx--btn bx--btn--primary" (click)="showToast()">Show info toast</button>
37+
<div class="banner-container"></div>
38+
`,
39+
providers: [BannerService]
40+
})
41+
class ToastStory {
42+
constructor(private bannerService: BannerService) { }
43+
44+
showToast() {
45+
this.bannerService.showToast({
46+
type: "info",
47+
title: "Sample toast",
48+
subtitle: "Sample subtitle message",
49+
caption: "Sample caption",
50+
target: ".banner-container"
51+
});
52+
}
53+
}
54+
3555
storiesOf("Banner", module)
3656
.addDecorator(
3757
moduleMetadata({
3858
declarations: [
39-
BannnerStory
59+
BannnerStory,
60+
ToastStory
4061
],
4162
imports: [
4263
BannerModule,
@@ -62,9 +83,14 @@ storiesOf("Banner", module)
6283
template: `
6384
<ibm-toast [bannerObj]="{
6485
type: 'error',
65-
title: 'Sample banner',
86+
title: 'Sample toast',
6687
subtitle: 'Sample subtitle message',
6788
caption: 'Sample caption'
6889
}"></ibm-toast>
6990
`
91+
}))
92+
.add("Dynamic toast", () => ({
93+
template: `
94+
<app-toast-story></app-toast-story>
95+
`
7096
}));

src/banner/toast.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, Input } from "@angular/core";
22

3-
import { Banner } from "./banner.component";
43
import { BannerService } from "./banner.service";
54
import { ToastContent } from "./banner-content.interface";
5+
import { Banner } from "./banner.component";
66

77
/**
88
* Banner messages are displayed toward the top of the UI and do not interrupt user’s work.
@@ -22,7 +22,10 @@ import { ToastContent } from "./banner-content.interface";
2222
<p class="bx--toast-notification__subtitle" [innerHTML]="bannerObj.subtitle"></p>
2323
<p class="bx--toast-notification__caption" [innerHTML]="bannerObj.caption"></p>
2424
</div>
25-
<button class="bx--toast-notification__close-button" type="button">
25+
<button
26+
class="bx--toast-notification__close-button"
27+
type="button"
28+
(click)="onClose()">
2629
<svg
2730
class="bx--toast-notification-icon"
2831
aria-label="close"
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component } from "@angular/core";
22
import { Dialog } from "../dialog.component";
3+
import { position } from "../../utils/position";
34

45
/**
56
* Extend the `Dialog` component to create an overflow menu.
@@ -9,16 +10,27 @@ import { Dialog } from "../dialog.component";
910
@Component({
1011
selector: "ibm-overflow-menu-pane",
1112
template: `
12-
<div #dialog>
13-
<ul
14-
class="bx--overflow-menu-options bx--overflow-menu-options--open"
15-
tabindex="-1">
16-
<ng-template
17-
[ngTemplateOutlet]="dialogConfig.content"
18-
[ngTemplateOutletContext]="{overflowMenu: this}">
19-
</ng-template>
20-
</ul>
21-
</div>
22-
`
13+
<ul
14+
#dialog
15+
class="bx--overflow-menu-options bx--overflow-menu-options--open"
16+
tabindex="-1">
17+
<ng-template
18+
[ngTemplateOutlet]="dialogConfig.content"
19+
[ngTemplateOutletContext]="{overflowMenu: this}">
20+
</ng-template>
21+
</ul>
22+
`
2323
})
24-
export class OverflowMenuPane extends Dialog {}
24+
export class OverflowMenuPane extends Dialog {
25+
onDialogInit() {
26+
/**
27+
* -20 shifts the menu up to compensate for the
28+
* extra offset generated by the wrapper component.
29+
*
30+
* 60 shifts the menu right to align the arrow.
31+
* (position service trys it's best to center everything,
32+
* so we need to add some compensation)
33+
*/
34+
this.addGap["bottom"] = pos => position.addOffset(pos, -20, 60);
35+
}
36+
}

0 commit comments

Comments
 (0)