mirror of
https://github.com/fleetdm/fleet
synced 2026-05-15 13:08:42 +00:00
* added storybook * added avatar component * added button story * added dropdown button story * removed unused ellipsis component * cleaned up modal path * reorganized enroll secrets table file * added flash story; removed unused persistent flash * added fleet ace story * added checkbox story * added dropdown story * added input story * fixed storybook build * fixed avatar * added input with icon story * added radio button story * added select targets dropdown story * added slider story * added tooltip story * added info banner story * removed unused loaders; added spinner story * added modal story * removed unused NumberPill * added pagination story * lint fixes * added documentation to run * modified documentation * fixed corelayout test * fixed format for date-fns * fixed date format that breaks tests * wait for page
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import React, { useEffect } from "react";
|
|
import classnames from "classnames";
|
|
|
|
const baseClass = "modal";
|
|
|
|
export 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;
|