Skip to content

Commit ca134a1

Browse files
authored
feat(tiles): Merge pull request #37 from markewallace/add_tiles_module
Add new tiles module with basic and clickable tile components
2 parents 5a177f1 + b32b803 commit ca134a1

File tree

8 files changed

+246
-1
lines changed

8 files changed

+246
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"storybook": "start-storybook -p 6006",
99
"docs:build": "compodoc src -p tsconfig.json",
1010
"docs:server": "compodoc src -p tsconfig.json -s -w",
11-
"lint": "tslint -e spec.ts src/**/*.ts && stylelint src/**/*.scss --config .stylelintrc.yml",
11+
"lint": "tslint src/**/*.ts && stylelint src/**/*.scss --config .stylelintrc.yml",
1212
"test": "karma start",
1313
"test:watch": "karma start --auto-watch --no-single-run",
1414
"utils:add": "git subtree add --prefix=src/utils [email protected]:peretz/utils.git master --squash",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export * from "./switch/switch.module";
2020
export * from "./radio/radio.module";
2121
export * from "./input/input.module";
2222
export * from "./select/select.module";
23+
export * from "./tiles/tiles.module";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
2+
3+
import { DebugElement, Component } from "@angular/core";
4+
import {
5+
async,
6+
ComponentFixture,
7+
TestBed
8+
} from "@angular/core/testing";
9+
import { By } from "@angular/platform-browser";
10+
11+
import { ClickableTile } from "./clickable-tile.component";
12+
13+
describe("ClickableTile", () => {
14+
beforeEach(async(() => {
15+
TestBed.configureTestingModule({
16+
declarations: [ClickableTile, ClickableTileTestComponent],
17+
}).compileComponents();
18+
}));
19+
20+
it("should create a ClickableTile", () => {
21+
let fixture: ComponentFixture<ClickableTile> = TestBed.createComponent(ClickableTile);
22+
let component: ClickableTile = fixture.componentInstance;
23+
fixture.detectChanges();
24+
25+
expect(component).toBeTruthy();
26+
});
27+
28+
it("should create a disabled ClickableTile", () => {
29+
let fixture: ComponentFixture<ClickableTileTestComponent> = TestBed.createComponent(ClickableTileTestComponent);
30+
let component: ClickableTileTestComponent = fixture.componentInstance;
31+
fixture.detectChanges();
32+
33+
const directiveEl = fixture.debugElement.query(By.directive(ClickableTile));
34+
expect(directiveEl).not.toBeNull();
35+
expect(directiveEl.attributes["disabled"]).toBeTruthy();
36+
expect(directiveEl.attributes["href"]).toBe("https://angular.carbondesignsystem.com/");
37+
});
38+
});
39+
40+
@Component({
41+
selector: "test-cmp",
42+
template: `
43+
<ibm-clickable-tile disabled="true" href="https://angular.carbondesignsystem.com/">
44+
Test Clickable Tile
45+
</ibm-clickable-tile>`,
46+
entryComponents: [ClickableTile]
47+
})
48+
class ClickableTileTestComponent {}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
Component,
3+
Input
4+
} from "@angular/core";
5+
6+
/**
7+
* Build application's clickable tiles using this component.
8+
*
9+
* ## Basic usage
10+
*
11+
* ```html
12+
* <ibm-clickable-tile>
13+
* tile content
14+
* </ibm-clickable-tile>
15+
* ```
16+
*
17+
* @export
18+
* @class ClickableTile
19+
* @implements {OnInit}
20+
*/
21+
@Component({
22+
selector: "ibm-clickable-tile",
23+
template: `
24+
<a
25+
class="bx--link bx--tile bx--tile--clickable"
26+
[ngClass]="{
27+
'bx--tile--is-clicked': clicked
28+
}"
29+
tabindex="0"
30+
(click)="onClick($event)"
31+
(keydown)="onKeyDown($event)"
32+
[href]="href"
33+
[attr.aria-disabled]="disabled">
34+
<ng-content></ng-content>
35+
</a>`
36+
})
37+
export class ClickableTile {
38+
/**
39+
* Sets the `href` attribute on the `ibm-clickable-tile` element.
40+
* @type {string}
41+
* @memberof ClickableTile
42+
*/
43+
@Input() href: string;
44+
45+
/**
46+
* Set to `true` to disable the clickable tile.
47+
* @type {boolean}
48+
* @memberof ClickableTile
49+
*/
50+
@Input() disabled = false;
51+
52+
clicked = false;
53+
54+
onClick(event) {
55+
this.clicked = !this.clicked;
56+
}
57+
58+
onKeyDown(event) {
59+
if (event.key === "Enter" || event.key === " ") {
60+
this.clicked = !this.clicked;
61+
}
62+
}
63+
}

