feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user