Error.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import styled, { css } from 'styled-components';
  5. import { fadeIn } from '../../helpers/animations';
  6. const ErrorMessage = styled.p`
  7. content: '';
  8. position: absolute;
  9. right: 36px;
  10. bottom: -64px;
  11. display: block;
  12. font-size: 14px;
  13. color: red;
  14. animation: ${fadeIn} 0.3s ease-out;
  15. @media only screen and (max-width: 768px) {
  16. right: 8px;
  17. bottom: -40px;
  18. font-size: 12px;
  19. }
  20. ${({ left }) =>
  21. left > -1 &&
  22. css`
  23. right: auto;
  24. left: ${left}px;
  25. `};
  26. ${({ bottom }) =>
  27. bottom &&
  28. css`
  29. bottom: ${bottom}px;
  30. `};
  31. `;
  32. const Error = ({ bottom, error, left, type }) => {
  33. const message = error[type] && (
  34. <ErrorMessage left={left} bottom={bottom}>
  35. {error[type]}
  36. </ErrorMessage>
  37. );
  38. return <div>{message}</div>;
  39. };
  40. Error.propTypes = {
  41. bottom: PropTypes.number,
  42. error: PropTypes.shape({
  43. auth: PropTypes.string.isRequired,
  44. shortener: PropTypes.string.isRequired,
  45. }).isRequired,
  46. type: PropTypes.string.isRequired,
  47. left: PropTypes.number,
  48. };
  49. Error.defaultProps = {
  50. bottom: -64,
  51. left: -1,
  52. };
  53. const mapStateToProps = ({ error }) => ({ error });
  54. export default connect(mapStateToProps)(Error);