Transfer previous Modal code
This commit is contained in:
parent
800ec27c36
commit
4ba4c15e23
2 changed files with 64 additions and 0 deletions
39
ui/src/Modal.tsx
Normal file
39
ui/src/Modal.tsx
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import {useEffect, useRef} from "react";
|
||||||
|
|
||||||
|
export function Modal(props: {
|
||||||
|
isOpen: boolean;
|
||||||
|
setClosed: () => void;
|
||||||
|
children: any;
|
||||||
|
}){
|
||||||
|
|
||||||
|
const ref = useRef<HTMLDialogElement>();
|
||||||
|
useEffect(() => {
|
||||||
|
if(props.isOpen){
|
||||||
|
// @ts-ignore
|
||||||
|
ref.current.showModal();
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
ref.current.close();
|
||||||
|
}
|
||||||
|
}, [props.isOpen])
|
||||||
|
|
||||||
|
|
||||||
|
return(
|
||||||
|
// The style part is just to make sure the dialog is hidden the split second before useEffect runs,
|
||||||
|
// in case the dialog content is derived from whatever determines isOpen
|
||||||
|
<dialog ref={ref} style={!props.isOpen ? {display: 'none'} : null}>
|
||||||
|
<div className="close-button-div" >
|
||||||
|
<button onClick={(e) => {
|
||||||
|
// we manually trigger a close anyway because the children can get updated before the dialog gets closed otherwise
|
||||||
|
// @ts-ignore
|
||||||
|
ref.current.close();
|
||||||
|
props.setClosed();
|
||||||
|
}}>✕</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
|
@ -164,3 +164,28 @@
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog {
|
||||||
|
border-radius: 10px;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
|
||||||
|
.close-button-div {
|
||||||
|
display: flex;
|
||||||
|
justify-content: end;
|
||||||
|
|
||||||
|
button {
|
||||||
|
border: 0;
|
||||||
|
background-color: inherit;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #aaaaaa;
|
||||||
|
font-weight: bold;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: black;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue