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
|
<template>
<div id="confirm-prompt">
<Dialog class="modal-entry" :style="style" :open="isRevealed" @close="cancel" >
<div class="modal-content-container">
<DialogPanel>
<DialogTitle class="modal-title">
{{ title }}
</DialogTitle>
<DialogDescription class="modal-description">
{{ message.text }}
</DialogDescription>
<p class="modal-text-secondary">
{{ message.subtext }}
</p>
<div class="modal-button-container">
<button class="rounded btn sm primary" @click="confirm">
Confirm
</button>
<button class="rounded btn sm" @click="cancel">
Close
</button>
</div>
</DialogPanel>
</div>
</Dialog>
</div>
</template>
<script setup lang="ts">
import { defaultTo } from 'lodash'
import { computed, ref } from 'vue'
import {
Dialog,
DialogPanel,
DialogTitle,
DialogDescription,
} from '@headlessui/vue'
import { onClickOutside } from '@vueuse/core'
import { useConfirm, useEnvSize } from '@vnuge/vnlib.browser'
const { headerHeight } = useEnvSize()
//Use component side of confirm
const { isRevealed, confirm, cancel, onReveal } = useConfirm()
const dialog = ref(null)
const message = ref({})
//Cancel prompt when user clicks outside of dialog, only when its open
onClickOutside(dialog, () => isRevealed.value ? cancel() : null)
//Set message on reveal
onReveal(m => message.value = m);
const title = computed(() => defaultTo(message.value.title, 'Confirm'))
const style = computed(() => {
return {
'height': `calc(100vh - ${headerHeight.value}px)`,
'top': `${headerHeight.value}px`
}
})
</script>
|