alertMessage.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import styled from '@emotion/styled';
  2. import {Alert} from 'sentry/components/alert';
  3. import {Button} from 'sentry/components/button';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {IconClose} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import AlertStore from 'sentry/stores/alertStore';
  8. type Props = {
  9. alert: ReturnType<(typeof AlertStore)['getState']>[number];
  10. system: boolean;
  11. };
  12. function AlertMessage({alert, system}: Props) {
  13. const handleClose = () => AlertStore.closeAlert(alert);
  14. const {url, message, type, opaque} = alert;
  15. return (
  16. <StyledAlert
  17. type={type}
  18. showIcon
  19. system={system}
  20. opaque={opaque}
  21. trailingItems={
  22. <StyledCloseButton
  23. icon={<IconClose size="sm" />}
  24. aria-label={t('Close')}
  25. onClick={alert.onClose ?? handleClose}
  26. size="zero"
  27. borderless
  28. />
  29. }
  30. >
  31. {url ? <ExternalLink href={url}>{message}</ExternalLink> : message}
  32. </StyledAlert>
  33. );
  34. }
  35. export default AlertMessage;
  36. const StyledAlert = styled(Alert)`
  37. margin: 0;
  38. `;
  39. const StyledCloseButton = styled(Button)`
  40. background-color: transparent;
  41. transition: opacity 0.1s linear;
  42. &:hover,
  43. &:focus {
  44. background-color: transparent;
  45. opacity: 1;
  46. }
  47. `;