-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKey.js
54 lines (53 loc) · 1.3 KB
/
Key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const template = /*html*/ `
<div @click="keyClick(keyContent)" :class="['key', keyContent.code, currentLang, shiftKeyOnStyle]">
<div v-if="isActiveKey" :class="['key', 'activeKey', keyContent.code, currentLang]">
<div>{{activeKeyValue}}</div>
</div>
<div>{{main}}</div>
<div>{{shifted}}</div>
</div>
`
export default {
template,
props: {
keyContent: Object,
currentLang: String,
activeKey: Object,
setActiveKey: Function,
playActiveKey: Function,
shiftOn: Boolean,
toggleShiftOn: Function
},
methods: {
keyClick(keyContent) {
this.setActiveKey(keyContent.code, this.shiftOn)
this.playActiveKey()
if (keyContent.code.includes('Shift')) {
this.toggleShiftOn()
}
}
},
computed: {
isActiveKey() {
const { keyContent, activeKey } = this
if (!activeKey) return false
return keyContent?.code === activeKey?.code
},
main() {
const { main, label, code } = this.keyContent
return label || main || code
},
shifted() {
const { shifted } = this.keyContent
return shifted
},
shiftKeyOnStyle() {
const { code } = this.keyContent
return code.includes('Shift') && this.shiftOn ? 'shiftKeyOn' : ''
},
activeKeyValue() {
const { keyValue, label, main, code } = this.activeKey
return keyValue?.trim() || label || main || code
}
}
}