-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
106 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
client/src/app/controls/group-tabs/group-tabs.component.html
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,20 @@ | ||
<nav *ngIf="tabs && control" | ||
[id]="'group-tab-' + groupId" | ||
role="tablist" | ||
#groupTabs> | ||
<div *ngFor="let tabItem of tabs" | ||
(click)="select(tabItem.id)" | ||
class="clickable group-tab" | ||
[class.selected-container]="tabItem.id === selectedTabId" | ||
[tabindex]="tabItem.id === selectedTabId ? 0 : -1" | ||
(keydown)="onKeyDown($event)" | ||
role="tab" | ||
[id]="'group-tab-item-' + tabItem.id" | ||
[attr.aria-controls]="'group-tab-item-' + tabItem.id" | ||
[attr.aria-selected]="tabItem.id === selectedTabId" | ||
[attr.aria-label]="tabItem.title"> | ||
|
||
<div [load-image]="tabItem.iconUrl" class="icon-medium"></div> | ||
<h3>{{tabItem.title}}</h3> | ||
</div> | ||
</nav> |
37 changes: 37 additions & 0 deletions
37
client/src/app/controls/group-tabs/group-tabs.component.scss
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,37 @@ | ||
@import '../../../sass/common/variables'; | ||
nav { | ||
display: flex; | ||
} | ||
|
||
.group-tab { | ||
background-color: $border-color; | ||
width: calc(100% / 3); | ||
text-align: center; | ||
height: 83px; | ||
padding-top: 7px; | ||
box-shadow: $card-box-shadow; | ||
|
||
h3 { | ||
margin-top: 2px; | ||
font-weight: bold; | ||
} | ||
|
||
h4 { | ||
font-size: 12px; | ||
} | ||
|
||
&.selected-container { | ||
background-color: $body-bg-color; | ||
} | ||
} | ||
|
||
:host-context(#app-root[theme=dark]) { | ||
.group-tab { | ||
background-color: lighten($chrome-color-dark, 10%); | ||
box-shadow: $card-box-shadow-hover-dark; | ||
|
||
&.selected-container{ | ||
background-color: $chrome-color-dark; | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
client/src/app/controls/group-tabs/group-tabs.component.ts
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,104 @@ | ||
import { | ||
Component, | ||
OnChanges, | ||
ElementRef, | ||
ViewChild, | ||
Input, | ||
SimpleChanges, | ||
Output, | ||
} from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
import { KeyCodes } from '../../shared/models/constants'; | ||
import { Dom } from '../../shared/Utilities/dom'; | ||
import { Subject } from 'rxjs/Subject'; | ||
|
||
export interface GroupTab { | ||
title: string; | ||
id: string; | ||
iconUrl: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'group-tabs', | ||
templateUrl: './group-tabs.component.html', | ||
styleUrls: ['./group-tabs.component.scss'], | ||
}) | ||
export class GroupTabsComponent implements OnChanges { | ||
@ViewChild('groupTabs') groupTabs: ElementRef; | ||
@Input() control: FormControl; | ||
@Input() tabs: GroupTab[]; | ||
@Input() groupId: string; | ||
@Output() valueChanged: Subject<string>; | ||
|
||
public selectedTabId: string; | ||
private _originalTabId: string; | ||
|
||
constructor() { | ||
this.valueChanged = new Subject<string>(); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (changes['control']) { | ||
this._originalTabId = this.control.value; | ||
this.selectedTabId = this.control.value; | ||
} | ||
} | ||
|
||
onKeyDown(event: KeyboardEvent) { | ||
if (event.keyCode === KeyCodes.arrowRight || event.keyCode === KeyCodes.arrowLeft) { | ||
let curIndex = this.tabs.findIndex(tab => tab.id === this.selectedTabId); | ||
const tabElements = this._getTabElements(); | ||
this._setFocus(false, tabElements, curIndex); | ||
|
||
if (event.keyCode === KeyCodes.arrowRight) { | ||
curIndex = this._getTargetIndex(curIndex + 1); | ||
} else { | ||
curIndex = this._getTargetIndex(curIndex - 1); | ||
} | ||
|
||
this.select(this.tabs[curIndex].id); | ||
this._setFocus(true, tabElements, curIndex); | ||
|
||
event.preventDefault(); | ||
} | ||
} | ||
|
||
select(tabId: string) { | ||
if (tabId !== this._originalTabId) { | ||
this.control.markAsDirty(); | ||
} else { | ||
this.control.markAsPristine(); | ||
} | ||
|
||
this.control.setValue(tabId); | ||
this.selectedTabId = tabId; | ||
this.valueChanged.next(tabId); | ||
} | ||
|
||
private _getTabElements() { | ||
return this.groupTabs.nativeElement.children; | ||
} | ||
|
||
private _setFocus(set: boolean, elements: HTMLCollection, index: number) { | ||
const tab = Dom.getTabbableControl(<HTMLElement>elements[index]); | ||
|
||
if (set) { | ||
Dom.setFocus(tab); | ||
} else { | ||
Dom.clearFocus(tab); | ||
} | ||
} | ||
|
||
private _getTargetIndex(currentIndex: number) { | ||
let targetIndex = 0; | ||
if (currentIndex < 0) { | ||
targetIndex = this.tabs.length - 1; | ||
} else if (currentIndex >= this.tabs.length) { | ||
targetIndex = 0; | ||
} else { | ||
targetIndex = currentIndex; | ||
} | ||
|
||
return targetIndex; | ||
} | ||
} |
23 changes: 6 additions & 17 deletions
23
client/src/app/site/container-settings/container-settings.component.html
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
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