shortId.tsx 1.1 KB

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