Skip to content

Commit ebf3e52

Browse files
authored
Merge pull request #21 from cal-smith/master
Add input and select components
2 parents 0dcb7d9 + 15f0fe8 commit ebf3e52

File tree

9 files changed

+121
-7
lines changed

9 files changed

+121
-7
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from "./checkbox/checkbox.module";
1919
export * from "./switch/switch.module";
2020
export * from "./radio/radio.module";
2121
export * from "./input/input.module";
22+
export * from "./select/select.module";

src/input/input.directive.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Directive, HostBinding } from "@angular/core";
2+
3+
@Directive({
4+
selector: "[ibmText]"
5+
})
6+
export class TextInput {
7+
@HostBinding("class") inputClass = "bx--text-input";
8+
}

src/input/input.module.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import { FormsModule } from "@angular/forms";
44
import { CommonModule } from "@angular/common";
55

66
// imports
7-
import { LabelComponent } from "../input/label.component";
8-
9-
// exports
10-
export { LabelComponent } from "../input/label.component";
7+
import { LabelComponent } from "./label.component";
8+
import { TextInput } from "./input.directive";
119

1210
@NgModule({
1311
declarations: [
14-
LabelComponent
12+
LabelComponent,
13+
TextInput
1514
],
1615
exports: [
17-
LabelComponent
16+
LabelComponent,
17+
TextInput
1818
],
1919
imports: [
2020
CommonModule,
2121
FormsModule,
2222
]
2323
})
24-
export class InputModule { }
24+
class InputModule { }
25+
26+
export { TextInput, LabelComponent, InputModule };

src/input/input.stories.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ storiesOf("Input", module).addDecorator(
1717
<input type="text" class="bx--text-input" placeholder="Optional placeholder text">
1818
</ibm-label>
1919
`
20+
}))
21+
.add("Input", () => ({
22+
template: `
23+
<input ibmText/>
24+
`
2025
}));

src/select/optgroup.directive.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Directive, HostBinding } from "@angular/core";
2+
3+
@Directive({
4+
// tslint:disable-next-line
5+
selector: "optgroup"
6+
})
7+
export class OptGroup {
8+
@HostBinding("class") inputClass = "bx--select-option";
9+
}

src/select/option.directive.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Directive, HostBinding } from "@angular/core";
2+
3+
@Directive({
4+
// tslint:disable-next-line
5+
selector: "option"
6+
})
7+
export class Option {
8+
@HostBinding("class") inputClass = "bx--select-option";
9+
}

src/select/select.component.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, Input } from "@angular/core";
2+
3+
@Component({
4+
selector: "ibm-select",
5+
template: `
6+
<div class="bx--form-item">
7+
<div class="bx--select">
8+
<label [attr.for]="id" class="bx--label">{{label}}</label>
9+
<select [attr.id]="id" class="bx--select-input">
10+
<ng-content></ng-content>
11+
</select>
12+
<svg class="bx--select__arrow" width="10" height="5" viewBox="0 0 10 5">
13+
<path d="M0 0l5 4.998L10 0z" fill-rule="evenodd" />
14+
</svg>
15+
</div>
16+
</div>
17+
`
18+
})
19+
export class Select {
20+
static selectCount = 0;
21+
@Input() label = "Select label";
22+
@Input() id = `select-${Select.selectCount++}`;
23+
}

src/select/select.module.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// modules
2+
import { NgModule } from "@angular/core";
3+
import { FormsModule } from "@angular/forms";
4+
import { CommonModule } from "@angular/common";
5+
6+
// imports
7+
import { Select } from "./select.component";
8+
import { Option } from "./option.directive";
9+
import { OptGroup } from "./optgroup.directive";
10+
11+
@NgModule({
12+
declarations: [
13+
Select,
14+
Option,
15+
OptGroup
16+
],
17+
exports: [
18+
Select,
19+
Option,
20+
OptGroup
21+
],
22+
imports: [
23+
CommonModule,
24+
FormsModule,
25+
]
26+
})
27+
class SelectModule { }
28+
29+
export { Select, Option, OptGroup, SelectModule };

src/select/select.stories.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { storiesOf, moduleMetadata } from "@storybook/angular";
2+
import { action } from "@storybook/addon-actions";
3+
import { withKnobs, boolean } from "@storybook/addon-knobs/angular";
4+
5+
import { SelectModule } from "../";
6+
7+
storiesOf("Select", module).addDecorator(
8+
moduleMetadata({
9+
imports: [SelectModule]
10+
})
11+
)
12+
.addDecorator(withKnobs)
13+
.add("Basic", () => ({
14+
template: `
15+
<ibm-select>
16+
<option value="" disabled selected hidden>Choose an option</option>
17+
<option value="solong">A much longer option that is worth having around to check how text flows</option>
18+
<optgroup label="Category 1">
19+
<option value="option1">Option 1</option>
20+
<option value="option2">Option 2</option>
21+
</optgroup>
22+
<optgroup label="Category 2">
23+
<option value="option1">Option 1</option>
24+
<option value="option2">Option 2</option>
25+
</optgroup>
26+
</ibm-select>
27+
`
28+
}));

0 commit comments

Comments
 (0)