Loading Overlay

Overlay & Feedback

Full-screen loading spinner overlay.

Preview

Usage

example.jsx
import { LoadingOverlay } from "@/components/ui/loading-overlay";

export default function Example() {
  return <LoadingOverlay />;
}

Source Code

Copy this file into components/ui/loading-overlay.jsx in your project.

loading-overlay.jsx
"use client";

import { forwardRef } from "react";
import { cn } from "@/lib/utils";

const LoadingOverlay = forwardRef(({ className, loading, children, label = "Loading...", ...props }, ref) => (
  <div ref={ref} className={cn("relative", className)} {...props}>
    {children}
    {loading && (
      <div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 rounded-[inherit] bg-background/80 backdrop-blur-sm">
        <div className="h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-primary" />
        <span className="text-sm text-muted-foreground">{label}</span>
      </div>
    )}
  </div>
));
LoadingOverlay.displayName = "LoadingOverlay";

export { LoadingOverlay };

Quick Install

Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.

npm install clsx tailwind-merge