shortId.tsx 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. export default class ShortId extends React.Component<Props> {
  11. render() {
  12. const {shortId, avatar} = this.props;
  13. if (!shortId) {
  14. return null;
  15. }
  16. return (
  17. <StyledShortId {...this.props}>
  18. {avatar}
  19. <StyledAutoSelectText avatar={!!avatar}>{shortId}</StyledAutoSelectText>
  20. </StyledShortId>
  21. );
  22. }
  23. }
  24. const StyledShortId = styled('div')`
  25. font-family: ${p => p.theme.text.familyMono};
  26. display: flex;
  27. align-items: center;
  28. justify-content: flex-end;
  29. `;
  30. const StyledAutoSelectText = styled(AutoSelectText, {shouldForwardProp: isPropValid})<{
  31. avatar: boolean;
  32. }>`
  33. margin-left: ${p => p.avatar && '0.5em'};
  34. min-width: 0;
  35. `;