Elffuss BraidHub

kikocis/continue public

94488b344dec · 2.1 KiBRawPermalink
1import { XMarkIcon } from "@heroicons/react/24/outline";
2import React, { isValidElement, useEffect } from "react";
3import ReactMarkdown from "react-markdown";
4import styled from "styled-components";
5import {
6 CloseButton,
7 defaultBorderRadius,
8 vscBackground,
9 vscForeground,
10} from "..";
11import { varWithFallback } from "../../styles/theme";
12
13interface TextDialogProps {
14 showDialog: boolean;
15 onEnter: () => void;
16 onClose: () => void;
17 message?: string | JSX.Element;
18}
19
20const ScreenCover = styled.div`
21 position: fixed;
22 width: 100%;
23 height: 100%;
24 background-color: ${varWithFallback("background")}aa;
25 z-index: 100000;
26 flex-direction: column;
27`;
28
29const DialogContainer = styled.div`
30 position: absolute;
31 top: 50%;
32 left: 50%;
33 transform: translate(-50%, -50%);
34 color: ${vscForeground};
35 background-color: ${vscBackground};
36 border-radius: ${defaultBorderRadius};
37 display: flex;
38 flex-direction: column;
39 box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
40 word-wrap: break-word;
41`;
42
43const TextDialog = (props: TextDialogProps) => {
44 useEffect(() => {
45 const handleKeyDown = (event: KeyboardEvent) => {
46 if (event.key === "Escape") {
47 props.onClose();
48 }
49 };
50
51 document.addEventListener("keydown", handleKeyDown);
52 return () => {
53 document.removeEventListener("keydown", handleKeyDown);
54 };
55 }, [props]);
56
57 if (!isValidElement(props.message) && typeof props.message !== "string") {
58 return null;
59 }
60
61 return (
62 <ScreenCover onClick={props.onClose} hidden={!props.showDialog}>
63 <DialogContainer
64 className="xs:w-[90%] no-scrollbar max-h-[95%] w-[92%] max-w-[600px] overflow-auto sm:w-[88%] md:w-[80%]"
65 onClick={(e) => {
66 e.stopPropagation();
67 }}
68 >
69 <CloseButton onClick={props.onClose}>
70 <XMarkIcon className="z-50 h-5 w-5 hover:brightness-125" />
71 </CloseButton>
72
73 {typeof props.message === "string" ? (
74 <ReactMarkdown>{props.message || ""}</ReactMarkdown>
75 ) : !React.isValidElement(props.message) ? null : (
76 props.message
77 )}
78 </DialogContainer>
79 </ScreenCover>
80 );
81};
82
83export default TextDialog;