mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Updated migration files to enhance readability by adjusting indentation and line breaks. - Added missing commas in the index file for migration imports. - Improved accessibility attributes in various UI components by ensuring proper aria-labels and roles. - Refactored key event handlers in UI components for better clarity and consistency. - Enhanced error message handling in form components to ensure proper display and accessibility. - Updated legacy function comments for clarity and maintainability.
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import Icon, { SizeProp, ThickProp } from "../Icon/Icon";
|
|
import IconProp from "../../../Types/Icon/IconProp";
|
|
import React, { FunctionComponent, ReactElement } from "react";
|
|
|
|
export interface ComponentProps {
|
|
onClose: () => void;
|
|
children: ReactElement | Array<ReactElement>;
|
|
}
|
|
|
|
const FullPageModal: FunctionComponent<ComponentProps> = (
|
|
props: ComponentProps,
|
|
): ReactElement => {
|
|
const handleClose: () => void = (): void => {
|
|
props.onClose?.();
|
|
};
|
|
|
|
const handleKeyDown: (event: React.KeyboardEvent) => void = (
|
|
event: React.KeyboardEvent,
|
|
): void => {
|
|
if (event.key === "Enter" || event.key === " ") {
|
|
event.preventDefault();
|
|
handleClose();
|
|
}
|
|
};
|
|
|
|
// Handle Escape key at the modal level
|
|
React.useEffect(() => {
|
|
const handleEscapeKey: (event: KeyboardEvent) => void = (
|
|
event: KeyboardEvent,
|
|
): void => {
|
|
if (event.key === "Escape") {
|
|
handleClose();
|
|
}
|
|
};
|
|
|
|
document.addEventListener("keydown", handleEscapeKey);
|
|
return () => {
|
|
document.removeEventListener("keydown", handleEscapeKey);
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<div className="full-page-modal" role="dialog" aria-modal="true">
|
|
<div
|
|
className="margin-50 align-right"
|
|
onClick={handleClose}
|
|
onKeyDown={handleKeyDown}
|
|
role="button"
|
|
tabIndex={0}
|
|
aria-label="Close modal"
|
|
>
|
|
<Icon
|
|
icon={IconProp.Close}
|
|
size={SizeProp.ExtraLarge}
|
|
thick={ThickProp.Thick}
|
|
/>
|
|
</div>
|
|
<div className="margin-50">{props.children}</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default FullPageModal;
|