Skip to content

Commit 8a1c15c

Browse files
committed
feat(select): first pass at a basic select component
1 parent ab51f97 commit 8a1c15c

File tree

7 files changed

+98
-1
lines changed

7 files changed

+98
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Directive, Input, HostBinding } from "@angular/core";
1+
import { Directive, HostBinding } from "@angular/core";
22

33
@Directive({
44
selector: "[ibmText]"

src/select/optgroup.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: "optgroup"
5+
})
6+
export class OptGroup {
7+
@HostBinding("class") inputClass = "bx--select-option";
8+
}

src/select/option.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: "option"
5+
})
6+
export class Option {
7+
@HostBinding("class") inputClass = "bx--select-option";
8+
}

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)