mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-28 03:47:03 +02:00
dialogBoxCreate now uses the same logic as other popups, now all popup can be dismissed with escape.
This commit is contained in:
+13
-1
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user