shortId.tsx 928 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import * as React from 'react';
  2. import isPropValid from '@emotion/is-prop-valid';
  3. import styled from '@emotion/styled';
  4. import AutoSelectText from 'app/components/autoSelectText';
  5. type Props = {
  6. shortId: string;
  7. avatar?: React.ReactNode;
  8. onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
  9. };
  10. const ShortId = ({shortId, avatar, ...props}: Props) => {
  11. if (!shortId) {
  12. return null;
  13. }
  14. return (
  15. <StyledShortId {...props}>
  16. {avatar}
  17. <StyledAutoSelectText avatar={!!avatar}>{shortId}</StyledAutoSelectText>
  18. </StyledShortId>
  19. );
  20. };
  21. const StyledShortId = styled('div')`
  22. font-family: ${p => p.theme.text.familyMono};
  23. display: flex;
  24. align-items: center;
  25. justify-content: flex-end;
  26. `;
  27. const StyledAutoSelectText = styled(AutoSelectText, {shouldForwardProp: isPropValid})<{
  28. avatar: boolean;
  29. }>`
  30. margin-left: ${p => p.avatar && '0.5em'};
  31. min-width: 0;
  32. `;
  33. export default ShortId;