shortId.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import AutoSelectText from 'sentry/components/autoSelectText';
  4. import Link from 'sentry/components/links/link';
  5. type Props = {
  6. shortId: string;
  7. avatar?: React.ReactNode;
  8. onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
  9. /**
  10. * A router target destination
  11. */
  12. to?: React.ComponentProps<typeof Link>['to'];
  13. className?: string;
  14. };
  15. function ShortId({shortId, avatar, onClick, to, className}: Props) {
  16. if (!shortId) {
  17. return null;
  18. }
  19. return (
  20. <StyledShortId onClick={onClick} className={className}>
  21. {avatar}
  22. {to ? (
  23. <Link to={to}>{shortId}</Link>
  24. ) : (
  25. <StyledAutoSelectText>{shortId}</StyledAutoSelectText>
  26. )}
  27. </StyledShortId>
  28. );
  29. }
  30. const StyledShortId = styled('div')`
  31. font-family: ${p => p.theme.text.familyMono};
  32. display: grid;
  33. grid-auto-flow: column;
  34. grid-gap: 0.5em;
  35. align-items: center;
  36. justify-content: flex-end;
  37. `;
  38. const StyledAutoSelectText = styled(AutoSelectText)`
  39. min-width: 0;
  40. a & {
  41. color: ${p => p.theme.linkColor};
  42. }
  43. `;
  44. export default ShortId;