import { inject, provide, computed, type Ref, type InjectionKey } from 'vue' export const portalTargetInjectionKey: InjectionKey> = Symbol('nuxt-ui.portal-target') export function usePortal(portal: Ref) { const portalTarget = inject(portalTargetInjectionKey, undefined) const to = computed(() => { if (typeof portal.value === 'boolean' || portal.value === undefined) { return portalTarget?.value ?? 'body' } return portal.value }) const disabled = computed(() => typeof portal.value === 'boolean' ? !portal.value : false) provide(portalTargetInjectionKey, computed(() => to.value)) return computed(() => ({ to: to.value, disabled: disabled.value })) }