Select2 improvements (#92)

* Select2 options are now left aligned, alternative text is gray, layer tab have ordinary select
* Increased height of select2 dropdown

Resolves #84
This commit is contained in:
Nejc Zdovc
2016-12-11 13:06:02 +01:00
committed by József Farkas
parent ffc820f47a
commit 68814185e7
7 changed files with 76 additions and 47 deletions
@@ -8,14 +8,20 @@
<b class="setting-label">Modifiers:</b> <b class="setting-label">Modifiers:</b>
<div class="btn-toolbar modifiers"> <div class="btn-toolbar modifiers">
<div class="btn-group btn-group-sm modifiers__left"> <div class="btn-group btn-group-sm modifiers__left">
<button type="button" class="btn btn-default" *ngFor="let modifier of leftModifiers; let index = index" [class.btn-primary]="leftModifierSelects[index]" <button type="button" class="btn btn-default"
(click)="toggleModifier(false, index)"> *ngFor="let modifier of leftModifiers; let index = index"
[class.btn-primary]="leftModifierSelects[index]"
(click)="toggleModifier(false, index)"
>
{{modifier}} {{modifier}}
</button> </button>
</div> </div>
<div class="btn-group btn-group-sm modifiers__right"> <div class="btn-group btn-group-sm modifiers__right">
<button type="button" class="btn btn-default" *ngFor="let modifier of rightModifiers; let index = index" [class.btn-primary]="rightModifierSelects[index]" <button type="button" class="btn btn-default"
(click)="toggleModifier(true, index)"> *ngFor="let modifier of rightModifiers; let index = index"
[class.btn-primary]="rightModifierSelects[index]"
(click)="toggleModifier(true, index)"
>
{{modifier}} {{modifier}}
</button> </button>
</div> </div>
@@ -23,8 +29,12 @@
</div> </div>
<div class="long-press-container" *ngIf="longPressEnabled"> <div class="long-press-container" *ngIf="longPressEnabled">
<b class="setting-label">Long press action:</b> <b class="setting-label">Long press action:</b>
<select2 #longPressSelect [data]="longPressGroups" [value]="selectedLongPressIndex.toString()" (valueChanged)="onLongpressChange($event)" <select2 #longPressSelect
[width]="140"></select2> [data]="longPressGroups"
[value]="selectedLongPressIndex.toString()"
(valueChanged)="onLongpressChange($event)"
[width]="140"
></select2>
<icon name="question-circle" title="This action happens when the key is being held along with another key."></icon> <icon name="question-circle" title="This action happens when the key is being held along with another key."></icon>
</div> </div>
@@ -110,10 +110,11 @@ export class KeypressTabComponent implements OnChanges, Tab {
if (state.additional && state.additional.explanation) { if (state.additional && state.additional.explanation) {
return jQuery( return jQuery(
'<span class="select2-item">' '<span class="select2-item">'
+ state.text + '<span>' + state.text + '</span>'
+ '<span class="scancode--searchterm"> ' + '<span class="scancode--searchterm"> '
+ state.additional.explanation + state.additional.explanation
+ '</span></span>' + '</span>' +
'</span>'
); );
} else { } else {
return jQuery('<span class="select2-item">' + state.text + '</span>'); return jQuery('<span class="select2-item">' + state.text + '</span>');
@@ -159,9 +159,9 @@
{ {
"id": "40", "id": "40",
"additional": { "additional": {
"explanation": "Enter" "explanation": "Return"
}, },
"text": "Return" "text": "Enter"
}, },
{ {
"id": "41", "id": "41",
@@ -177,7 +177,7 @@
}, },
{ {
"id": "44", "id": "44",
"text": "Spacebar" "text": "Space"
} }
] ]
}, },
@@ -231,7 +231,7 @@
] ]
}, },
{ {
"text": "Functionkeys", "text": "Function keys",
"children": [ "children": [
{ {
"id": "58", "id": "58",
@@ -350,7 +350,7 @@
] ]
}, },
{ {
"text": "NumberPad", "text": "Numpad",
"children": [ "children": [
{ {
"id": "83", "id": "83",
@@ -503,7 +503,7 @@
] ]
}, },
{ {
"text": "MediaKeys", "text": "Media Keys",
"children": [ "children": [
{ {
"id": "127", "id": "127",
@@ -1,6 +1,14 @@
<select2 #toggleSelect [data]="toggleData" [value]="toggle.toString()" (valueChanged)="toggleChanged($event)"></select2> <select (change)="toggleChanged($event.target.value)">
<option *ngFor="let item of toggleData" [value]="item.id" [selected]="toggle === item.id">
{{ item.text }}
</option>
</select>
<span>the</span> <span>the</span>
<select2 #layerSelect [data]="layerData" [value]="layer.toString()" (valueChanged)="layerChanged($event)"></select2> <select (change)="layerChanged($event.target.value)">
<option *ngFor="let item of layerData" [value]="item.id" [selected]="layer === item.id">
{{ item.text }}
</option>
</select>
<span [ngSwitch]="toggle"> <span [ngSwitch]="toggle">
<template ngSwitchCase="true">layer by pressing this key.</template> <template ngSwitchCase="true">layer by pressing this key.</template>
<template ngSwitchDefault="false">layer by holding this key.</template> <template ngSwitchDefault="false">layer by holding this key.</template>
@@ -3,9 +3,16 @@
margin: 0 -5px; margin: 0 -5px;
> span, > span,
> select2 { > select {
margin: 0 5px; margin: 0 5px;
display: flex; display: flex;
align-items: center; align-items: center;
} }
} }
select {
background-color: #fff;
border: 1px solid #aaa;
border-radius: 4px;
padding: 4px 20px 4px 8px;
}
@@ -1,9 +1,7 @@
import { Component, Input, OnChanges, ViewChild } from '@angular/core'; import { Component, Input, OnChanges } from '@angular/core';
import { KeyAction, LayerName, SwitchLayerAction } from '../../../../config-serializer/config-items/key-action'; import { KeyAction, LayerName, SwitchLayerAction } from '../../../../config-serializer/config-items/key-action';
import { Select2Component, Select2OptionData } from 'ng2-select2/ng2-select2';
import { Tab } from '../tab'; import { Tab } from '../tab';
@Component({ @Component({
@@ -13,39 +11,35 @@ import { Tab } from '../tab';
}) })
export class LayerTabComponent implements OnChanges, Tab { export class LayerTabComponent implements OnChanges, Tab {
@Input() defaultKeyAction: KeyAction; @Input() defaultKeyAction: KeyAction;
@ViewChild('toggleSelect') toggleSelect2: Select2Component;
@ViewChild('layerSelect') layerSelect2: Select2Component;
private toggle: boolean; toggleData: {id: boolean, text: string}[] = [
private layer: LayerName;
/* tslint:disable:no-unused-variable: They're used in the template */
private toggleData: Array<Select2OptionData> = [
{ {
id: 'false', id: false,
text: 'Activate' text: 'Activate'
}, },
{ {
id: 'true', id: true,
text: 'Toggle' text: 'Toggle'
} }
]; ];
private layerData: Array<Select2OptionData> = [ layerData: {id: number, text: string}[] = [
{ {
id: '0', id: 0,
text: 'Mod' text: 'Mod'
}, },
{ {
id: '1', id: 1,
text: 'Fn' text: 'Fn'
}, },
{ {
id: '2', id: 2,
text: 'Mouse' text: 'Mouse'
} }
]; ];
/* tslint:enable:no-unused-variable */
private toggle: boolean;
private layer: LayerName;
constructor() { constructor() {
this.toggle = false; this.toggle = false;
@@ -64,6 +58,7 @@ export class LayerTabComponent implements OnChanges, Tab {
if (!(keyAction instanceof SwitchLayerAction)) { if (!(keyAction instanceof SwitchLayerAction)) {
return false; return false;
} }
let switchLayerAction: SwitchLayerAction = <SwitchLayerAction>keyAction; let switchLayerAction: SwitchLayerAction = <SwitchLayerAction>keyAction;
this.toggle = switchLayerAction.isLayerToggleable; this.toggle = switchLayerAction.isLayerToggleable;
this.layer = switchLayerAction.layer; this.layer = switchLayerAction.layer;
@@ -77,17 +72,11 @@ export class LayerTabComponent implements OnChanges, Tab {
return keyAction; return keyAction;
} }
// TODO: change to the correct type when the wrapper has added it. toggleChanged(value: string) {
/* tslint:disable:no-unused-variable: This function is used in the template */ this.toggle = value === 'true';
private toggleChanged(event: any) {
/* tslint:enable:no-unused-variable */
this.toggle = event.value;
} }
// TODO: change to the correct type when the wrapper has added it. layerChanged(value: number) {
/* tslint:disable:no-unused-variable: This function is used in the template */ this.layer = +value;
private layerChanged(event: any) {
/* tslint:enable:no-unused-variable */
this.layer = +event.value;
} }
} }
+15 -1
View File
@@ -17,10 +17,20 @@ main-app {
.select2 { .select2 {
&-container { &-container {
z-index: 1100; z-index: 1100;
.scancode--searchterm {
text-align: right;
color: #b7b7b7;
}
}
&-item {
display: flex;
justify-content: space-between;
} }
&-results { &-results {
text-align: center; text-align: left;
} }
} }
@@ -28,6 +38,10 @@ main-app {
cursor: pointer; cursor: pointer;
} }
.select2-container--default .select2-dropdown--below .select2-results > .select2-results__options {
max-height: 300px;
}
/* GitHub ribbon */ /* GitHub ribbon */
.github-fork-ribbon { .github-fork-ribbon {
background-color: #a00; background-color: #a00;