dialogBoxCreate now uses the same logic as other popups, now all popup can be dismissed with escape.

This commit is contained in:
Olivier Gagnon
2021-08-18 00:51:51 -04:00
parent 5c92360310
commit d6b349b6ff
6 changed files with 74 additions and 95 deletions
+13 -1
View File
@@ -3,15 +3,27 @@
*
* Takes in a prop for rendering the content inside the popup
*/
import * as React from "react";
import React, { useEffect } from "react";
interface IProps<T> {
content: (props: T) => React.ReactElement;
id: string;
props: T;
removePopup: (id: string) => void;
}
export function Popup<T>(props: IProps<T>): React.ReactElement {
function keyDown(event: KeyboardEvent): void {
if(event.key === 'Escape') props.removePopup(props.id);
}
useEffect(() => {
document.addEventListener('keydown', keyDown);
return () => {
document.removeEventListener('keydown', keyDown);
}
});
return (
<div className={"popup-box-content"} id={`${props.id}-content`}>
{React.createElement(props.content, props.props)}