Profectus/src/components/fields/FeedbackButton.vue

75 lines
1.4 KiB
Vue
Raw Permalink Normal View History

2021-06-20 23:29:55 -05:00
<template>
<button @click.stop="click" class="feedback" :class="{ activated, left }">
<slot />
</button>
2021-06-20 23:29:55 -05:00
</template>
2022-01-13 22:25:47 -06:00
<script setup lang="ts">
2022-01-24 22:25:34 -06:00
import { nextTick, ref } from "vue";
2021-06-20 23:29:55 -05:00
2022-01-24 22:25:34 -06:00
defineProps<{
left?: boolean;
}>();
2022-01-13 22:25:47 -06:00
const emit = defineEmits<{
(e: "click"): void;
}>();
2022-01-13 22:25:47 -06:00
const activated = ref(false);
2024-10-18 09:26:10 -05:00
const activatedTimeout = ref<NodeJS.Timeout | null>(null);
2022-01-13 22:25:47 -06:00
function click() {
emit("click");
// Give feedback to user
2024-10-18 09:26:10 -05:00
if (activatedTimeout.value != null) {
2022-01-13 22:25:47 -06:00
clearTimeout(activatedTimeout.value);
}
2022-01-13 22:25:47 -06:00
activated.value = false;
nextTick(() => {
activated.value = true;
activatedTimeout.value = setTimeout(() => (activated.value = false), 500);
});
}
2021-06-20 23:29:55 -05:00
</script>
<style scoped>
.feedback {
position: relative;
2021-06-20 23:29:55 -05:00
}
.feedback::after {
position: absolute;
left: calc(100% + 5px);
top: 50%;
transform: translateY(-50%);
content: "✔";
opacity: 0;
pointer-events: none;
box-shadow: inset 0 0 0 35px rgba(111, 148, 182, 0);
text-shadow: none;
2021-06-20 23:29:55 -05:00
}
.feedback.left::after {
left: unset;
right: calc(100% + 5px);
2021-06-20 23:29:55 -05:00
}
.feedback.activated::after {
animation: feedback 0.5s ease-out forwards;
2021-06-20 23:29:55 -05:00
}
@keyframes feedback {
0% {
opacity: 1;
transform: scale3d(0.4, 0.4, 1), translateY(-50%);
}
80% {
opacity: 0.1;
}
100% {
opacity: 0;
transform: scale3d(1.2, 1.2, 1), translateY(-50%);
}
2021-06-20 23:29:55 -05:00
}
</style>