asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
37 lines (34 loc) • 849 B
JavaScript
import { ref } from 'vue';
import { preventScroll } from '../../utils/preventScoll.mjs';
function usePopup() {
const popupProps = ref({
isShow: false,
popupComponentName: null
});
const showPopup = (componentName, callback) => {
popupProps.value.isShow = true;
preventScroll(true);
popupProps.value.popupComponentName = componentName;
callback && callback();
};
const hidePopup = () => {
popupProps.value.isShow = false;
preventScroll(false);
};
const handlePopupEvent = (eventHandlers, event) => {
const { type, params } = event;
const handler = eventHandlers[type];
if (handler) {
handler(params);
} else {
console.warn(`Unhandled event type: ${type}`);
}
};
return {
showPopup,
hidePopup,
popupProps,
handlePopupEvent
};
}
export { usePopup };