| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { computed, inject, provide } from 'vue';
- const PortalContextKey = Symbol('PortalContextKey');
- export const useProvidePortal = function (instance) {
- let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
- inTriggerContext: true
- };
- provide(PortalContextKey, {
- inTriggerContext: config.inTriggerContext,
- shouldRender: computed(() => {
- const {
- sPopupVisible,
- popupRef,
- forceRender,
- autoDestroy
- } = instance || {};
- // if (popPortal) return true;
- let shouldRender = false;
- if (sPopupVisible || popupRef || forceRender) {
- shouldRender = true;
- }
- if (!sPopupVisible && autoDestroy) {
- shouldRender = false;
- }
- return shouldRender;
- })
- });
- };
- export const useInjectPortal = () => {
- useProvidePortal({}, {
- inTriggerContext: false
- });
- const portalContext = inject(PortalContextKey, {
- shouldRender: computed(() => false),
- inTriggerContext: false
- });
- return {
- shouldRender: computed(() => portalContext.shouldRender.value || portalContext.inTriggerContext === false)
- };
- };
|