loadingContainer.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import theme from 'sentry/utils/theme';
  5. const defaultProps = {
  6. isLoading: false,
  7. isReloading: false,
  8. maskBackgroundColor: theme.white,
  9. };
  10. type DefaultProps = Readonly<typeof defaultProps>;
  11. type Props = {
  12. children?: React.ReactNode;
  13. className?: string;
  14. } & DefaultProps;
  15. type MaskProps = {
  16. isReloading: boolean;
  17. maskBackgroundColor: string;
  18. };
  19. export default function LoadingContainer(props: Props) {
  20. const {className, children, isReloading, isLoading, maskBackgroundColor} = props;
  21. const isLoadingOrReloading = isLoading || isReloading;
  22. return (
  23. <Container className={className}>
  24. {isLoadingOrReloading && (
  25. <div>
  26. <LoadingMask
  27. isReloading={isReloading}
  28. maskBackgroundColor={maskBackgroundColor}
  29. />
  30. <Indicator />
  31. </div>
  32. )}
  33. {children}
  34. </Container>
  35. );
  36. }
  37. LoadingContainer.defaultProps = defaultProps;
  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. `;