Skip to content

Commit dac46c3

Browse files
authored
Merge pull request #239 from youda97/master
feat(inline-loading): Add inline loading component
2 parents a73681a + 434dfc0 commit dac46c3

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export * from "./dropdown/dropdown.module";
1111
export * from "./forms/forms.module";
1212
export * from "./i18n/i18n.module";
1313
export * from "./icon/icon.module";
14+
export * from "./inline-loading/inline-loading.module";
1415
export * from "./input/input.module";
1516
export * from "./link/link.module";
1617
export * from "./list-group/list-group.module";
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {
2+
Component,
3+
Input,
4+
Output,
5+
EventEmitter,
6+
HostBinding
7+
} from "@angular/core";
8+
9+
@Component({
10+
selector: "ibm-inline-loading",
11+
template: `
12+
<div class="bx--inline-loading__animation">
13+
<div
14+
*ngIf="success === false"
15+
class="bx--loading bx--loading--small">
16+
<svg class="bx--loading__svg" viewBox="-75 -75 150 150">
17+
<circle cx="0" cy="0" r="37.5"></circle>
18+
</svg>
19+
</div>
20+
<svg
21+
*ngIf="success === true"
22+
class="bx--inline-loading__checkmark-container bx--inline-loading__svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">
23+
<polyline class="bx--inline-loading__checkmark" points="0.74 3.4 3.67 6.34 9.24 0.74"></polyline>
24+
</svg>
25+
</div>
26+
<p *ngIf="success === false" class="bx--inline-loading__text">{{loadingText}}</p>
27+
<p *ngIf="success === true" class="bx--inline-loading__text">{{successText}}</p>
28+
`
29+
})
30+
export class InlineLoading {
31+
/**
32+
* Specify the text description for the loading state.
33+
*
34+
* @memberof InlineLoading
35+
*/
36+
@Input() loadingText;
37+
/**
38+
* Specify the text description for the success state.
39+
*
40+
* @memberof InlineLoading
41+
*/
42+
@Input() successText;
43+
/**
44+
* Provide a delay for the `setTimeout` for success.
45+
*
46+
* @memberof InlineLoading
47+
*/
48+
@Input() successDelay = 1500;
49+
50+
/**
51+
* Returns value `true` if the component is in the success state.
52+
*/
53+
@Input() get success() {
54+
return this._success;
55+
}
56+
/**
57+
* Set the component's state to match the parameter and emits onSuccess if it exits.
58+
*/
59+
set success (success: boolean) {
60+
this._success = success;
61+
if (this._success) {
62+
setTimeout(() => {
63+
this.onSuccess.emit();
64+
}, this.successDelay);
65+
}
66+
}
67+
68+
/**
69+
* Emits event after the success state is active
70+
*
71+
* @type {EventEmitter<any>}
72+
* @memberof InlineLoading
73+
*/
74+
@Output() onSuccess: EventEmitter<any> = new EventEmitter();
75+
76+
@HostBinding("class.bx--inline-loading") loadingClass = true;
77+
78+
/**
79+
* Set to `true` if the action is completed successfully.
80+
*
81+
* @memberof InlineLoading
82+
*/
83+
protected _success = false;
84+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from "@angular/core";
2+
import { CommonModule } from "@angular/common";
3+
4+
import { InlineLoading } from "./inline-loading.component";
5+
6+
export { InlineLoading } from "./inline-loading.component";
7+
8+
@NgModule({
9+
declarations: [InlineLoading],
10+
exports: [InlineLoading],
11+
imports: [CommonModule]
12+
})
13+
export class InlineLoadingModule { }
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 { InlineLoading } from "./inline-loading.component";
4+
import { I18nModule } from "../i18n/i18n.module";
5+
6+
describe("Inline Loading", () => {
7+
let component: InlineLoading;
8+
let fixture: ComponentFixture<InlineLoading>;
9+
10+
beforeEach(() => {
11+
TestBed.configureTestingModule({
12+
declarations: [InlineLoading],
13+
imports: [I18nModule]
14+
});
15+
16+
fixture = TestBed.createComponent(InlineLoading);
17+
component = fixture.componentInstance;
18+
});
19+
20+
it("should work", () => {
21+
expect(component instanceof InlineLoading).toBe(true);
22+
});
23+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { storiesOf, moduleMetadata } from "@storybook/angular";
2+
import { withNotes } from "@storybook/addon-notes";
3+
import { action } from "@storybook/addon-actions";
4+
import { withKnobs, boolean, object } from "@storybook/addon-knobs/angular";
5+
6+
import { InlineLoadingModule, ButtonModule } from "../";
7+
8+
storiesOf("Inline Loading", module)
9+
.addDecorator(
10+
moduleMetadata({
11+
imports: [InlineLoadingModule, ButtonModule]
12+
})
13+
)
14+
.addDecorator(withKnobs)
15+
.add("Basic", () => ({
16+
template: `
17+
<ibm-inline-loading #loading (onSuccess)="onSuccess()" [loadingText]="loadingText" [successText]="successText"></ibm-inline-loading>
18+
<button ibmButton (click)="loading.success = !loading.success">Toggle state</button>
19+
`,
20+
props: {
21+
onSuccess: action("onSuccess"),
22+
loadingText: "Loading data...",
23+
successText: "Data loaded."
24+
}
25+
}));

0 commit comments

Comments
 (0)