Profectus/src/components/fields/DangerButton.vue

77 lines
1.2 KiB
Vue
Raw Normal View History

2021-06-20 23:29:55 -05:00
<template>
2021-07-24 17:08:52 -05:00
<span class="container" :class="{ confirming }">
2021-06-20 23:29:55 -05:00
<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
},
2021-07-24 17:08:52 -05:00
emits: [ 'click', 'confirmingChanged' ],
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;
}
2021-07-24 17:08:52 -05:00
.container.confirming button {
font-size: 1em;
}
2021-06-20 23:29:55 -05:00
.container > * {
margin: 0 4px;
}
</style>
2021-06-20 23:29:55 -05:00
<style>
2021-06-20 23:29:55 -05:00
.danger {
position: relative;
2021-06-20 23:29:55 -05:00
border: solid 2px var(--danger);
border-right-width: 16px;
2021-06-20 23:29:55 -05:00
}
.danger::after {
position: absolute;
2021-06-20 23:29:55 -05:00
content: "!";
color: white;
right: -13px;
2021-06-20 23:29:55 -05:00
}
</style>