2026-01-28 22:37:47 +03:00
|
|
|
<template>
|
2026-10-07 13:10:41 +03:00
|
|
|
<BaseModal :id="modalId" :title="title" ref="modal">
|
2026-01-28 22:37:47 +03:00
|
|
|
<template #body>
|
2026-10-07 09:38:09 +03:00
|
|
|
<p class="text-main" style="white-space: pre-line;">{{ message }}</p>
|
2026-01-28 22:37:47 +03:00
|
|
|
</template>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<button v-if="showCancel" type="button" class="btn-action btn-action-secondary" @click="close">Cancel</button>
|
|
|
|
|
<button type="button" class="btn-action" :class="confirmBtnClass" @click="confirm">
|
|
|
|
|
{{ confirmText }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</BaseModal>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-10-07 13:10:41 +03:00
|
|
|
import { ref, useId } from 'vue';
|
2026-01-28 22:37:47 +03:00
|
|
|
import BaseModal from './BaseModal.vue';
|
|
|
|
|
|
2026-10-07 13:10:41 +03:00
|
|
|
// Unique element id: several ConfirmModal instances may live on one page
|
|
|
|
|
const modalId = `confirm-${useId()}`;
|
2026-01-28 22:37:47 +03:00
|
|
|
const emit = defineEmits(['confirm']);
|
|
|
|
|
const modal = ref(null);
|
|
|
|
|
|
|
|
|
|
const title = ref('');
|
|
|
|
|
const message = ref('');
|
|
|
|
|
const confirmText = ref('Confirm');
|
|
|
|
|
const confirmBtnClass = ref('btn-action-danger');
|
|
|
|
|
const showCancel = ref(true);
|
|
|
|
|
const data = ref(null);
|
|
|
|
|
|
|
|
|
|
const open = (opts) => {
|
|
|
|
|
title.value = opts.title || 'Are you sure?';
|
|
|
|
|
message.value = opts.message || '';
|
|
|
|
|
confirmText.value = opts.confirmText || 'Confirm';
|
|
|
|
|
confirmBtnClass.value = opts.confirmBtnClass || 'btn-action-danger';
|
|
|
|
|
showCancel.value = opts.showCancel !== false;
|
|
|
|
|
data.value = opts.data || null;
|
|
|
|
|
modal.value.show();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const close = () => {
|
|
|
|
|
modal.value.hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const confirm = () => {
|
|
|
|
|
emit('confirm', data.value);
|
|
|
|
|
close();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
defineExpose({ open, close });
|
|
|
|
|
</script>
|