loadingContainer.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import styled from '@emotion/styled';
  2. import LoadingIndicator from 'sentry/components/loadingIndicator';
  3. import theme from 'sentry/utils/theme';
  4. export type LoadingContainerProps = {
  5. children?: React.ReactNode;
  6. className?: string;
  7. isLoading?: boolean;
  8. isReloading?: boolean;
  9. maskBackgroundColor?: string;
  10. };
  11. type MaskProps = {
  12. isReloading: boolean;
  13. maskBackgroundColor: string;
  14. };
  15. export default function LoadingContainer({
  16. isLoading = false,
  17. isReloading = false,
  18. maskBackgroundColor = theme.white,
  19. className,
  20. children,
  21. }: LoadingContainerProps) {
  22. const isLoadingOrReloading = isLoading || isReloading;
  23. return (
  24. <Container className={className}>
  25. {isLoadingOrReloading && (
  26. <div>
  27. <LoadingMask
  28. isReloading={isReloading}
  29. maskBackgroundColor={maskBackgroundColor}
  30. />
  31. <Indicator />
  32. </div>
  33. )}
  34. {children}
  35. </Container>
  36. );
  37. }
  38. const Container = styled('div')`
  39. position: relative;
  40. `;
  41. const LoadingMask = styled('div')<MaskProps>`
  42. position: absolute;
  43. z-index: 1;
  44. background-color: ${p => p.maskBackgroundColor};
  45. width: 100%;
  46. height: 100%;
  47. opacity: ${p => (p.isReloading ? '0.6' : '1')};
  48. `;
  49. const Indicator = styled(LoadingIndicator)`
  50. position: absolute;
  51. z-index: 3;
  52. width: 100%;
  53. `;