-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from cal-smith/master
Add input and select components
- Loading branch information
Showing
9 changed files
with
121 additions
and
7 deletions.
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
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,8 @@ | ||
import { Directive, HostBinding } from "@angular/core"; | ||
|
||
@Directive({ | ||
selector: "[ibmText]" | ||
}) | ||
export class TextInput { | ||
@HostBinding("class") inputClass = "bx--text-input"; | ||
} |
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
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,9 @@ | ||
import { Directive, HostBinding } from "@angular/core"; | ||
|
||
@Directive({ | ||
// tslint:disable-next-line | ||
selector: "optgroup" | ||
}) | ||
export class OptGroup { | ||
@HostBinding("class") inputClass = "bx--select-option"; | ||
} |
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,9 @@ | ||
import { Directive, HostBinding } from "@angular/core"; | ||
|
||
@Directive({ | ||
// tslint:disable-next-line | ||
selector: "option" | ||
}) | ||
export class Option { | ||
@HostBinding("class") inputClass = "bx--select-option"; | ||
} |
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,23 @@ | ||
import { Component, Input } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "ibm-select", | ||
template: ` | ||
<div class="bx--form-item"> | ||
<div class="bx--select"> | ||
<label [attr.for]="id" class="bx--label">{{label}}</label> | ||
<select [attr.id]="id" class="bx--select-input"> | ||
<ng-content></ng-content> | ||
</select> | ||
<svg class="bx--select__arrow" width="10" height="5" viewBox="0 0 10 5"> | ||
<path d="M0 0l5 4.998L10 0z" fill-rule="evenodd" /> | ||
</svg> | ||
</div> | ||
</div> | ||
` | ||
}) | ||
export class Select { | ||
static selectCount = 0; | ||
@Input() label = "Select label"; | ||
@Input() id = `select-${Select.selectCount++}`; | ||
} |
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,29 @@ | ||
// modules | ||
import { NgModule } from "@angular/core"; | ||
import { FormsModule } from "@angular/forms"; | ||
import { CommonModule } from "@angular/common"; | ||
|
||
// imports | ||
import { Select } from "./select.component"; | ||
import { Option } from "./option.directive"; | ||
import { OptGroup } from "./optgroup.directive"; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
Select, | ||
Option, | ||
OptGroup | ||
], | ||
exports: [ | ||
Select, | ||
Option, | ||
OptGroup | ||
], | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
] | ||
}) | ||
class SelectModule { } | ||
|
||
export { Select, Option, OptGroup, SelectModule }; |
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,28 @@ | ||
import { storiesOf, moduleMetadata } from "@storybook/angular"; | ||
import { action } from "@storybook/addon-actions"; | ||
import { withKnobs, boolean } from "@storybook/addon-knobs/angular"; | ||
|
||
import { SelectModule } from "../"; | ||
|
||
storiesOf("Select", module).addDecorator( | ||
moduleMetadata({ | ||
imports: [SelectModule] | ||
}) | ||
) | ||
.addDecorator(withKnobs) | ||
.add("Basic", () => ({ | ||
template: ` | ||
<ibm-select> | ||
<option value="" disabled selected hidden>Choose an option</option> | ||
<option value="solong">A much longer option that is worth having around to check how text flows</option> | ||
<optgroup label="Category 1"> | ||
<option value="option1">Option 1</option> | ||
<option value="option2">Option 2</option> | ||
</optgroup> | ||
<optgroup label="Category 2"> | ||
<option value="option1">Option 1</option> | ||
<option value="option2">Option 2</option> | ||
</optgroup> | ||
</ibm-select> | ||
` | ||
})); |