Made trackHover less intrusive

This commit is contained in:
thepaperpilot 2022-07-27 22:21:20 -05:00
parent 0c3ce6af45
commit 39c62f3b9c

View file

@ -214,39 +214,13 @@ export function processedPropType<T>(...types: PropTypes[]): PropType<ProcessedC
} }
export function trackHover(element: VueFeature): Ref<boolean> { export function trackHover(element: VueFeature): Ref<boolean> {
const elementComponent = element[ComponentKey];
const isHovered = ref(false); const isHovered = ref(false);
element[ComponentKey] = defineComponent({
props: {
element: {
type: Object as PropType<VueFeature>,
required: true
}
},
setup: function (props) {
const element = toRef(props, "element");
onUnmounted(() => (isHovered.value = false));
return () => (
<div
style="display: inline-block"
onPointerenter={() => (isHovered.value = true)}
onPointerleave={() => (isHovered.value = false)}
>
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
{unwrapRef(element) == null ? "" : renderJSX(unwrapRef(element)!)}
</div>
);
}
}) as GenericComponent;
const elementGatherProps = element[GatherProps].bind(element); const elementGatherProps = element[GatherProps].bind(element);
element[GatherProps] = () => ({ element[GatherProps] = () => ({
element: { ...elementGatherProps(),
[ComponentKey]: elementComponent, onPointerenter: () => (isHovered.value = true),
[GatherProps]: elementGatherProps onPointerleave: () => (isHovered.value = false)
}
}); });
return isHovered; return isHovered;