UNPKG

nuke-modal

Version:

模态框

38 lines (33 loc) 1.26 kB
/** @jsx createElement */ import { createElement, findDOMNode, unmountComponentAtNode, render } from 'rax'; import { isWeb } from 'nuke-env'; import ToastComponent from './toast-component'; export default function show(options, duration, node = null) { const { message, icon, ...others } = options; if (isWeb) { const ToastInnerComponent = ( <ToastComponent message={message} icon={icon} duration={duration} {...others} onClose={afterCloseCallback} /> ); let container, MaskInstance, wrapId = '_nuke_wrap'; container = document.getElementById(wrapId); if (!container) { container = document.createElement('div'); container.setAttribute('id', wrapId); container.setAttribute('style', 'position:absolute;top:0;left:0;width:100%;height:100%;display:flex;'); document.body.appendChild(container); container = document.getElementById(wrapId); } render(ToastInnerComponent, findDOMNode(document.getElementById(wrapId)), function () { MaskInstance = this; }); function afterCloseCallback() { if (container) { unmountComponentAtNode(container); document.body.removeChild(container); container = MaskInstance = null; } } } }