ShortenerResult.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Button from '../Button';
  6. import Loading from '../PageLoading';
  7. import { fadeIn } from '../../helpers/animations';
  8. const Wrapper = styled.div`
  9. position: relative;
  10. display: flex;
  11. justify-content: center;
  12. align-items: center;
  13. button {
  14. margin-left: 24px;
  15. }
  16. `;
  17. const Url = styled.h2`
  18. margin: 8px 0;
  19. font-size: 32px;
  20. font-weight: 300;
  21. border-bottom: 2px dotted #aaa;
  22. cursor: pointer;
  23. transition: all 0.2s ease;
  24. :hover {
  25. opacity: 0.5;
  26. }
  27. @media only screen and (max-width: 448px) {
  28. font-size: 24px;
  29. }
  30. `;
  31. const CopyMessage = styled.p`
  32. position: absolute;
  33. top: -32px;
  34. left: 0;
  35. font-size: 14px;
  36. color: #689f38;
  37. animation: ${fadeIn} 0.3s ease-out;
  38. `;
  39. const ShortenerResult = ({ copyHandler, isCopied, loading, url }) =>
  40. loading ? (
  41. <Loading />
  42. ) : (
  43. <Wrapper>
  44. {isCopied && <CopyMessage>Copied to clipboard.</CopyMessage>}
  45. <CopyToClipboard text={url.list[0].shortUrl} onCopy={copyHandler}>
  46. <Url>{url.list[0].shortUrl.replace(/^https?:\/\//, '')}</Url>
  47. </CopyToClipboard>
  48. <CopyToClipboard text={url.list[0].shortUrl} onCopy={copyHandler}>
  49. <Button icon="copy">Copy</Button>
  50. </CopyToClipboard>
  51. </Wrapper>
  52. );
  53. ShortenerResult.propTypes = {
  54. copyHandler: PropTypes.func.isRequired,
  55. isCopied: PropTypes.bool.isRequired,
  56. loading: PropTypes.bool.isRequired,
  57. url: PropTypes.shape({
  58. list: PropTypes.array.isRequired,
  59. }).isRequired,
  60. };
  61. export default ShortenerResult;