@@ -6,12 +6,52 @@ import {
66 StyledModalErrorTitlebar ,
77} from "./ErrorModal.styles" ;
88import { ModalRow } from "./Modal" ;
9+ import { useEffect , useRef , useState } from "react" ;
10+ import { StyledModalContent } from "./Modal.styles" ;
911
1012export type ErrorVariant = "error" | "warning" | "info" ;
1113
1214const ErrorModal = ( ) => {
1315 const theme = useTheme ( ) ;
14- const { isOpen, msg, type, close } = useError ( ) ;
16+ const { isOpen, msg, type, close } = {
17+ isOpen : true ,
18+ msg : "Error" ,
19+ type : ErrorType . INFO ,
20+ close : ( ) => { } ,
21+ } ;
22+
23+ const [ isModalOpen , setModalOpen ] = useState < boolean > ( isOpen ) ;
24+ const modalRef = useRef < HTMLDialogElement > ( null ) ;
25+
26+ const handleCloseModal = ( ) => {
27+ if ( onClose ) {
28+ onClose ( ) ;
29+ }
30+ setModalOpen ( false ) ;
31+ } ;
32+
33+ const handleKeyDown = ( event : any ) => {
34+ if ( event . key === "Escape" ) {
35+ handleCloseModal ( ) ;
36+ }
37+ } ;
38+
39+ useEffect ( ( ) => {
40+ setModalOpen ( isOpen ) ;
41+ } , [ isOpen ] ) ;
42+
43+ useEffect ( ( ) => {
44+ const modalElement = modalRef . current ;
45+
46+ document . getElementById ( `${ type_str } -modal` ) ! . focus ( ) ;
47+ if ( modalElement ) {
48+ if ( isModalOpen ) {
49+ modalElement . showModal ( ) ;
50+ } else {
51+ modalElement . close ( ) ;
52+ }
53+ }
54+ } , [ isModalOpen ] ) ;
1555
1656 var type_str : ErrorVariant = "error" ;
1757 var type_header = "Error" ;
@@ -46,57 +86,62 @@ const ErrorModal = () => {
4686 return (
4787 < StyledModalError
4888 id = { `${ type_str } -modal` }
49- isOpen = { isOpen }
50- onClose = { onClose }
89+ ref = { modalRef }
90+ onKeyDown = { handleKeyDown }
5191 variant = { type_str }
92+ roundness = { theme . roundness }
5293 error = { theme . palette . error }
53- errorBorder = { theme . palette . border . info }
94+ errorBorder = { theme . palette . border . error }
5495 info = { theme . palette . background }
5596 infoBorder = { theme . palette . border . info }
5697 warning = { theme . palette . warning }
5798 warningBorder = { theme . palette . border . warning }
5899 >
59- < StyledModalErrorTitlebar
60- color = { theme . palette . text }
61- darkColor = { theme . palette . text }
62- title = { type_header }
63- htmlFor = "actionName"
64- variant = { type_str }
65- />
66- < ModalRow >
67- < StyledModalErrorRow
68- roundness = { theme . roundness }
69- variant = { type_str }
70- errorButtonColor = { theme . palette . button . error }
71- errorHoverColor = { theme . palette . button . hoverError }
72- errorTextColor = { theme . palette . text }
73- infoButtonColor = { theme . palette . button . info }
74- infoHoverColor = { theme . palette . button . hoverInfo }
75- infoTextColor = { theme . palette . text }
76- warningButtonColor = { theme . palette . button . warning }
77- warningHoverColor = { theme . palette . button . hoverWarning }
78- warningTextColor = { theme . palette . darkText }
79- >
80- < label id = "errorMsg" > { msg } </ label >
81- </ StyledModalErrorRow >
82- </ ModalRow >
83- < ModalRow >
84- < StyledModalErrorRow
100+ < StyledModalContent id = "bt-modal-contents" >
101+ < StyledModalErrorTitlebar
102+ color = { theme . palette . text }
103+ darkColor = { theme . palette . darkText }
104+ hoverColor = { theme . palette . secondary }
85105 roundness = { theme . roundness }
86106 variant = { type_str }
87- errorButtonColor = { theme . palette . button . error }
88- errorHoverColor = { theme . palette . button . hoverError }
89- errorTextColor = { theme . palette . text }
90- infoButtonColor = { theme . palette . button . info }
91- infoHoverColor = { theme . palette . button . hoverInfo }
92- infoTextColor = { theme . palette . text }
93- warningButtonColor = { theme . palette . button . warning }
94- warningHoverColor = { theme . palette . button . hoverWarning }
95- warningTextColor = { theme . palette . darkText }
96107 >
97- < div onClick = { ( ) => onClose ( ) } > Close</ div >
98- </ StyledModalErrorRow >
99- </ ModalRow >
108+ < label htmlFor = "actionName" > { type_header } </ label >
109+ </ StyledModalErrorTitlebar >
110+ < ModalRow >
111+ < StyledModalErrorRow
112+ roundness = { theme . roundness }
113+ variant = { type_str }
114+ errorButtonColor = { theme . palette . button . error }
115+ errorHoverColor = { theme . palette . button . hoverError }
116+ errorTextColor = { theme . palette . text }
117+ infoButtonColor = { theme . palette . button . info }
118+ infoHoverColor = { theme . palette . button . hoverInfo }
119+ infoTextColor = { theme . palette . text }
120+ warningButtonColor = { theme . palette . button . warning }
121+ warningHoverColor = { theme . palette . button . hoverWarning }
122+ warningTextColor = { theme . palette . darkText }
123+ >
124+ < label id = "errorMsg" > { msg } </ label >
125+ </ StyledModalErrorRow >
126+ </ ModalRow >
127+ < ModalRow >
128+ < StyledModalErrorRow
129+ roundness = { theme . roundness }
130+ variant = { type_str }
131+ errorButtonColor = { theme . palette . button . error }
132+ errorHoverColor = { theme . palette . button . hoverError }
133+ errorTextColor = { theme . palette . text }
134+ infoButtonColor = { theme . palette . button . info }
135+ infoHoverColor = { theme . palette . button . hoverInfo }
136+ infoTextColor = { theme . palette . text }
137+ warningButtonColor = { theme . palette . button . warning }
138+ warningHoverColor = { theme . palette . button . hoverWarning }
139+ warningTextColor = { theme . palette . darkText }
140+ >
141+ < button onClick = { ( ) => onClose ( ) } > Close</ button >
142+ </ StyledModalErrorRow >
143+ </ ModalRow >
144+ </ StyledModalContent >
100145 </ StyledModalError >
101146 ) ;
102147} ;
0 commit comments