-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tiles): Merge pull request #37 from markewallace/add_tiles_module
Add new tiles module with basic and clickable tile components
- Loading branch information
Showing
8 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"storybook": "start-storybook -p 6006", | ||
"docs:build": "compodoc src -p tsconfig.json", | ||
"docs:server": "compodoc src -p tsconfig.json -s -w", | ||
"lint": "tslint -e spec.ts src/**/*.ts && stylelint src/**/*.scss --config .stylelintrc.yml", | ||
"lint": "tslint src/**/*.ts && stylelint src/**/*.scss --config .stylelintrc.yml", | ||
"test": "karma start", | ||
"test:watch": "karma start --auto-watch --no-single-run", | ||
"utils:add": "git subtree add --prefix=src/utils [email protected]:peretz/utils.git master --squash", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> | ||
|
||
import { DebugElement, Component } from "@angular/core"; | ||
import { | ||
async, | ||
ComponentFixture, | ||
TestBed | ||
} from "@angular/core/testing"; | ||
import { By } from "@angular/platform-browser"; | ||
|
||
import { ClickableTile } from "./clickable-tile.component"; | ||
|
||
describe("ClickableTile", () => { | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ClickableTile, ClickableTileTestComponent], | ||
}).compileComponents(); | ||
})); | ||
|
||
it("should create a ClickableTile", () => { | ||
let fixture: ComponentFixture<ClickableTile> = TestBed.createComponent(ClickableTile); | ||
let component: ClickableTile = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
|
||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should create a disabled ClickableTile", () => { | ||
let fixture: ComponentFixture<ClickableTileTestComponent> = TestBed.createComponent(ClickableTileTestComponent); | ||
let component: ClickableTileTestComponent = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
|
||
const directiveEl = fixture.debugElement.query(By.directive(ClickableTile)); | ||
expect(directiveEl).not.toBeNull(); | ||
expect(directiveEl.attributes["disabled"]).toBeTruthy(); | ||
expect(directiveEl.attributes["href"]).toBe("https://angular.carbondesignsystem.com/"); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
selector: "test-cmp", | ||
template: ` | ||
<ibm-clickable-tile disabled="true" href="https://angular.carbondesignsystem.com/"> | ||
Test Clickable Tile | ||
</ibm-clickable-tile>`, | ||
entryComponents: [ClickableTile] | ||
}) | ||
class ClickableTileTestComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
Component, | ||
Input | ||
} from "@angular/core"; | ||
|
||
/** | ||
* Build application's clickable tiles using this component. | ||
* | ||
* ## Basic usage | ||
* | ||
* ```html | ||
* <ibm-clickable-tile> | ||
* tile content | ||
* </ibm-clickable-tile> | ||
* ``` | ||
* | ||
* @export | ||
* @class ClickableTile | ||
* @implements {OnInit} | ||
*/ | ||
@Component({ | ||
selector: "ibm-clickable-tile", | ||
template: ` | ||
<a | ||
class="bx--link bx--tile bx--tile--clickable" | ||
[ngClass]="{ | ||
'bx--tile--is-clicked': clicked | ||
}" | ||
tabindex="0" | ||
(click)="onClick($event)" | ||
(keydown)="onKeyDown($event)" | ||
[href]="href" | ||
[attr.aria-disabled]="disabled"> | ||
<ng-content></ng-content> | ||
</a>` | ||
}) | ||
export class ClickableTile { | ||
/** | ||
* Sets the `href` attribute on the `ibm-clickable-tile` element. | ||
* @type {string} | ||
* @memberof ClickableTile | ||
*/ | ||
@Input() href: string; | ||
|
||
/** | ||
* Set to `true` to disable the clickable tile. | ||
* @type {boolean} | ||
* @memberof ClickableTile | ||
*/ | ||
@Input() disabled = false; | ||
|
||
clicked = false; | ||
|
||
onClick(event) { | ||
this.clicked = !this.clicked; | ||
} | ||
|
||
onKeyDown(event) { | ||
if (event.key === "Enter" || event.key === " ") { | ||
this.clicked = !this.clicked; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> | ||
|
||
import { | ||
async, | ||
ComponentFixture, | ||
TestBed | ||
} from "@angular/core/testing"; | ||
|
||
import { Tile } from "./tile.component"; | ||
|
||
describe("Tile", () => { | ||
let component: Tile; | ||
let fixture: ComponentFixture<Tile>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [Tile], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(Tile); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create a Tile", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
Component, | ||
HostBinding | ||
} from "@angular/core"; | ||
|
||
/** | ||
* Build application's tiles using this component. | ||
* | ||
* ## Basic usage | ||
* | ||
* ```html | ||
* <ibm-tile> | ||
* tile content | ||
* </ibm-tile> | ||
* ``` | ||
* | ||
* @export | ||
* @class Tile | ||
* @implements {OnInit} | ||
*/ | ||
@Component({ | ||
selector: "ibm-tile", | ||
template: `<ng-content></ng-content>` | ||
}) | ||
export class Tile { | ||
@HostBinding("class") tileClass = "bx--tile"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { CommonModule } from "@angular/common"; | ||
import { TranslateModule } from "@ngx-translate/core"; | ||
|
||
import { Tile } from "./tile.component"; | ||
import { ClickableTile } from "./clickable-tile.component"; | ||
|
||
export { Tile } from "./tile.component"; | ||
export { ClickableTile } from "./clickable-tile.component"; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
Tile, | ||
ClickableTile | ||
], | ||
exports: [ | ||
Tile, | ||
ClickableTile | ||
], | ||
imports: [ | ||
CommonModule, | ||
TranslateModule.forChild() | ||
] | ||
}) | ||
export class TilesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { storiesOf, moduleMetadata } from "@storybook/angular"; | ||
import { withKnobs } from "@storybook/addon-knobs/angular"; | ||
|
||
import { TranslateModule } from "@ngx-translate/core"; | ||
|
||
import { TilesModule } from "../"; | ||
|
||
storiesOf("Tiles", module) | ||
.addDecorator( | ||
moduleMetadata({ | ||
imports: [ | ||
TilesModule, | ||
TranslateModule.forRoot() | ||
] | ||
}) | ||
) | ||
.addDecorator(withKnobs) | ||
.add("Basic", () => ({ | ||
template: ` | ||
<ibm-tile> | ||
tile content goes here... | ||
</ibm-tile> | ||
` | ||
})) | ||
.add("Multiple", () => ({ | ||
template: ` | ||
<div style="display: flex; flex-flow: row wrap; justify-content: space-around;"> | ||
<ibm-tile> | ||
Tile 1 | ||
</ibm-tile> | ||
<ibm-tile> | ||
Tile 2 | ||
</ibm-tile> | ||
<ibm-tile> | ||
Tile 3 | ||
</ibm-tile> | ||
</div> | ||
` | ||
})) | ||
.add("Clickable", () => ({ | ||
template: ` | ||
<p>Normal</p> | ||
<ibm-clickable-tile href="#"> | ||
clickable tile content goes here... | ||
</ibm-clickable-tile> | ||
<p>Disabled</p> | ||
<ibm-clickable-tile href="#" [disabled]="true"> | ||
clickable tile content goes here... | ||
</ibm-clickable-tile> | ||
` | ||
})); |