import React from "react" ; import { createPortalDOM } from "../utils/dom" ; import { DialogType } from "./style" ; import { WrapperProps , Wrapper } from "./Wrapper" ; import isPlainObject from "lodash/isPlainObject" ; import omit from "lodash/omit" ; export interface ShowDialogOption extends WrapperProps { blankClosable ? : boolean ; content ? : React . ReactNode ; type ? : DialogType ; } param option returns export function showDialog ( option ) { const { mount , destroy } = createPortalDOM ( ) ; let config = { status : "show" , blankClosable : false } ; if ( React . isValidElement ( option ) || ! isPlainObject ( option ) ) { config . content = option ; } else { config = { ... config , ... ( option as ShowDialogOption ) } ; } const blankClosable = ! ! config . blankClosable ; const children = config . content ; const onBlankClick = config . onBlankClick ; const onHide = config . onHide ; const props = omit ( config , [ "blankClosable" , "content" , "onHide" ] ) ; const closeDialog = async ( ) => { props . status = "hide" ; props . onHide = ( ) => { destroy ( ) ; onHide ?. ( ) ; } ; await mount ( < Wrapper { ... props } > { children } < /Wrapper>); } ; if ( blankClosable ) { props . onBlankClick = async ( event ) => { await closeDialog ( ) ; onBlankClick ?. ( event ) ; } ; } const amountShow = mount ( < Wrapper { ... props } > { children } < /Wrapper>); return async ( ) => { await amountShow ; await closeDialog ( ) ; } ; }