ShortenerResult.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React, { FC, useState } from 'react';
  2. import styled from 'styled-components';
  3. import { CopyToClipboard } from 'react-copy-to-clipboard';
  4. import QRCode from 'qrcode.react';
  5. import { Flex } from 'reflexbox/styled-components';
  6. import Button from '../Button';
  7. import Loading from '../PageLoading';
  8. import { fadeIn } from '../../helpers/animations';
  9. import TBodyButton from '../Table/TBody/TBodyButton';
  10. import Modal from '../Modal';
  11. // TODO: types
  12. interface Props {
  13. copyHandler: any;
  14. isCopied: boolean;
  15. loading: boolean;
  16. url: {
  17. list: any[];
  18. };
  19. }
  20. const Wrapper = styled(Flex).attrs({
  21. justifyContent: 'center',
  22. alignItems: 'center',
  23. })`
  24. position: relative;
  25. button {
  26. margin-left: 24px;
  27. }
  28. `;
  29. const Url = styled.h2`
  30. margin: 8px 0;
  31. font-size: 32px;
  32. font-weight: 300;
  33. border-bottom: 2px dotted #aaa;
  34. cursor: pointer;
  35. transition: all 0.2s ease;
  36. :hover {
  37. opacity: 0.5;
  38. }
  39. @media only screen and (max-width: 448px) {
  40. font-size: 24px;
  41. }
  42. `;
  43. const CopyMessage = styled.p`
  44. position: absolute;
  45. top: -32px;
  46. left: 0;
  47. font-size: 14px;
  48. color: #689f38;
  49. animation: ${fadeIn} 0.3s ease-out;
  50. `;
  51. const QRButton = styled(TBodyButton)`
  52. width: 36px;
  53. height: 36px;
  54. margin-left: 12px !important;
  55. box-shadow: 0 4px 10px rgba(100, 100, 100, 0.2);
  56. :hover {
  57. box-shadow: 0 4px 10px rgba(100, 100, 100, 0.3);
  58. }
  59. @media only screen and (max-width: 768px) {
  60. height: 32px;
  61. width: 32px;
  62. img {
  63. width: 14px;
  64. height: 14px;
  65. }
  66. }
  67. `;
  68. const Icon = styled.img`
  69. width: 16px;
  70. height: 16px;
  71. `;
  72. const ShortenerResult: FC<Props> = ({
  73. copyHandler,
  74. isCopied,
  75. loading,
  76. url,
  77. }) => {
  78. const [qrModal, setQrModal] = useState(false);
  79. const toggleQrCodeModal = () => setQrModal(current => !current);
  80. const showQrCode = window.innerWidth > 420;
  81. if (loading) return <Loading />;
  82. return (
  83. <Wrapper>
  84. {isCopied && <CopyMessage>Copied to clipboard.</CopyMessage>}
  85. <CopyToClipboard text={url.list[0].shortLink} onCopy={copyHandler}>
  86. <Url>{url.list[0].shortLink.replace(/^https?:\/\//, '')}</Url>
  87. </CopyToClipboard>
  88. <CopyToClipboard text={url.list[0].shortLink} onCopy={copyHandler}>
  89. <Button icon="copy">Copy</Button>
  90. </CopyToClipboard>
  91. {showQrCode && (
  92. <QRButton onClick={toggleQrCodeModal}>
  93. <Icon src="/images/qrcode.svg" />
  94. </QRButton>
  95. )}
  96. <Modal show={qrModal} close={toggleQrCodeModal}>
  97. <QRCode value={url.list[0].shortLink} size={196} />
  98. </Modal>
  99. </Wrapper>
  100. );
  101. };
  102. export default ShortenerResult;