Skip to content

Commit

Permalink
feat(component): allow various clearing operations
Browse files Browse the repository at this point in the history
The clearing operations are:
- `clearOneDigit`
- `clearAllScreens`
- `clearEntryScreen`

`entryScreen` is a separate screen. It will be implemented soon
  • Loading branch information
lemredd committed Dec 20, 2022
1 parent bfc445c commit 3669d10
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/CalculatorContainer/CorrectionButton.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { computed } from "vue"
import type { Corrections } from "@/types/buttons"
interface Props {
Expand All @@ -7,17 +8,23 @@ interface Props {
const props = defineProps<Props>()
interface CustomEvents {
(event: "appendToScreen", valueToAppend: Corrections): void
(event: "clearOneDigit"): void
(event: "clearAllScreens"): void
(event: "clearEntryScreen"): void
}
const emit = defineEmits<CustomEvents>()
const mayOneDigitOnly = computed(() => props.value === "")
const mayClearEntryScreenOnly = computed(() => props.value === "CE")
function appendToScreen() {
emit("appendToScreen", props.value)
function clearScreens() {
if (mayClearEntryScreenOnly.value) emit("clearEntryScreen")
if (mayOneDigitOnly.value) emit("clearOneDigit")
else emit("clearAllScreens")
}
</script>

<template>
<button class="correction-button" @click="appendToScreen">
<button class="correction-button" @click="clearScreens">
{{ props.value }}
</button>
</template>
Expand Down

0 comments on commit 3669d10

Please sign in to comment.