Skip to content

Commit

Permalink
Merge pull request #21 from cal-smith/master
Browse files Browse the repository at this point in the history
Add input and select components
  • Loading branch information
cal-smith authored Aug 23, 2018
2 parents 0dcb7d9 + 15f0fe8 commit ebf3e52
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from "./checkbox/checkbox.module";
export * from "./switch/switch.module";
export * from "./radio/radio.module";
export * from "./input/input.module";
export * from "./select/select.module";
8 changes: 8 additions & 0 deletions src/input/input.directive.ts
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";
}
16 changes: 9 additions & 7 deletions src/input/input.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";

// imports
import { LabelComponent } from "../input/label.component";

// exports
export { LabelComponent } from "../input/label.component";
import { LabelComponent } from "./label.component";
import { TextInput } from "./input.directive";

@NgModule({
declarations: [
LabelComponent
LabelComponent,
TextInput
],
exports: [
LabelComponent
LabelComponent,
TextInput
],
imports: [
CommonModule,
FormsModule,
]
})
export class InputModule { }
class InputModule { }

export { TextInput, LabelComponent, InputModule };
5 changes: 5 additions & 0 deletions src/input/input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ storiesOf("Input", module).addDecorator(
<input type="text" class="bx--text-input" placeholder="Optional placeholder text">
</ibm-label>
`
}))
.add("Input", () => ({
template: `
<input ibmText/>
`
}));
9 changes: 9 additions & 0 deletions src/select/optgroup.directive.ts
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";
}
9 changes: 9 additions & 0 deletions src/select/option.directive.ts
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";
}
23 changes: 23 additions & 0 deletions src/select/select.component.ts
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++}`;
}
29 changes: 29 additions & 0 deletions src/select/select.module.ts
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 };
28 changes: 28 additions & 0 deletions src/select/select.stories.ts
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>
`
}));

0 comments on commit ebf3e52

Please sign in to comment.