Loading.tsx 887 B

12345678910111213141516171819202122232425262728293031323334353637
  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
  22. className={`fixed inset-0 bg-black/60 z-[9] flex items-center justify-center ${
  23. visible ? "" : "hidden"
  24. }`}
  25. >
  26. <div className="inline-block transform translate-z-[1px]">
  27. <div className="inline-block w-16 h-16 m-2 rounded-full bg-white dark:bg-gray-200 animate-[pd-loading-spin_5s_cubic-bezier(0,0.2,0.8,1)_infinite]" />
  28. </div>
  29. </div>
  30. );
  31. }