33 lines
900 B
Vue
33 lines
900 B
Vue
<script setup lang="ts">
|
|
import { useAttrs, onBeforeUpdate, onUnmounted } from "vue";
|
|
import { usePopover } from "./context";
|
|
defineOptions({ inheritAttrs: false });
|
|
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
|
|
const ctx = usePopover();
|
|
const attrs = useAttrs();
|
|
const keys = ["aria-label", "aria-labelledby", "aria-describedby", "role"];
|
|
function sync() {
|
|
const next = Object.fromEntries(
|
|
keys.filter((key) => key in attrs).map((key) => [key, attrs[key]]),
|
|
);
|
|
const previous = ctx.dialogAttrs.value;
|
|
if (keys.some((key) => next[key] !== previous[key]))
|
|
ctx.dialogAttrs.value = next;
|
|
}
|
|
sync();
|
|
onBeforeUpdate(sync);
|
|
onUnmounted(() => {
|
|
ctx.dialogAttrs.value = {};
|
|
});
|
|
</script>
|
|
<template>
|
|
<component
|
|
:is="as"
|
|
v-bind="$attrs"
|
|
class="hv-popover__dialog"
|
|
data-slot="popover-dialog"
|
|
>
|
|
<slot :close="ctx.state.close" />
|
|
</component>
|
|
</template>
|