emptyMessage.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import space from 'sentry/styles/space';
  4. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  5. interface Props extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
  6. action?: React.ReactElement;
  7. description?: React.ReactNode;
  8. icon?: React.ReactNode;
  9. leftAligned?: boolean;
  10. size?: 'large' | 'medium';
  11. title?: React.ReactNode;
  12. }
  13. type WrapperProps = Pick<Props, 'size'>;
  14. const EmptyMessage = styled(
  15. ({
  16. title,
  17. description,
  18. icon,
  19. children,
  20. action,
  21. leftAligned: _leftAligned,
  22. ...props
  23. }: Props) => (
  24. <div data-test-id="empty-message" {...props}>
  25. {icon && <IconWrapper>{icon}</IconWrapper>}
  26. {title && <Title noMargin={!description && !children && !action}>{title}</Title>}
  27. {description && <Description>{description}</Description>}
  28. {children && <Description noMargin>{children}</Description>}
  29. {action && <Action>{action}</Action>}
  30. </div>
  31. )
  32. )<WrapperProps>`
  33. display: flex;
  34. ${p =>
  35. p.leftAligned
  36. ? css`
  37. max-width: 70%;
  38. align-items: flex-start;
  39. padding: ${space(4)};
  40. `
  41. : css`
  42. text-align: center;
  43. align-items: center;
  44. padding: ${space(4)} 15%;
  45. `};
  46. flex-direction: column;
  47. color: ${p => p.theme.textColor};
  48. font-size: ${p =>
  49. p.size && p.size === 'large' ? p.theme.fontSizeExtraLarge : p.theme.fontSizeMedium};
  50. `;
  51. const IconWrapper = styled('div')`
  52. color: ${p => p.theme.gray200};
  53. margin-bottom: ${space(1)};
  54. `;
  55. const Title = styled('strong')<{noMargin: boolean}>`
  56. font-size: ${p => p.theme.fontSizeExtraLarge};
  57. ${p => !p.noMargin && `margin-bottom: ${space(1)};`}
  58. `;
  59. const Description = styled(TextBlock)`
  60. margin: 0;
  61. `;
  62. const Action = styled('div')`
  63. margin-top: ${space(2)};
  64. `;
  65. export default EmptyMessage;