diff options
author | Erich Eckner <erich.eckner.ext@bestsecret.com> | 2023-02-03 11:14:53 +0100 |
---|---|---|
committer | Erich Eckner <erich.eckner.ext@bestsecret.com> | 2023-02-03 11:14:53 +0100 |
commit | 2188e12f4edfcc1bbb2f7fa56616bef798dff89f (patch) | |
tree | 574b4b7c7c1809a4d035da81a6413ce2932a0b1d /src/components | |
parent | 8cd0e5413f2a991fd336f8202789fad6a4f855b6 (diff) | |
download | wordle-frontend-2188e12f4edfcc1bbb2f7fa56616bef798dff89f.tar.xz |
keyboard events are now handled more or less properly
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Keyboard.vue | 26 | ||||
-rw-r--r-- | src/components/KeyboardKey.vue | 9 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/components/Keyboard.vue b/src/components/Keyboard.vue index 4777a9c..3b428c8 100644 --- a/src/components/Keyboard.vue +++ b/src/components/Keyboard.vue @@ -1,11 +1,11 @@ <template> <table> - <tr - v-for="letters in ['QWERTZUIOPÜ', 'ASDFFGHJKLÖÄ', 'YXCVBNMß']" - :key="letters" - > + <tr v-for="letters in rows" :key="letters"> <td v-for="letter in letters" :key="letter"> - <KeyboardKey :letter="letter"></KeyboardKey> + <KeyboardKey + :letter="letter" + :buttonPressed="pressButton" + ></KeyboardKey> </td> </tr> </table> @@ -13,6 +13,22 @@ <script setup lang="ts"> import KeyboardKey from "@/components/KeyboardKey.vue"; + +let props = defineProps<{ + addLetter: (letter: string) => void; + removeLetter: () => void; + navigate: (direction: "left" | "right" | "first" | "last") => void; +}>(); + +const rows = ["QWERTZUIOPÜ", "ASDFFGHJKLÖÄ", "YXCVBNMß"]; + +function pressButton(letter: string) { + if (rows.join("").indexOf(letter) > -1) { + props.addLetter(letter); + } else { + console.log("button " + letter + " pressed"); + } +} </script> <style scoped></style> diff --git a/src/components/KeyboardKey.vue b/src/components/KeyboardKey.vue index 1deb0ca..6ce8d47 100644 --- a/src/components/KeyboardKey.vue +++ b/src/components/KeyboardKey.vue @@ -1,14 +1,11 @@ <template> - <button @click="pressButton()">{{ letter }}</button> + <button @click="buttonPressed(letter)">{{ letter }}</button> </template> <script setup lang="ts"> -function pressButton() { - console.log("button " + props.letter + " pressed"); -} - -let props = defineProps<{ +defineProps<{ letter: string; + buttonPressed: (letter: string) => void; }>(); </script> |