import { Box, Typography } from "@mui/material"; import { BarSpinner } from "./Spinners/BarSpinner/BarSpinner"; import { CSSProperties } from "react"; export type LoaderListStatus = "LOADING" | "NO_RESULTS" interface ListLoaderProps { isLoading: boolean; loadingMessage?: string; // Optional message while loading resultsLength: number; noResultsMessage?: string; // Optional message when no results children: React.ReactNode; // Required, to render the list content loaderList?: (status: LoaderListStatus) => React.ReactNode; // Function type loaderHeight?: CSSProperties } export const ListLoader = ({ isLoading, loadingMessage, resultsLength, children, noResultsMessage, loaderList, loaderHeight }: ListLoaderProps) => { return ( <> {loaderList && isLoading && ( <> {loaderList("LOADING")} )} {loaderList && !isLoading && resultsLength === 0 && ( <> {loaderList("NO_RESULTS")} )} {!loaderList && isLoading && ( {loadingMessage || `Fetching list`} )} {!loaderList && !isLoading && resultsLength === 0 && ( {noResultsMessage} )} {!isLoading && resultsLength > 0 && <>{children}} ); };