Profectus/src/components/fields/DangerButton.vue

71 lines
1.1 KiB
Vue
Raw Normal View History

2021-06-20 23:29:55 -05:00
<template>
<span class="container">
<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>
</template>
<script>
export default {
name: 'danger-button',
data() {
return {
confirming: false
}
},
props: {
2021-06-26 01:45:05 -05:00
disabled: Boolean,
skipConfirm: Boolean
2021-06-20 23:29:55 -05:00
},
watch: {
confirming(newValue) {
this.$emit('confirmingChanged', newValue);
}
},
methods: {
click() {
2021-06-26 01:45:05 -05:00
if (this.skipConfirm) {
this.$emit('click');
return;
}
2021-06-20 23:29:55 -05:00
if (this.confirming) {
this.$emit('click');
}
this.confirming = !this.confirming;
},
cancel() {
this.confirming = false;
}
}
};
</script>
<style scoped>
.container {
display: flex;
align-items: center;
}
.container > * {
margin: 0 4px;
}
.danger {
border: solid 2px var(--danger);
padding-right: 0;
}
.danger::after {
content: "!";
color: white;
background: var(--danger);
padding: 2px;
margin-left: 6px;
height: 100%;
}
</style>