index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from "react";
  2. import styled from "styled-components";
  3. import { MdReportGmailerrorred, MdOutlineCheckCircleOutline } from "react-icons/md";
  4. import useJson from "src/store/useJson";
  5. const StyledErrorWrapper = styled.div`
  6. z-index: 1;
  7. `;
  8. const StyledErrorExpand = styled.div<{ error: boolean }>`
  9. position: relative;
  10. display: flex;
  11. width: 100%;
  12. padding: 4px 16px;
  13. height: 36px;
  14. border-radius: 0;
  15. justify-content: space-between;
  16. align-items: center;
  17. color: ${({ theme, error }) => (error ? theme.TEXT_DANGER : theme.TEXT_POSITIVE)};
  18. pointer-events: ${({ error }) => !error && "none"};
  19. background: ${({ theme }) => theme.BACKGROUND_SECONDARY};
  20. `;
  21. const StyledTitle = styled.span`
  22. display: flex;
  23. justify-content: center;
  24. align-items: center;
  25. font-weight: 500;
  26. gap: 10px;
  27. font-size: 16px;
  28. `;
  29. const StyledError = styled.pre`
  30. color: ${({ theme }) => theme.TEXT_DANGER};
  31. border-bottom: 1px solid ${({ theme }) => theme.SILVER_DARK};
  32. font-size: 12px;
  33. padding: 12px;
  34. margin: 0;
  35. word-wrap: break-word;
  36. white-space: pre-line;
  37. `;
  38. export const ErrorContainer = () => {
  39. const hasError = useJson(state => state.hasError);
  40. return (
  41. <StyledErrorWrapper>
  42. <StyledErrorExpand error={hasError}>
  43. <StyledTitle>
  44. {hasError ? (
  45. <MdReportGmailerrorred size={20} />
  46. ) : (
  47. <MdOutlineCheckCircleOutline size={20} />
  48. )}
  49. {hasError ? "Invalid JSON" : "JSON Valid"}
  50. </StyledTitle>
  51. </StyledErrorExpand>
  52. </StyledErrorWrapper>
  53. );
  54. };