winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
37 lines (36 loc) • 1.1 kB
JavaScript
import { ref, onMounted, onBeforeUnmount } from "vue";
import { useMemo } from "vooks";
import { on, off } from "evtd";
const teleportDisabled = "__disabled__";
function useAdjustedTo(props) {
const fullscreenElementRef = ref();
if (typeof document !== "undefined") {
fullscreenElementRef.value = document.fullscreenElement;
const handleFullscreenChange = () => {
fullscreenElementRef.value = document.fullscreenElement;
};
onMounted(() => {
on("fullscreenchange", document, handleFullscreenChange);
});
onBeforeUnmount(() => {
off("fullscreenchange", document, handleFullscreenChange);
});
}
return useMemo(() => {
const { to } = props;
if (to !== void 0) {
if (to === false)
return teleportDisabled;
if (to === true)
return fullscreenElementRef.value || "body";
return to;
}
return to != null ? to : fullscreenElementRef.value || "body";
});
}
useAdjustedTo.tdkey = teleportDisabled;
useAdjustedTo.propTo = {
type: [String, Object, Boolean],
default: void 0
};
export { useAdjustedTo };