Loading.tsx 843 B

123456789101112131415161718192021222324252627282930313233
  1. import { useEffect, useState } from "preact/hooks";
  2. interface LoadingGlobalHook {
  3. show: () => void;
  4. hide: () => void;
  5. }
  6. declare global {
  7. var $loading: LoadingGlobalHook | undefined;
  8. }
  9. export default function Loading() {
  10. const [visible, setVisible] = useState(false);
  11. useEffect(() => {
  12. globalThis.$loading = {
  13. show: () => setVisible(true),
  14. hide: () => setVisible(false),
  15. };
  16. return () => {
  17. delete globalThis.$loading;
  18. };
  19. }, []);
  20. return (
  21. <div className={`fixed inset-0 bg-black/60 z-[9] flex items-center justify-center ${visible ? "" : "hidden"}`}>
  22. <div className="inline-block transform translate-z-[1px]">
  23. <div className="inline-block w-16 h-16 m-2 rounded-full bg-white animate-[pd-loading-spin_5s_cubic-bezier(0,0.2,0.8,1)_infinite]" />
  24. </div>
  25. </div>
  26. );
  27. }