Profectus/src/components/fields/DangerButton.vue

79 lines
1.6 KiB
Vue
Raw Normal View History

2021-06-20 23:29:55 -05:00
<template>
2022-01-13 22:25:47 -06:00
<span class="container" :class="{ confirming: isConfirming }">
<span v-if="isConfirming">Are you sure?</span>
<button @click.stop="click" class="button danger" :disabled="disabled">
2022-01-13 22:25:47 -06:00
<span v-if="isConfirming">Yes</span>
<slot v-else />
</button>
2022-01-13 22:25:47 -06:00
<button v-if="isConfirming" class="button" @click.stop="cancel">No</button>
</span>
2021-06-20 23:29:55 -05:00
</template>
2022-01-13 22:25:47 -06:00
<script setup lang="ts">
import { ref, toRefs, unref, watch } from "vue";
2022-01-24 22:25:34 -06:00
const _props = defineProps<{
disabled?: boolean;
skipConfirm?: boolean;
}>();
const props = toRefs(_props);
2022-01-13 22:25:47 -06:00
const emit = defineEmits<{
(e: "click"): void;
(e: "confirmingChanged", value: boolean): void;
}>();
const isConfirming = ref(false);
watch(isConfirming, isConfirming => {
emit("confirmingChanged", isConfirming);
});
2022-01-13 22:25:47 -06:00
function click() {
if (unref(props.skipConfirm)) {
emit("click");
return;
}
if (isConfirming.value) {
emit("click");
}
isConfirming.value = !isConfirming.value;
}
function cancel() {
isConfirming.value = false;
}
2021-06-20 23:29:55 -05:00
</script>
<style scoped>
.container {
display: flex;
2021-06-20 23:29:55 -05:00
align-items: center;
2021-09-19 11:08:47 -05:00
background: var(--raised-background);
box-shadow: var(--raised-background) 0 2px 3px 5px;
2021-06-20 23:29:55 -05:00
}
2021-07-24 17:08:52 -05:00
.container.confirming button {
font-size: 1em;
2021-07-24 17:08:52 -05:00
}
2021-06-20 23:29:55 -05:00
.container > * {
margin: 0 4px;
2021-06-20 23:29:55 -05:00
}
</style>
2021-06-20 23:29:55 -05:00
<style>
2022-01-24 22:25:34 -06:00
.danger,
.button.danger {
position: relative;
border: solid 2px var(--danger);
border-right-width: 16px;
2021-06-20 23:29:55 -05:00
}
.danger::after {
position: absolute;
content: "!";
color: white;
right: -13px;
2021-06-20 23:29:55 -05:00
}
</style>