summaryrefslogtreecommitdiff
path: root/extension/react-app/src/components/ToggleErrorDiv.tsx
blob: 69112ef7c2053283cfda59e890e86e4971751e99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useState } from "react";
import styled from "styled-components";
import { defaultBorderRadius } from ".";

// Should be a toggleable div with red border and light red background that displays a main message and detail inside

interface ToggleErrorDivProps {
  title: string;
  error: string;
}

const TopDiv = styled.div`
  border: 1px solid red;
  background-color: #ff000020;
  padding: 8px;

  border-radius: ${defaultBorderRadius};
  cursor: pointer;
`;

const ToggleErrorDiv = (props: ToggleErrorDivProps) => {
  const [open, setOpen] = useState(false);
  return (
    <TopDiv
      onClick={() => {
        setOpen(!open);
      }}
    >
      <div className="flex flex-row">
        <div className="flex-grow">
          <p>
            {open ? "▼" : "▶"} {props.title}
          </p>
        </div>
      </div>
      {open && <pre className="overflow-scroll">{props.error}</pre>}
    </TopDiv>
  );
};

export default ToggleErrorDiv;