(props = {}, type)
| 6 | const className = '.el-notification'; |
| 7 | |
| 8 | export default function NotificationCenter(props = {}, type) { |
| 9 | const div = document.createElement('div'); |
| 10 | |
| 11 | document.body.appendChild(div); |
| 12 | |
| 13 | if (typeof props === 'string' || React.isValidElement(props)) { |
| 14 | props = { |
| 15 | message: props |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | if (type) { |
| 20 | props.type = type; |
| 21 | } |
| 22 | |
| 23 | if (!props.offset) { |
| 24 | props.offset = 0 |
| 25 | } |
| 26 | |
| 27 | const instances = document.querySelectorAll(className) |
| 28 | |
| 29 | const lastInstance = instances[instances.length - 1]; |
| 30 | |
| 31 | props.top = (lastInstance ? (parseInt(lastInstance.style.top) + lastInstance.offsetHeight) : props.offset) + 16; |
| 32 | |
| 33 | const element = React.createElement(Notification, Object.assign({}, props, { |
| 34 | willUnmount(height, top) { |
| 35 | setTimeout(() => document.body.removeChild(div)); |
| 36 | requestAnimationFrame(() => { |
| 37 | const instances = document.querySelectorAll(className); |
| 38 | const len = instances.length; |
| 39 | for (let i = 0; i < len; i++) { |
| 40 | const element = instances[i]; |
| 41 | const elementTop = parseInt(element.style.top); |
| 42 | if (elementTop > top) { |
| 43 | element.style.top = `${elementTop - height - 16}px`; |
| 44 | } |
| 45 | } |
| 46 | }) |
| 47 | } |
| 48 | })); |
| 49 | |
| 50 | ReactDOM.render(element, div); |
| 51 | } |
| 52 | |
| 53 | /* eslint-disable */ |
| 54 | ['success', 'warning', 'info', 'error'].forEach(type => { |
no test coverage detected