This repository has been archived on 2024-06-14. You can view files and clone it, but cannot push or open issues or pull requests.
icynet-admin/components/common/Modal/services/ModalService.ts

29 lines
736 B
TypeScript

import {
ModalType,
ModalEventDetail,
} from '../../../../lib/types/modal.interface';
const ModalService = {
on(event: string, callback: (props: ModalEventDetail<Object>) => void) {
document.addEventListener(event, (e: Event) =>
callback((e as CustomEvent<ModalEventDetail<Object>>).detail)
);
},
open<T>(component: ModalType<T>, props: any = {}) {
return new Promise((resolve, _) => {
document.dispatchEvent(
new CustomEvent<ModalEventDetail<T>>('open', {
detail: {
component,
props,
resolve,
target: (document.activeElement as HTMLElement) || undefined,
},
})
);
});
},
};
export default ModalService;