UNPKG

@resourge/react-fetch

Version:

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

61 lines (58 loc) 1.62 kB
/** * react-fetch v1.43.1 * * Copyright (c) resourge. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import { useState } from 'react'; import { createPortal } from 'react-dom'; import Loader from '../Loader'; import { GlobalLoading } from './GlobalLoading'; import { setGlobalLoading, globalColor } from './constants'; import { jsx } from 'react/jsx-runtime'; const GlobalLoader = ({ loaderId, style, children, color = globalColor }) => { const [portalContainer] = useState(() => { let portalContainer = document.getElementById('global-loader'); if (!portalContainer) { portalContainer = document.createElement('div'); portalContainer.id = 'global-loader'; document.body.appendChild(portalContainer); } return portalContainer; }); const globalLoading = setGlobalLoading(children != null ? children : jsx(GlobalLoading, { color: color })); return jsx(Loader, { loaderId: loaderId, loadingElement: (createPortal(jsx("div", { style: { position: 'fixed', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0.25)', zIndex: 10000, WebkitBackdropFilter: 'blur(3px)', backdropFilter: 'blur(3px)', ...style }, children: globalLoading }), portalContainer)) }); }; export { GlobalLoader as default }; //# sourceMappingURL=GlobalLoader.js.map