import React, {useState} from 'react' import ReactDOM from 'react-dom' import styles from './style.module.css' interface Props { node: HTMLDivElement, children: any, stateChange?: Function, show?: boolean, title?: string } function Dialog({node, children, stateChange, show = false, title}: Props) { const [ishow, setIShow] = useState(false) const showChange = (show: boolean) => { setIShow(show) stateChange && stateChange(show) } if (show !== ishow) { setIShow(show) return null } const Layer = ishow ? (
showChange(false)}> {title &&
{title}
}
{children}
showChange(false)} >取消 showChange(true)}>确定
) : null return ReactDOM.createPortal(Layer, node) } const node = document.querySelector('#dialog') const GDialog = (props: any) => export default GDialog