1<template>
2 <Button :label="label" @click="handleDiscard" />
3</template>
4
5<script setup lang="ts">
6import { globalStore } from "@/stores/globalStore";
7const { $dialog } = globalStore();
8const emit = defineEmits<{
9 (event: "discard"): void;
10}>();
11
12const {
13 label = "Discard",
14 hideDialog = false,
15 title = "Discard?",
16 message = "Are you sure you want to discard this?",
17} = defineProps<{
18 label?: string;
19 hideDialog?: boolean;
20 title?: string;
21 message?: string;
22}>();
23
24function handleDiscard() {
25 if (hideDialog) {
26 emit("discard");
27 return;
28 }
29 $dialog({
30 title: title,
31 message: message,
32 onConfirm: ({ hideDialog }: { hideDialog: Function }) => {
33 hideDialog();
34 },
35 actions: [
36 {
37 label: "Delete",
38 theme: "red",
39 iconLeft: "lucide-trash-2",
40 variant: "solid",
41 onClick({ close }: { close: () => void }) {
42 emit("discard");
43 close();
44 },
45 },
46 ],
47 });
48}
49</script>
50