CurrentError.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React, { Component } from 'react';
  2. import styled from 'styled-components';
  3. import close from '../assets/close.png';
  4. import { Context } from '../shared/Context';
  5. type PropsType = {
  6. };
  7. type StateType = {
  8. };
  9. export default class CurrentError extends Component<PropsType, StateType> {
  10. state = {
  11. expanded: false
  12. }
  13. render() {
  14. if (this.context.currentError) {
  15. if (!this.state.expanded) {
  16. return (
  17. <StyledCurrentError onClick={() => this.setState({ expanded: true })}>
  18. <ErrorText>Error: {this.context.currentError}</ErrorText>
  19. <CloseButton onClick={(e) => {
  20. this.context.setCurrentError(null);
  21. e.stopPropagation();
  22. }}>
  23. <CloseButtonImg src={close} />
  24. </CloseButton>
  25. </StyledCurrentError>
  26. );
  27. }
  28. return (
  29. <ExpandedError onClick={() => this.setState({ expanded: false })}>
  30. Error: {this.context.currentError}
  31. <CloseButtonAlt onClick={() => this.context.setCurrentError(null)}>
  32. <CloseButtonImg src={close} />
  33. </CloseButtonAlt>
  34. </ExpandedError>
  35. );
  36. }
  37. return null;
  38. }
  39. }
  40. CurrentError.contextType = Context;
  41. const CloseButton = styled.div`
  42. display: flex;
  43. align-items: center;
  44. justify-content: center;
  45. width: 30px;
  46. height: 30px;
  47. border-radius: 50%;
  48. margin-left: 10px;
  49. cursor: pointer;
  50. :hover {
  51. background-color: #ffffff11;
  52. }
  53. `;
  54. const CloseButtonAlt = styled(CloseButton)`
  55. position: absolute;
  56. top: 5px;
  57. right: 5px;
  58. `;
  59. const CloseButtonImg = styled.img`
  60. width: 10px;
  61. `;
  62. const ErrorText = styled.div`
  63. white-space: nowrap;
  64. overflow: hidden;
  65. text-overflow: ellipsis;
  66. width: calc(100% - 50px);
  67. `;
  68. const StyledCurrentError = styled.div`
  69. position: fixed;
  70. bottom: 20px;
  71. width: 300px;
  72. left: 17px;
  73. padding: 15px;
  74. padding-right: 0px;
  75. font-family: 'Work Sans', sans-serif;
  76. height: 50px;
  77. font-size: 13px;
  78. border-radius: 3px;
  79. background: #383842dd;
  80. border: 1px solid #ffffff55;
  81. display: flex;
  82. align-items: center;
  83. color: #FFDB8C;
  84. > i {
  85. font-size: 18px;
  86. margin-right: 10px;
  87. }
  88. animation: floatIn 0.5s;
  89. animation-fill-mode: forwards;
  90. @keyframes floatIn {
  91. from {
  92. opacity: 0; transform: translateY(20px);
  93. }
  94. to {
  95. opacity: 1; transform: translateY(0px);
  96. }
  97. }
  98. `;
  99. const ExpandedError = styled(StyledCurrentError)`
  100. width: 500px;
  101. height: auto;
  102. max-height: 300px;
  103. padding: 20px;
  104. overflow-y: auto;
  105. `;