-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmationModal.vue
More file actions
147 lines (135 loc) · 3.64 KB
/
ConfirmationModal.vue
File metadata and controls
147 lines (135 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script lang="ts" setup>
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
interface Props {
// The id of the component that will be linked to this modal. This MUST BE UNIQUE,
// as modals get closed by ID references! Could be a UUID etc.
linkedComponentId: string;
image?: string;
headline: string;
icon: string;
description: string;
warning?: string;
confirmButtonText: string;
cancelButtonText?: string;
confirmButtonColor:
| 'default'
| 'primary'
| 'secondary'
| 'accent'
| 'error'
| 'success'
| 'warning'
| 'info'
| 'neutral';
confirmButtonIcon?: string;
hideCancelButton?: boolean;
hideDontShowAgain?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
image: '',
warning: '',
cancelButtonText: undefined, // Remove t() from here
confirmButtonIcon: '',
hideCancelButton: false,
hideDontShowAgain: false,
});
// Use computed to get cancel button text
const cancelButtonTextComputed = computed(() => props.cancelButtonText || t('generic.cancel'));
// "cancel" emit is called abort because cancel is a reserved word
const emit = defineEmits<{
(event: 'confirm' | 'abort' | 'dontShowAgain'): void;
}>();
const dontShowAgain = ref(false);
const closeModal = () => {
const modal = document.getElementById(
props.linkedComponentId,
) as HTMLDialogElement;
if (modal) modal.close();
};
const handleCancel = () => {
emit('abort');
if (dontShowAgain.value) {
emit('dontShowAgain');
}
closeModal();
};
const handleConfirm = () => {
emit('confirm');
if (dontShowAgain.value) {
emit('dontShowAgain');
}
closeModal();
};
</script>
<template>
<dialog
:id="props.linkedComponentId"
class="modal"
@cancel="handleCancel"
>
<div class="modal-box w-11/12 max-w-md">
<div class="w-full flex justify-between mb-8">
<h3 class="text-2xl font-bold">
{{ props.headline }}
</h3>
<div class="mx-4 mt-1">
<FontAwesomeIcon :icon="props.icon" @click="props.icon=='xmark'? closeModal() : null"/>
</div>
</div>
<div class="flex flex-col items-center max-w-full">
<div
v-if="props.image"
class="mask mask-squircle size-24 mb-8"
>
<img
:src="props.image"
alt="Modal image"
class="rounded-box"
>
</div>
</div>
<p class="text-lg text-base-content text-left mb-4">
{{ props.description }}
</p>
<div
v-if="props.warning"
class="text-sm text-base-content/60 text-left mb-8"
>
<span>{{ props.warning }}</span>
</div>
<div v-if="!props.hideDontShowAgain" class="mb-4">
<label class="label">
<input
v-model="dontShowAgain"
class="checkbox"
type="checkbox"
>
{{ t('modal.dontShowAgain') }}
</label>
</div>
<div class="flex flex-col gap-2">
<CustomButton
v-if="!props.hideCancelButton"
:text="cancelButtonTextComputed"
block
color="default"
size="xl"
variant="ghost"
@click="handleCancel"
/>
<CustomButton
:color="props.confirmButtonColor"
:left-icon="props.confirmButtonIcon"
:text="props.confirmButtonText"
block
size="xl"
variant="soft"
@click="handleConfirm"
/>
</div>
</div>
</dialog>
</template>