refactor: Layers (#85)
This commit is contained in:
@@ -1,16 +1,8 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<span class="uhk__layer-switcher--wrapper" data-title="Layers: ">
|
<span class="uhk__layer-switcher--wrapper" data-title="Layers: ">
|
||||||
<button #baseButton type="button" class="btn btn-default btn-lg btn-primary" (click)="selectLayer(0)">
|
<button type="button" class="btn btn-default btn-lg" *ngFor="let button of buttons; let index = index" (click)="selectLayer(index)"
|
||||||
Base
|
[class.btn-primary]="index === current">
|
||||||
</button>
|
{{ button }}
|
||||||
<button #modButton type="button" class="btn btn-default btn-lg" (click)="selectLayer(1)">
|
|
||||||
Mod
|
|
||||||
</button>
|
|
||||||
<button #fnButton type="button" class="btn btn-default btn-lg" (click)="selectLayer(2)">
|
|
||||||
Fn
|
|
||||||
</button>
|
|
||||||
<button #mouseButton type="button" class="btn btn-default btn-lg" (click)="selectLayer(3)">
|
|
||||||
Mouse
|
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
import {
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||||
Component, Output, EventEmitter, ElementRef, QueryList, ViewChildren, Renderer, Input
|
|
||||||
} from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'layers',
|
selector: 'layers',
|
||||||
@@ -9,43 +7,25 @@ import {
|
|||||||
})
|
})
|
||||||
export class LayersComponent {
|
export class LayersComponent {
|
||||||
@Input() current: number;
|
@Input() current: number;
|
||||||
@Output() selected = new EventEmitter();
|
@Output() select = new EventEmitter();
|
||||||
|
|
||||||
@ViewChildren('baseButton,modButton,fnButton,mouseButton')
|
private buttons: string[];
|
||||||
buttonsQueryList: QueryList<ElementRef>;
|
|
||||||
|
|
||||||
private buttons: ElementRef[];
|
constructor() {
|
||||||
private selectedLayerIndex: number;
|
this.buttons = ['Base', 'Mod', 'Fn', 'Mouse'];
|
||||||
|
this.current = 0;
|
||||||
constructor(private renderer: Renderer) {
|
|
||||||
this.buttons = [];
|
|
||||||
this.selectedLayerIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnChanges() {
|
|
||||||
if (this.buttons.length > 0 && this.current !== this.selectedLayerIndex) {
|
|
||||||
this.buttons.forEach((button: ElementRef) => {
|
|
||||||
this.renderer.setElementClass(button.nativeElement, 'btn-primary', false);
|
|
||||||
});
|
|
||||||
this.renderer.setElementClass(this.buttons[this.current].nativeElement, 'btn-primary', true);
|
|
||||||
this.selectedLayerIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectLayer(index: number) {
|
selectLayer(index: number) {
|
||||||
if (index === this.selectedLayerIndex) {
|
if (this.current === index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.buttons = this.buttonsQueryList.toArray();
|
this.select.emit({
|
||||||
this.selected.emit({
|
oldIndex: this.current,
|
||||||
oldIndex: this.selectedLayerIndex,
|
|
||||||
index: index
|
index: index
|
||||||
});
|
});
|
||||||
|
|
||||||
this.renderer.setElementClass(this.buttons[this.selectedLayerIndex].nativeElement, 'btn-primary', false);
|
this.current = index;
|
||||||
this.renderer.setElementClass(this.buttons[index].nativeElement, 'btn-primary', true);
|
|
||||||
|
|
||||||
this.selectedLayerIndex = index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template ngIf="layers">
|
<template ngIf="layers">
|
||||||
<layers (selected)="selectLayer($event.oldIndex, $event.index)" [current]="currentLayer"></layers>
|
<layers (select)="selectLayer($event.oldIndex, $event.index)" [current]="currentLayer"></layers>
|
||||||
<div class="keyboard-slider" >
|
<div class="keyboard-slider" >
|
||||||
<svg-keyboard *ngFor="let layer of layers"
|
<svg-keyboard *ngFor="let layer of layers"
|
||||||
[@layerState]="layer.animation"
|
[@layerState]="layer.animation"
|
||||||
|
|||||||
Reference in New Issue
Block a user