Skip to content
Snippets Groups Projects
Commit 71370b54 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add AConfirmDialog component

parent 60c87785
No related branches found
No related tags found
No related merge requests found
<template>
<ADialog ref="dialog" is-modal @close="emit('cancel')">
<slot />
<p v-if="promptValue">
<SafeHTML
v-if="promptLabel"
:id="promptLabelId"
as="p"
:html="promptLabel"
sanitize-preset="inline-noninteractive"
class="tw-mb-2"
/>
<FormGroup v-slot="attrs">
<input
v-bind="attrs"
v-model="promptVerifyValue"
type="text"
required
:aria-labelledby="promptLabelId"
/>
</FormGroup>
</p>
<template #footer>
<div class="tw-flex tw-items-center tw-gap-3">
<button
type="button"
class="btn"
:class="confirmClass ?? 'btn-danger'"
:disabled="!canConfirm"
@click="confirm"
>
<SafeHTML :html="confirmLabel" sanitize-preset="inline-noninteractive" />
</button>
<button type="button" class="btn" @click="dialog.close()">
<SafeHTML :html="cancelLabel ?? t('cancel')" sanitize-preset="inline-noninteractive" />
</button>
</div>
</template>
</ADialog>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import ADialog from '@/components/generic/ADialog.vue'
import { useI18n } from '@/i18n'
import SafeHTML from '@/components/generic/SafeHTML'
import FormGroup from '@/components/generic/FormGroup.vue'
import { useId } from '@/util'
const props = defineProps<{
confirmLabel: string
confirmClass?: string
promptLabel?: string
promptValue?: string
cancelLabel?: string
}>()
const emit = defineEmits<{ cancel: []; confirm: [] }>()
const { t } = useI18n()
const dialog = ref()
const promptLabelId = useId('confirm-dialog-prompt-label')
const promptVerifyValue = ref('')
const canConfirm = computed(
() => typeof props.promptValue === 'undefined' || promptVerifyValue.value === props.promptValue,
)
function confirm() {
emit('confirm')
dialog.value.close()
}
onMounted(() => dialog.value.open())
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment