Skip to content

Commit 626ce43

Browse files
committed
Review updates
1 parent 71ca6c0 commit 626ce43

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

src/grid/grid-test.component.ts

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

src/grid/grid.directive.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { Component } from "@angular/core";
12
import { async, TestBed } from "@angular/core/testing";
23
import { By } from "@angular/platform-browser";
3-
import { TestGridComponent } from "./grid-test.component";
44
import { ColumnDirective, GridDirective, RowDirective } from "./grid.directive";
55

6-
describe("Grid Directive", () => {
6+
@Component({
7+
selector: "ibm-test-grid",
8+
template: ""
9+
})
10+
class TestGridComponent {}
11+
12+
describe("GridDirective", () => {
713
beforeEach(() => {
814
TestBed.configureTestingModule({
915
declarations: [
@@ -18,7 +24,7 @@ describe("Grid Directive", () => {
1824
it("should render a grid", async(() => {
1925
TestBed.overrideComponent(TestGridComponent, {
2026
set: {
21-
template: "<div ibmGrid class='test-directive'></div>"
27+
template: "<div ibmGrid></div>"
2228
}
2329
});
2430

@@ -36,7 +42,7 @@ describe("Grid Directive", () => {
3642
it("should render a row", async(() => {
3743
TestBed.overrideComponent(TestGridComponent, {
3844
set: {
39-
template: "<div ibmRow class='test-directive'></div>"
45+
template: "<div ibmRow></div>"
4046
}
4147
});
4248

@@ -55,7 +61,7 @@ describe("Grid Directive", () => {
5561
TestBed.overrideComponent(TestGridComponent, {
5662
set: {
5763
template:
58-
"<div ibmCol [offsets]='{\"md\": 2}' [columnNumbers]='{\"lg\":3, \"md\": \"nobreak\"}' class='test-directive'></div>"
64+
"<div ibmCol [offsets]='{\"md\": 2}' [columnNumbers]='{\"lg\":3, \"md\": \"nobreak\"}' class='custom-class-example'></div>"
5965
}
6066
});
6167

@@ -70,7 +76,7 @@ describe("Grid Directive", () => {
7076

7177
const directiveInstance = directiveEl.injector.get(ColumnDirective);
7278
expect(directiveInstance.columnClasses).toBe(
73-
"bx--col-lg-3 bx--col-md bx--offset-md-2 test-directive"
79+
"bx--col-lg-3 bx--col-md bx--offset-md-2 custom-class-example"
7480
);
7581
});
7682
}));

src/grid/grid.directive.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,36 @@ export class ColumnDirective implements OnInit {
2424

2525
@Input() offsets = {};
2626

27-
@HostBinding("class") columnClasses: string;
27+
protected _columnClasses: string[] = [];
28+
29+
@HostBinding("class")
30+
get columnClasses(): string {
31+
return this._columnClasses.join(" ");
32+
}
33+
34+
set(classes: string) {
35+
this._columnClasses = classes.split(" ");
36+
}
2837

2938
ngOnInit() {
30-
const classNames = [];
3139
try {
3240
Object.keys(this.columnNumbers).forEach(key => {
3341
if (this.columnNumbers[key] === "nobreak") {
34-
classNames.push(`bx--col-${key}`);
42+
this._columnClasses.push(`bx--col-${key}`);
3543
} else {
36-
classNames.push(`bx--col-${key}-${this.columnNumbers[key]}`);
44+
this._columnClasses.push(`bx--col-${key}-${this.columnNumbers[key]}`);
3745
}
3846
});
3947

4048
Object.keys(this.offsets).forEach(key => {
41-
classNames.push(`bx--offset-${key}-${this.offsets[key]}`);
49+
this._columnClasses.push(`bx--offset-${key}-${this.offsets[key]}`);
4250
});
4351
} catch (err) {
4452
console.error(`Malformed \`offsets\` or \`columnNumbers\`: ${err}`);
4553
}
4654

4755
if (this.class !== "") {
48-
classNames.push(this.class);
56+
this._columnClasses.push(this.class);
4957
}
50-
51-
this.columnClasses = classNames.join(" ");
5258
}
5359
}

src/grid/grid.stories.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 { GridModule } from "../";
7+
8+
storiesOf("Grid", module)
9+
.addDecorator(
10+
moduleMetadata({
11+
imports: [GridModule]
12+
})
13+
)
14+
.addDecorator(withKnobs)
15+
.add("Basic", () => ({
16+
template: `
17+
<div ibmGrid>
18+
<div ibmRow>
19+
<div ibmCol class="custom-class-example" [columnNumbers]="{'md':3, 'sm': 12}">First Column</div>
20+
<div ibmCol class="custom-class-example" [columnNumbers]="{'md':3, 'sm': 12}">Second column</div>
21+
</div>
22+
</div>
23+
`
24+
}));

0 commit comments

Comments
 (0)