TBodyShortUrl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled from 'styled-components';
  4. import { CopyToClipboard } from 'react-copy-to-clipboard';
  5. import TBodyButton from './TBodyButton';
  6. const Wrapper = styled.div`
  7. display: flex;
  8. align-items: center;
  9. `;
  10. const CopyText = styled.div`
  11. position: absolute;
  12. top: 0;
  13. left: 40px;
  14. font-size: 11px;
  15. color: green;
  16. `;
  17. const Icon = styled.img`
  18. width: 12px;
  19. height: 12px;
  20. `;
  21. const TBodyShortUrl = ({ index, copiedIndex, handleCopy, url }) => (
  22. <Wrapper>
  23. {copiedIndex === index && <CopyText>Copied to clipboard!</CopyText>}
  24. <CopyToClipboard onCopy={() => handleCopy(index)} text={`${url.shortUrl}`}>
  25. <TBodyButton>
  26. <Icon src="/images/copy.svg" />
  27. </TBodyButton>
  28. </CopyToClipboard>
  29. <a href={`${url.shortUrl}`}>{`${url.shortUrl.replace(/^https?:\/\//, '')}`}</a>
  30. </Wrapper>
  31. );
  32. TBodyShortUrl.propTypes = {
  33. copiedIndex: PropTypes.number.isRequired,
  34. handleCopy: PropTypes.func.isRequired,
  35. index: PropTypes.number.isRequired,
  36. url: PropTypes.shape({
  37. id: PropTypes.string.isRequired,
  38. }).isRequired,
  39. };
  40. export default TBodyShortUrl;