baseBadge.tsx 2.0 KB

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