53 lines
1.7 KiB
Vue
53 lines
1.7 KiB
Vue
<script setup lang="ts">
|
|
import { computed, provide, watchEffect, onUnmounted, useAttrs } from "vue";
|
|
import { DialogTitle } from "reka-ui";
|
|
import { alertDialogVariants } from "@heroui-vue/styles";
|
|
import OverlayDialogContent from "../overlay/OverlayDialogContent.vue";
|
|
import { surfaceContextKey } from "../surface/context";
|
|
import { useAlertDialog } from "./context";
|
|
defineOptions({ inheritAttrs: false });
|
|
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
|
|
as: "div",
|
|
});
|
|
const ctx = useAlertDialog();
|
|
const attrs = useAttrs();
|
|
watchEffect(() => {
|
|
ctx.contentId.value = props.id ?? ctx.defaultId;
|
|
});
|
|
onUnmounted(() => {
|
|
ctx.contentId.value = ctx.defaultId;
|
|
});
|
|
provide(surfaceContextKey, { variant: computed(() => "default" as const) });
|
|
</script>
|
|
<template>
|
|
<OverlayDialogContent
|
|
v-bind="attrs"
|
|
:as="as"
|
|
:id="ctx.contentId.value"
|
|
:class="alertDialogVariants({ size: ctx.size.value }).dialog()"
|
|
:is-dismissable="ctx.dismissable.value"
|
|
:is-keyboard-dismiss-disabled="ctx.keyboardDisabled.value"
|
|
role="alertdialog"
|
|
data-slot="alert-dialog-dialog"
|
|
:data-exiting="!ctx.state.isOpen.value || undefined"
|
|
:data-placement="ctx.placement.value"
|
|
:aria-labelledby="
|
|
'aria-labelledby' in attrs
|
|
? (attrs['aria-labelledby'] as string)
|
|
: Array.from(ctx.titles.values()).join(' ') || undefined
|
|
"
|
|
:aria-describedby="attrs['aria-describedby'] as string | undefined"
|
|
>
|
|
<DialogTitle
|
|
v-if="
|
|
('aria-label' in attrs || 'aria-labelledby' in attrs) &&
|
|
!ctx.titles.size
|
|
"
|
|
as="span"
|
|
class="sr-only"
|
|
aria-hidden="true"
|
|
/>
|
|
<slot :close="ctx.state.close" :is-open="ctx.state.isOpen.value" />
|
|
</OverlayDialogContent>
|
|
</template>
|