"use client" import { ReactNode } from "react" import { cn } from "../utils/cn" interface ContentLoadingContainerProps { /** * Whether the content is currently loading */ isLoading: boolean /** * The actual content to display when not loading */ children: ReactNode /** * The skeleton component to show during loading */ skeletonComponent: ReactNode /** * Additional CSS classes */ className?: string /** * Minimum height to prevent layout jumps */ minHeight?: string /** * Loading overlay opacity (0-1) */ loadingOpacity?: number /** * Transition duration in milliseconds */ transitionDuration?: number } /** * ContentLoadingContainer * * A unified loading container that wraps card grids and manages loading states * while keeping UI controls persistent. This component: * * - Shows skeleton loading only in content area * - Maintains consistent layout dimensions during loading * - Provides smooth transitions between loading and loaded states * - Prevents layout jumps by preserving container height * - Supports customizable skeleton components for different content types * * Usage: * ```tsx * } * minHeight="min-h-[800px]" * > * * * ``` */ export function ContentLoadingContainer({ isLoading, children, skeletonComponent, className, minHeight = "min-h-[300px] md:min-h-[800px]", loadingOpacity = 1, transitionDuration = 300, }: ContentLoadingContainerProps) { return (
{/* Loading Skeleton Overlay */} {isLoading && (
{skeletonComponent}
)} {/* Actual Content */}
{children}
) } /** * Hook for managing content loading states with common patterns */ export function useContentLoading(isLoading: boolean) { const containerProps = { 'aria-busy': isLoading, 'data-loading': isLoading } const getSkeletonCount = (contentType: 'vendor' | 'blog') => { return contentType === 'vendor' ? 12 : 6 } const getMinHeight = (contentType: 'vendor' | 'blog') => { // Vendor cards are typically taller, need more space return contentType === 'vendor' ? "min-h-[400px] md:min-h-[900px]" : "min-h-[300px] md:min-h-[800px]" } return { containerProps, getSkeletonCount, getMinHeight } }