UNPKG

chowa

Version:

UI component library based on React

59 lines (58 loc) 1.86 kB
/** * @license chowa v1.1.3 * * Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn). * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const React = require("react"); const ReactDom = require("react-dom"); const nprogress_1 = require("./nprogress"); const utils_1 = require("../utils"); class $nprogress { static start(props) { if (this.instance !== null) { return this.instance.set(0); } const mountNode = document.createElement('div'); document.body.appendChild(mountNode); const insProps = Object.assign(Object.assign({}, props), { onHide: () => { ReactDom.unmountComponentAtNode(mountNode); document.body.removeChild(mountNode); this.instance = null; if (typeof props === 'object' && utils_1.hasProperty(props, 'onHide')) { props.onHide(); } } }); ReactDom.render(React.createElement(nprogress_1.default, Object.assign({ ref: (ins) => { if (ins === null) { return; } this.instance = ins; this.instance.start(); } }, insProps)), mountNode); } static done() { if (this.instance === null) { return; } this.instance.done(); } static set(percent) { if (this.instance === null) { $nprogress.start(); } this.instance.set(percent); } static inc() { if (this.instance === null) { $nprogress.start(); } this.instance.inc(); } } $nprogress.instance = null; exports.default = $nprogress;