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>
<span class="container" :class="{ confirming }">
<span v-if="confirming">Are you sure?</span>
<button @click.stop="click" class="button danger" :disabled="disabled">
<span v-if="confirming">Yes</span>
<slot v-else />
</button>
<button v-if="confirming" class="button" @click.stop="cancel">No</button>
</span>
2021-06-20 23:29:55 -05:00
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
name: "danger-button",
data() {
return {
confirming: false
};
},
props: {
disabled: Boolean,
skipConfirm: Boolean
},
emits: ["click", "confirmingChanged"],
watch: {
confirming(newValue) {
this.$emit("confirmingChanged", newValue);
}
},
methods: {
click() {
if (this.skipConfirm) {
this.$emit("click");
return;
}
if (this.confirming) {
this.$emit("click");
}
this.confirming = !this.confirming;
},
cancel() {
this.confirming = 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-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>
2021-06-20 23:29:55 -05:00
.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>