Skip to content

Commit 0663a27

Browse files
authored
Merge branch 'master' into dynamic_overflow
2 parents 7af75e5 + 19b8582 commit 0663a27

20 files changed

+368
-35
lines changed

src/checkbox/checkbox.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ export class Checkbox implements ControlValueAccessor, AfterViewInit {
137137
* Reflects whether the checkbox state is indeterminate.
138138
* @readonly
139139
*/
140-
@Input() get indeterminate() {
140+
get indeterminate() {
141141
return this._indeterminate;
142142
}
143143

144144
/**
145145
* Set the checkbox's indeterminate state to match the parameter and transition the view to reflect the change.
146146
*/
147-
set indeterminate(indeterminate: boolean) {
147+
@Input() set indeterminate(indeterminate: boolean) {
148148
let changed = this._indeterminate !== indeterminate;
149149
this._indeterminate = indeterminate;
150150

@@ -161,14 +161,14 @@ export class Checkbox implements ControlValueAccessor, AfterViewInit {
161161
* Returns value `true` if state is selected for the checkbox.
162162
* @readonly
163163
*/
164-
@Input() get checked() {
164+
get checked() {
165165
return this._checked;
166166
}
167167

168168
/**
169169
* Updating the state of a checkbox to match the state of the parameter passed in.
170170
*/
171-
set checked (checked: boolean) {
171+
@Input() set checked (checked: boolean) {
172172
if (checked !== this.checked) {
173173
if (this._indeterminate) {
174174
Promise.resolve().then(() => {

src/code-snippet/code-snippet.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ export class CodeSnippet {
9696
@Input() display: SnippetType = SnippetType.single;
9797
@Input() translations = this.i18n.get().CODE_SNIPPET;
9898

99+
/**
100+
* Set to `"light"` to apply the light style on the code snippet.
101+
* @type {"light" | "dark"}
102+
* @memberof CodeSnippet
103+
*/
104+
@Input() theme: "light" | "dark" = "dark";
105+
99106
/**
100107
* Text displayed in the tooltip when user clicks button to copy code.
101108
*
@@ -122,6 +129,9 @@ export class CodeSnippet {
122129
@HostBinding("class.bx--snippet--inline") get snippetInlineClass() {
123130
return this.display === SnippetType.inline;
124131
}
132+
@HostBinding("class.bx--snippet--light") get snippetInlineLightClass() {
133+
return this.display === SnippetType.inline && this.theme === "light";
134+
}
125135
@HostBinding("class.bx--btn--copy") get btnCopyClass() {
126136
return this.display === SnippetType.inline;
127137
}

src/code-snippet/code-snippet.stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ storiesOf("CodeSnippet", module).addDecorator(
6666
props: {
6767
inlineCode
6868
}
69+
}))
70+
.add("Inline Light", () => ({
71+
template: `Here is some <ibm-code-snippet display="inline" theme="light">{{inlineCode}}</ibm-code-snippet> for you.`,
72+
props: {
73+
inlineCode
74+
}
6975
}));

src/content-switcher/content-switcher-option.directive.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class ContentSwitcherOption {
1515
this._active = value;
1616
this.selectedClass = value;
1717
this.ariaSelected = value;
18+
this.tabindex = value ? "0" : "-1";
1819
}
1920

2021
get active() {
@@ -29,6 +30,7 @@ export class ContentSwitcherOption {
2930
@HostBinding("class.bx--content-switcher--selected") selectedClass = false;
3031
@HostBinding("attr.role") role = "tab";
3132
@HostBinding("attr.aria-selected") ariaSelected = false;
33+
@HostBinding("attr.tabIndex") tabindex = "-1";
3234

3335
protected _active = false;
3436

@@ -37,4 +39,16 @@ export class ContentSwitcherOption {
3739
this.active = true;
3840
this.selected.emit(true);
3941
}
42+
43+
@HostListener("focus")
44+
onFocus() {
45+
this.active = true;
46+
}
47+
48+
@HostListener("blur", ["$event"])
49+
onBlur(event) {
50+
if (event.relatedTarget) {
51+
this.active = false;
52+
}
53+
}
4054
}

src/content-switcher/content-switcher.component.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import {
55
QueryList,
66
Output,
77
EventEmitter,
8-
AfterViewInit
8+
AfterViewInit,
9+
HostListener,
10+
ElementRef
911
} from "@angular/core";
1012
import { ContentSwitcherOption } from "./content-switcher-option.directive";
13+
import { isFocusInLastItem, isFocusInFirstItem } from "./../common/tab.service";
1114

1215
/**
1316
*
@@ -31,7 +34,10 @@ export class ContentSwitcher implements AfterViewInit {
3134

3235
@ContentChildren(ContentSwitcherOption) options: QueryList<ContentSwitcherOption>;
3336

37+
constructor(protected elementRef: ElementRef) {}
38+
3439
ngAfterViewInit() {
40+
this.options.first.active = true;
3541
this.options.forEach(option => {
3642
option.selected.subscribe(_ => {
3743
const active = option;
@@ -44,4 +50,43 @@ export class ContentSwitcher implements AfterViewInit {
4450
});
4551
});
4652
}
53+
54+
@HostListener("keydown", ["$event"])
55+
hostkeys(event: KeyboardEvent) {
56+
const buttonList = Array.from<any>(this.elementRef.nativeElement.querySelectorAll(".bx--content-switcher-btn"));
57+
58+
switch (event.key) {
59+
case "Right": // IE specific value
60+
case "ArrowRight":
61+
event.preventDefault();
62+
if (!isFocusInLastItem(event, buttonList)) {
63+
const index = buttonList.findIndex(item => item === event.target);
64+
buttonList[index + 1].focus();
65+
} else {
66+
buttonList[0].focus();
67+
}
68+
break;
69+
70+
case "Left": // IE specific value
71+
case "ArrowLeft":
72+
event.preventDefault();
73+
if (!isFocusInFirstItem(event, buttonList)) {
74+
const index = buttonList.findIndex(item => item === event.target);
75+
buttonList[index - 1].focus();
76+
} else {
77+
buttonList[buttonList.length - 1].focus();
78+
}
79+
break;
80+
81+
case "Home":
82+
event.preventDefault();
83+
buttonList[0].focus();
84+
break;
85+
86+
case "End":
87+
event.preventDefault();
88+
buttonList[buttonList.length - 1].focus();
89+
break;
90+
}
91+
}
4792
}

src/dropdown/dropdown.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import { I18n } from "./../i18n/i18n.module";
2828
@Component({
2929
selector: "ibm-dropdown",
3030
template: `
31-
<div class="bx--list-box">
31+
<div
32+
class="bx--list-box"
33+
[ngClass]="{'bx--dropdown--light': theme === 'light'}">
3234
<button
3335
type="button"
3436
#dropdownButton
@@ -82,7 +84,11 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
8284
* item selection.
8385
*/
8486
@Input() type: "single" | "multi" = "single";
85-
87+
/**
88+
* `light` or `dark` dropdown theme
89+
* @memberof Dropdown
90+
*/
91+
@Input() theme: "light" | "dark" = "dark";
8692
/**
8793
* Set to `true` to disable the dropdown.
8894
*/

src/dropdown/dropdown.stories.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ storiesOf("Dropdown", module)
4141
onClose: action("Dropdown closed")
4242
}
4343
}))
44+
.add("Light", () => ({
45+
template: `
46+
<ibm-dropdown
47+
theme="light"
48+
placeholder="Select"
49+
[disabled]="disabled"
50+
(selected)="selected($event)"
51+
(onClose)="onClose($event)">
52+
<ibm-dropdown-list [items]="items"></ibm-dropdown-list>
53+
</ibm-dropdown>
54+
`,
55+
props: {
56+
disabled: boolean("disabled", false),
57+
items: object("items", [
58+
{ content: "one" },
59+
{ content: "two" },
60+
{ content: "three" },
61+
{ content: "four" }
62+
]),
63+
selected: action("Selected fired for dropdown"),
64+
onClose: action("Dropdown closed")
65+
}
66+
}))
4467
.add("Multi-select", withNotes({ text: "Notes on multi select" })(() => ({
4568
template: `
4669
<ibm-dropdown

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./forms/forms.module";
1212
export * from "./i18n/i18n.module";
1313
export * from "./icon/icon.module";
1414
export * from "./input/input.module";
15+
export * from "./link/link.module";
1516
export * from "./list-group/list-group.module";
1617
export * from "./loading/loading.module";
1718
export * from "./modal/modal.module";
@@ -26,5 +27,3 @@ export * from "./switch/switch.module";
2627
export * from "./table/table.module";
2728
export * from "./tabs/tabs.module";
2829
export * from "./tiles/tiles.module";
29-
export * from "./toggle/toggle.module";
30-
export * from "./utils/position";

src/link/link.directive.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
Directive,
3+
HostBinding,
4+
Input
5+
} from "@angular/core";
6+
7+
/**
8+
* A convinence directive for applying styling to a link.
9+
*
10+
* Example:
11+
*
12+
* ```hmtl
13+
* <a href="#" ibmLink>A link</a>
14+
* ```
15+
*
16+
* See the [vanilla carbon docs](http://www.carbondesignsystem.com/components/link/code) for more detail.
17+
*/
18+
@Directive({
19+
selector: "[ibmLink]"
20+
})
21+
22+
export class Link {
23+
@HostBinding("class.bx--link") baseClass = true;
24+
25+
/**
26+
* Automatically set to `-1` when link is disabled.
27+
* @memberof Link
28+
*/
29+
@HostBinding("attr.tabindex") tabindex;
30+
31+
/**
32+
* Set to true to disable link.
33+
* @memberof Link
34+
*/
35+
@Input()
36+
@HostBinding("attr.aria-disabled")
37+
set disabled(disabled: boolean) {
38+
this._disabled = disabled;
39+
this.tabindex = this.disabled ? -1 : null;
40+
}
41+
42+
get disabled(): boolean {
43+
return this._disabled;
44+
}
45+
46+
private _disabled;
47+
}

src/link/link.module.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NgModule } from "@angular/core";
2+
import { CommonModule } from "@angular/common";
3+
4+
import { Link } from "./link.directive";
5+
6+
export { Link } from "./link.directive";
7+
8+
@NgModule({
9+
declarations: [
10+
Link
11+
],
12+
exports: [
13+
Link
14+
],
15+
imports: [
16+
CommonModule
17+
]
18+
})
19+
export class LinkModule {}

0 commit comments

Comments
 (0)