src/tiles/tile.component.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
2+
3+
import {
4+
async,
5+
ComponentFixture,
6+
TestBed
7+
} from "@angular/core/testing";
8+
9+
import { Tile } from "./tile.component";
10+
11+
describe("Tile", () => {
12+
let component: Tile;
13+
let fixture: ComponentFixture<Tile>;
14+
15+
beforeEach(async(() => {
16+
TestBed.configureTestingModule({
17+
declarations: [Tile],
18+
}).compileComponents();
19+
}));
20+
21+
beforeEach(() => {
22+
fixture = TestBed.createComponent(Tile);
23+
component = fixture.componentInstance;
24+
fixture.detectChanges();
25+
});
26+
27+
it("should create a Tile", () => {
28+
expect(component).toBeTruthy();
29+
});
30+
});

src/tiles/tile.component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
Component,
3+
HostBinding
4+
} from "@angular/core";
5+
6+
/**
7+
* Build application's tiles using this component.
8+
*
9+
* ## Basic usage
10+
*
11+
* ```html
12+
* <ibm-tile>
13+
* tile content
14+
* </ibm-tile>
15+
* ```
16+
*
17+
* @export
18+
* @class Tile
19+
* @implements {OnInit}
20+
*/
21+
@Component({
22+
selector: "ibm-tile",
23+
template: `<ng-content></ng-content>`
24+
})
25+
export class Tile {
26+
@HostBinding("class") tileClass = "bx--tile";
27+
}

src/tiles/tiles.module.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NgModule } from "@angular/core";
2+
import { CommonModule } from "@angular/common";
3+
import { TranslateModule } from "@ngx-translate/core";
4+
5+
import { Tile } from "./tile.component";
6+
import { ClickableTile } from "./clickable-tile.component";
7+
8+
export { Tile } from "./tile.component";
9+
export { ClickableTile } from "./clickable-tile.component";
10+
11+
@NgModule({
12+
declarations: [
13+
Tile,
14+
ClickableTile
15+
],
16+
exports: [
17+
Tile,
18+
ClickableTile
19+
],
20+
imports: [
21+
CommonModule,
22+
TranslateModule.forChild()
23+
]
24+
})
25+
export class TilesModule {}

src/tiles/tiles.stories.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { storiesOf, moduleMetadata } from "@storybook/angular";
2+
import { withKnobs } from "@storybook/addon-knobs/angular";
3+
4+
import { TranslateModule } from "@ngx-translate/core";
5+
6+
import { TilesModule } from "../";
7+
8+
storiesOf("Tiles", module)
9+
.addDecorator(
10+
moduleMetadata({
11+
imports: [
12+
TilesModule,
13+
TranslateModule.forRoot()
14+
]
15+
})
16+
)
17+
.addDecorator(withKnobs)
18+
.add("Basic", () => ({
19+
template: `
20+
<ibm-tile>
21+
tile content goes here...
22+
</ibm-tile>
23+
`
24+
}))
25+
.add("Multiple", () => ({
26+
template: `
27+
<div style="display: flex; flex-flow: row wrap; justify-content: space-around;">
28+
<ibm-tile>
29+
Tile 1
30+
</ibm-tile>
31+
<ibm-tile>
32+
Tile 2
33+
</ibm-tile>
34+
<ibm-tile>
35+
Tile 3
36+
</ibm-tile>
37+
</div>
38+
`
39+
}))
40+
.add("Clickable", () => ({
41+
template: `
42+
<p>Normal</p>
43+
<ibm-clickable-tile href="#">
44+
clickable tile content goes here...
45+
</ibm-clickable-tile>
46+
<p>Disabled</p>
47+
<ibm-clickable-tile href="#" [disabled]="true">
48+
clickable tile content goes here...
49+
</ibm-clickable-tile>
50+
`
51+
}));

0 commit comments

Comments
 (0)