Newer
Older

Valentin Rigal
committed
<template>
<div>
<div v-if="!charTable">An error occured loading the keyboard</div>
<div v-else v-for="(row, i) in charTable" :key="i">
<span v-for="(char, j) in row" :key="j">
<button
type="button"
v-if="char"
v-on:mouseup="$emit('input', char.character)"
>
{{ char.character }}
</button>
<button type="button" v-else> </button>
</span>
</div>

Valentin Rigal
committed
</div>
</template>
<script>
export default {
props: {

Valentin Rigal
committed
required: true,
},
computed: {
characters() {
return this.keyboard.characters;

Valentin Rigal
committed
},
rowsCount() {
return (
this.characters && Math.max(...this.characters.map((c) => c.row)) + 1
);
columnsCount() {
return (
this.characters && Math.max(...this.characters.map((c) => c.column)) + 1
);
charTable() {
if (!this.columnsCount || !this.rowsCount) return;
// Return a list of every column with padding
const table = Array.from(
Array(this.rowsCount),
() => new Array(this.columnsCount)
);
if (!this.characters) return table;
this.characters.forEach((c) => {
table[c.row][c.column] = c;
});
return table;

Valentin Rigal
committed
},
};
</script>
<style scoped>
button {
width: 3rem;
height: 3rem;
margin: 0.1rem;

Valentin Rigal
committed
}
</style>