baseBadge.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {memo} from 'react';
  2. import styled from '@emotion/styled';
  3. import Avatar from 'sentry/components/avatar';
  4. import space from 'sentry/styles/space';
  5. import {AvatarProject, Organization, Team} from 'sentry/types';
  6. type Props = {
  7. displayName: React.ReactNode;
  8. avatarProps?: Record<string, any>;
  9. avatarSize?: number;
  10. className?: string;
  11. description?: React.ReactNode;
  12. // Hides the main display name
  13. hideAvatar?: boolean;
  14. hideName?: boolean;
  15. organization?: Organization;
  16. project?: AvatarProject;
  17. team?: Team;
  18. };
  19. const BaseBadge = memo(
  20. ({
  21. displayName,
  22. hideName = false,
  23. hideAvatar = false,
  24. avatarProps = {},
  25. avatarSize = 24,
  26. description,
  27. team,
  28. organization,
  29. project,
  30. className,
  31. }: Props) => (
  32. <Wrapper className={className}>
  33. {!hideAvatar && (
  34. <StyledAvatar
  35. {...avatarProps}
  36. size={avatarSize}
  37. hideName={hideName}
  38. team={team}
  39. organization={organization}
  40. project={project}
  41. data-test-id="badge-styled-avatar"
  42. />
  43. )}
  44. {(!hideName || !!description) && (
  45. <DisplayNameAndDescription>
  46. {!hideName && (
  47. <DisplayName data-test-id="badge-display-name">{displayName}</DisplayName>
  48. )}
  49. {!!description && <Description>{description}</Description>}
  50. </DisplayNameAndDescription>
  51. )}
  52. </Wrapper>
  53. )
  54. );
  55. export default BaseBadge;
  56. const Wrapper = styled('div')`
  57. display: flex;
  58. align-items: center;
  59. flex-shrink: 0;
  60. `;
  61. const StyledAvatar = styled(Avatar)<{hideName: boolean}>`
  62. margin-right: ${p => (p.hideName ? 0 : space(1))};
  63. flex-shrink: 0;
  64. `;
  65. const DisplayNameAndDescription = styled('div')`
  66. display: flex;
  67. flex-direction: column;
  68. line-height: 1.2;
  69. overflow: hidden;
  70. `;
  71. const DisplayName = styled('span')`
  72. overflow: hidden;
  73. text-overflow: ellipsis;
  74. line-height: 1.2;
  75. `;
  76. const Description = styled('div')`
  77. font-size: 0.875em;
  78. margin-top: ${space(0.25)};
  79. color: ${p => p.theme.gray300};
  80. line-height: 14px;
  81. ${p => p.theme.overflowEllipsis};
  82. `;