Skip to content

Confirm

Confirm is a self-contained component used to prompt the user for confirmation. It displays a title, message, and two buttons: confirm and cancel. The confirm button supports a loading state and custom colors. The component emits an event when the user confirms the action.

Note: This component relies on the following external components to function properly:


<script setup>
import Modal from './Modal.vue';
import Heading from './Heading.vue';
import Button from './Button.vue';
defineProps({
title: {
type: String,
required: true,
},
message: {
type: String,
required: true,
},
confirmText: {
type: String,
default: 'Confirm',
},
confirmColor: {
type: String,
default: 'red',
validator: (value) => ['blue', 'red', 'yellow', 'green'].includes(value),
},
cancelText: {
type: String,
default: 'Cancel',
},
loading: Boolean,
});
defineEmits(['confirmed']);
const visible = defineModel('visible');
</script>
<template>
<Modal
v-model:visible="visible"
:with-container="false"
:classes="{ container: 'w-fit mx-auto px-4' }"
:card-props="{ paddless: true, class: 'p-8' }"
>
<div class="flex flex-col items-center justify-center text-center gap-4">
<Heading
:title="title"
:level="4"
/>
<p>{{ message }}</p>
<div class="flex gap-2">
<Button
:color="confirmColor"
:loading="loading"
@click="$emit('confirmed')"
>
{{ confirmText }}
</Button>
<Button @click="visible = false">
{{ cancelText }}
</Button>
</div>
</div>
</Modal>
</template>

PropTypeDefaultRequiredDescription
titleStringYesThe title displayed at the top of the modal.
messageStringYesThe message shown below the title.
confirmTextString"Confirm"NoThe label for the confirm button.
confirmColorString"red"NoColor of the confirm button. Must be one of "blue", "red", "yellow", or "green".
cancelTextString"Cancel"NoThe label for the cancel button.
loadingBooleanfalseNoShows a loading state on the confirm button when true.
PropTypeDescription
visibleBooleanControls the visibility of the modal dialog.
EventDescription
confirmedEmitted when the user clicks the confirm button.

This component does not use any slots.