ShortenerInput.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, { FC } from 'react';
  2. import styled from 'styled-components';
  3. import SVG from 'react-inlinesvg';
  4. import ShortenerOptions from './ShortenerOptions';
  5. import TextInput from '../TextInput';
  6. import Error from '../Error';
  7. // TODO: types
  8. interface Props {
  9. handleSubmit: any;
  10. isAuthenticated: boolean;
  11. domain: string;
  12. setShortenerFormError: any;
  13. }
  14. const ShortenerForm = styled.form`
  15. position: relative;
  16. display: flex;
  17. justify-content: center;
  18. align-items: center;
  19. width: 800px;
  20. max-width: 100%;
  21. `;
  22. const Submit = styled.div`
  23. content: '';
  24. position: absolute;
  25. top: 0;
  26. right: 12px;
  27. width: 64px;
  28. height: 100%;
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. cursor: pointer;
  33. :hover svg {
  34. fill: #673ab7;
  35. }
  36. @media only screen and (max-width: 448px) {
  37. right: 8px;
  38. width: 40px;
  39. }
  40. `;
  41. const Icon = styled(SVG)`
  42. svg {
  43. width: 28px;
  44. height: 28px;
  45. margin-right: 8px;
  46. margin-top: 2px;
  47. fill: #aaa;
  48. transition: all 0.2s ease-out;
  49. @media only screen and (max-width: 448px) {
  50. height: 22px;
  51. width: 22px;
  52. }
  53. }
  54. `;
  55. const ShortenerInput: FC<Props> = ({
  56. isAuthenticated,
  57. domain,
  58. handleSubmit,
  59. setShortenerFormError,
  60. }) => (
  61. <ShortenerForm id="shortenerform" onSubmit={handleSubmit}>
  62. <TextInput
  63. id="target"
  64. name="target"
  65. placeholder="Paste your long URL"
  66. autoFocus
  67. />
  68. <Submit onClick={handleSubmit}>
  69. <Icon src="/images/send.svg" />
  70. </Submit>
  71. <Error type="shortener" />
  72. <ShortenerOptions
  73. isAuthenticated={isAuthenticated}
  74. setShortenerFormError={setShortenerFormError}
  75. domain={domain}
  76. />
  77. </ShortenerForm>
  78. );
  79. export default ShortenerInput;