Elffuss BraidHub

kikocis/continue public

main · 2.0 KiBRawPermalink
1import { XMarkIcon } from "@heroicons/react/24/outline";
2import React, { isValidElement } from "react";
3import ReactMarkdown from "react-markdown";
4import styled from "styled-components";
5import {
6 CloseButton,
7 defaultBorderRadius,
8 vscBackground,
9 vscForeground,
10} from "..";
11
12interface TextDialogProps {
13 showDialog: boolean;
14 onEnter: () => void;
15 onClose: () => void;
16 message?: string | JSX.Element;
17}
18
19const ScreenCover = styled.div`
20 position: fixed;
21 width: 100%;
22 height: 100%;
23 background-color: rgba(0, 0, 0, 0.35);
24 backdrop-filter: blur(0.5px);
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 const handleKeyDown = (event: React.KeyboardEvent) => {
45 if (event.key === "Escape") {
46 props.onClose();
47 }
48 };
49
50 if (!isValidElement(props.message) && typeof props.message !== "string") {
51 return null;
52 }
53
54 return (
55 <ScreenCover
56 onClick={props.onClose}
57 hidden={!props.showDialog}
58 onKeyDown={handleKeyDown}
59 tabIndex={-1}
60 >
61 <DialogContainer
62 className="xs:w-[90%] no-scrollbar max-h-[95%] w-[92%] max-w-[600px] overflow-auto sm:w-[88%] md:w-[80%]"
63 onClick={(e) => {
64 e.stopPropagation();
65 }}
66 >
67 <CloseButton onClick={props.onClose}>
68 <XMarkIcon className="z-50 h-5 w-5 hover:brightness-125" />
69 </CloseButton>
70
71 {typeof props.message === "string" ? (
72 <ReactMarkdown>{props.message || ""}</ReactMarkdown>
73 ) : !React.isValidElement(props.message) ? null : (
74 props.message
75 )}
76 </DialogContainer>
77 </ScreenCover>
78 );
79};
80
81export default TextDialog;