mirror of
https://github.com/fleetdm/fleet
synced 2026-05-17 05:58:40 +00:00
* Closes #922 * #922 added Windows section to build docs * go sum updated * updated go sum * fixed #963 - calling teams api if not on core * added command for seeding queries * added command default to higher level * linted test * only need 2 queries * fixed e2e command for seeding queries * fixes #952 - added esc key binding to modals * #952 lint fix
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import React, { useEffect } from "react";
|
|
import classnames from "classnames";
|
|
|
|
const baseClass = "modal";
|
|
|
|
interface IModalProps {
|
|
children: JSX.Element;
|
|
onExit: () => void;
|
|
title: string | JSX.Element;
|
|
className?: string;
|
|
}
|
|
|
|
const Modal = ({ children, onExit, title, className }: IModalProps) => {
|
|
useEffect(() => {
|
|
const closeWithEscapeKey = (e: KeyboardEvent) => {
|
|
if (e.key === "Escape") {
|
|
onExit();
|
|
}
|
|
};
|
|
|
|
document.addEventListener("keydown", closeWithEscapeKey);
|
|
|
|
return () => {
|
|
document.removeEventListener("keydown", closeWithEscapeKey);
|
|
};
|
|
}, []);
|
|
|
|
const modalContainerClassName = classnames(
|
|
`${baseClass}__modal_container`,
|
|
className
|
|
);
|
|
|
|
return (
|
|
<div className={`${baseClass}__background`}>
|
|
<div className={modalContainerClassName}>
|
|
<div className={`${baseClass}__header`}>
|
|
<span>{title}</span>
|
|
<div className={`${baseClass}__ex`}>
|
|
<button className="button button--unstyled" onClick={onExit} />
|
|
</div>
|
|
</div>
|
|
<div className={`${baseClass}__content`}>{children}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Modal;
|