{"version":3,"file":"usePopover.mjs","sources":["../../../../../../packages/components/popover/src/usePopover.ts"],"sourcesContent":["import { computed, ref, watch } from 'vue'\nimport { isString } from '@element-plus/utils/util'\nimport { usePopper } from '@element-plus/components/popper'\nimport PopupManager from '@element-plus/utils/popup-manager'\n\nimport type { SetupContext } from 'vue'\nimport type { IPopperOptions, EmitType } from '@element-plus/components/popper'\nexport interface IUsePopover extends IPopperOptions {\n  width: number | string\n}\n\nexport const SHOW_EVENT = 'show'\nexport const HIDE_EVENT = 'hide'\n\nexport default function usePopover(\n  props: IUsePopover,\n  ctx: SetupContext<string[]>\n) {\n  const zIndex = ref(PopupManager.nextZIndex())\n  const width = computed(() => {\n    if (isString(props.width)) {\n      return props.width as string\n    }\n    return `${props.width}px`\n  })\n\n  const popperStyle = computed(() => {\n    return {\n      width: width.value,\n      zIndex: zIndex.value,\n    }\n  })\n\n  const popperProps = usePopper(props, ctx as SetupContext<EmitType[]>)\n\n  watch(popperProps.visibility, (val) => {\n    if (val) {\n      zIndex.value = PopupManager.nextZIndex()\n    }\n    ctx.emit(val ? SHOW_EVENT : HIDE_EVENT)\n  })\n\n  return {\n    ...popperProps,\n    popperStyle,\n  }\n}\n"],"names":[],"mappings":";;;;;;;MAWa,aAAa;MACb,aAAa;oBAGxB,OACA,KACA;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,QAAQ,SAAS,MAAM;AAC3B,QAAI,SAAS,MAAM,QAAQ;AACzB,aAAO,MAAM;AAAA;AAEf,WAAO,GAAG,MAAM;AAAA;AAGlB,QAAM,cAAc,SAAS,MAAM;AACjC,WAAO;AAAA,MACL,OAAO,MAAM;AAAA,MACb,QAAQ,OAAO;AAAA;AAAA;AAInB,QAAM,cAAc,UAAU,OAAO;AAErC,QAAM,YAAY,YAAY,CAAC,QAAQ;AACrC,QAAI,KAAK;AACP,aAAO,QAAQ,aAAa;AAAA;AAE9B,QAAI,KAAK,MAAM,aAAa;AAAA;AAG9B,SAAO;AAAA,OACF;AAAA,IACH;AAAA;AAAA;;;;"}