|
1 | | -/******************************************************************************** |
2 | | - * Copyright (c) 2025 Contributors to the Eclipse Foundation |
3 | | - * |
4 | | - * See the NOTICE file(s) distributed with this work for additional |
5 | | - * information regarding copyright ownership. |
6 | | - * |
7 | | - * This program and the accompanying materials are made available under the |
8 | | - * terms of the Eclipse Public License v. 2.0 which is available at |
9 | | - * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and |
10 | | - * |
11 | | - * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 |
12 | | - ********************************************************************************/ |
13 | | - |
14 | | -import React from "react"; |
15 | | -import ReactDOM from "react-dom"; |
16 | | - |
17 | | -interface SpinnerTemplateProps { |
18 | | - fullScreen?: boolean; // overlay ->true, inline component -> false |
19 | | - className?: string; |
20 | | - show?: boolean; |
21 | | -} |
22 | | - |
23 | | -const SpinnerTemplate: React.FC<SpinnerTemplateProps> = ({ |
24 | | - fullScreen = true, |
25 | | - className = "", |
26 | | - show = true, |
27 | | -}) => { |
28 | | - if (!show) { |
29 | | - return null; |
30 | | - } |
31 | | - |
32 | | - const spinnerElement = <Spinner className={className} />; |
33 | | - |
34 | | - if (fullScreen) { |
35 | | - return ReactDOM.createPortal( |
36 | | - <div className="bg-transparent-400 absolute left-0 top-0 z-10 flex h-full w-full items-center justify-center text-white"> |
37 | | - <div className="bg-transparent-400 flex max-h-screen w-1/3 flex-col items-center justify-center p-4"> |
38 | | - <div className="justify-center overflow-hidden p-2"> |
39 | | - {spinnerElement} |
40 | | - </div> |
41 | | - </div> |
42 | | - </div>, |
43 | | - document.getElementById("modal-root") as HTMLElement |
44 | | - ); |
45 | | - } |
46 | | - |
47 | | - return ( |
48 | | - <div className={`flex items-center justify-center py-4 ${className}`}> |
49 | | - {spinnerElement} |
50 | | - </div> |
51 | | - ); |
52 | | -}; |
53 | | - |
54 | | -const Spinner: React.FC<{ className?: string }> = ({ className = "" }) => { |
55 | | - return ( |
56 | | - <div className={`spinner-container ${className}`}> |
57 | | - <div className="loading-spinner"></div> |
58 | | - </div> |
59 | | - ); |
60 | | -}; |
61 | | - |
62 | | -export { Spinner }; |
63 | | -export default SpinnerTemplate; |
| 1 | +/******************************************************************************** |
| 2 | + * Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 3 | + * |
| 4 | + * See the NOTICE file(s) distributed with this work for additional |
| 5 | + * information regarding copyright ownership. |
| 6 | + * |
| 7 | + * This program and the accompanying materials are made available under the |
| 8 | + * terms of the Eclipse Public License v. 2.0 which is available at |
| 9 | + * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and |
| 10 | + * |
| 11 | + * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 |
| 12 | + ********************************************************************************/ |
| 13 | + |
| 14 | +import React from "react"; |
| 15 | +import ReactDOM from "react-dom"; |
| 16 | + |
| 17 | +interface SpinnerTemplateProps { |
| 18 | + fullScreen?: boolean; // overlay ->true, inline component -> false |
| 19 | + className?: string; |
| 20 | + show?: boolean; |
| 21 | +} |
| 22 | + |
| 23 | +const SpinnerTemplate: React.FC<SpinnerTemplateProps> = ({ |
| 24 | + fullScreen = true, |
| 25 | + className = "", |
| 26 | + show = true, |
| 27 | +}) => { |
| 28 | + if (!show) { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + const spinnerElement = <Spinner className={className} />; |
| 33 | + |
| 34 | + if (fullScreen) { |
| 35 | + return ReactDOM.createPortal( |
| 36 | + <div className="bg-transparent-400 absolute left-0 top-0 z-10 flex h-full w-full items-center justify-center text-white"> |
| 37 | + <div className="bg-transparent-400 flex max-h-screen w-1/3 flex-col items-center justify-center p-4"> |
| 38 | + <div className="justify-center overflow-hidden p-2"> |
| 39 | + {spinnerElement} |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + </div>, |
| 43 | + document.getElementById("modal-root") as HTMLElement |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + return ( |
| 48 | + <div className={`flex items-center justify-center py-4 ${className}`}> |
| 49 | + {spinnerElement} |
| 50 | + </div> |
| 51 | + ); |
| 52 | +}; |
| 53 | + |
| 54 | +const Spinner: React.FC<{ className?: string }> = ({ className = "" }) => { |
| 55 | + return ( |
| 56 | + <div className={`spinner-container ${className}`}> |
| 57 | + <div className="loading-spinner"></div> |
| 58 | + </div> |
| 59 | + ); |
| 60 | +}; |
| 61 | + |
| 62 | +export { Spinner }; |
| 63 | +export default SpinnerTemplate; |
0 commit comments