Skip to content

Commit 8dc5dc4

Browse files
authored
Merge pull request #200 from youda97/master
Add loading components
2 parents cdaca30 + bc94930 commit 8dc5dc4

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

src/i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
"RESET_SEARCH": "Reset search"
6464
}
6565
},
66+
"LOADING": {
67+
"TITLE": "Loading"
68+
},
6669
"MODAL": {
6770
"CLOSE": "Close modal"
6871
},

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export * from "./tiles/tiles.module";
2424
export * from "./progress-indicator/progress-indicator.module";
2525
export * from "./i18n/i18n.module";
2626
export * from "./pagination/pagination.module";
27+
export * from "./loading/loading.module";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
2+
3+
import { Loading } from "./loading.component";
4+
import { I18nModule } from "../i18n/i18n.module";
5+
6+
describe("Loading", () => {
7+
let component: Loading;
8+
let fixture: ComponentFixture<Loading>;
9+
10+
beforeEach(() => {
11+
TestBed.configureTestingModule({
12+
declarations: [Loading],
13+
imports: [I18nModule]
14+
});
15+
16+
fixture = TestBed.createComponent(Loading);
17+
component = fixture.componentInstance;
18+
});
19+
20+
it("should work", () => {
21+
expect(component instanceof Loading).toBe(true);
22+
});
23+
});

src/loading/loading.component.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Component, Input, HostBinding } from "@angular/core";
2+
import { I18n } from "./../i18n/i18n.module";
3+
4+
@Component({
5+
selector: "ibm-loading",
6+
template: `
7+
<div
8+
[ngClass]="{'bx--loading--small': size === 'sm'}"
9+
class="bx--loading">
10+
<svg class="bx--loading__svg" viewBox="-75 -75 150 150">
11+
<title>{{title}}</title>
12+
<circle cx="0" cy="0" r="37.5" />
13+
</svg>
14+
</div>
15+
`
16+
})
17+
export class Loading {
18+
/**
19+
* Accessible title for the loading circle.
20+
* Defaults to the `LOADING.TITLE` value from the i18n service.
21+
*/
22+
@Input() title = this.i18n.get().LOADING.TITLE;
23+
24+
/**
25+
* Specify the size of the button
26+
* @type {("normal" | "sm")}
27+
* @memberof Loading
28+
*/
29+
@Input() size: "normal" | "sm" = "normal";
30+
31+
/**
32+
* Set to `true` to make loader with an overlay.
33+
* @type {boolean}
34+
* @memberof Loading
35+
*/
36+
@Input() @HostBinding("class.bx--loading-overlay") overlay = false;
37+
38+
constructor(private i18n: I18n) {}
39+
}

src/loading/loading.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule } from "@angular/core";
2+
import { CommonModule } from "@angular/common";
3+
4+
import { Loading } from "./loading.component";
5+
import { I18nModule } from "./../i18n/i18n.module";
6+
7+
export { Loading } from "./loading.component";
8+
9+
@NgModule({
10+
declarations: [Loading],
11+
exports: [Loading],
12+
imports: [CommonModule, I18nModule]
13+
})
14+
export class LoadingModule {}

src/loading/loading.stories.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { storiesOf, moduleMetadata } from "@storybook/angular";
2+
import { action } from "@storybook/addon-actions";
3+
import { withKnobs, boolean } from "@storybook/addon-knobs/angular";
4+
5+
import { LoadingModule } from "../";
6+
7+
storiesOf("Loading", module).addDecorator(
8+
moduleMetadata({
9+
imports: [LoadingModule]
10+
})
11+
)
12+
.addDecorator(withKnobs)
13+
.add("Basic", () => ({
14+
template: `
15+
<ibm-loading [overlay]="true"></ibm-loading>
16+
`
17+
}))
18+
.add("Small", () => ({
19+
template: `
20+
<ibm-loading size="sm"></ibm-loading>
21+
`
22+
}));

0 commit comments

Comments
 (0)