// Window.jsx import React, { useEffect, useState } from "react"; import Overlay, { OverlayChildrenProps } from "../overlay"; import Backdrop from "../backdrop"; import classNames from "classnames"; export interface WindowProps { children: | React.ReactElement | ((props: OverlayChildrenProps) => React.ReactElement); show: boolean; onClose: (result?: T) => void; onBackdropClick?: (result?: T) => void; } const Window = ({ children, show, onClose, onBackdropClick }: WindowProps) => { const [isVisible, setIsVisible] = useState(show); useEffect(() => { if (show) { setIsVisible(true); } else { setIsVisible(false); } }, [show]); const handleOverlayVisibleChange = (visible: boolean) => { if (!visible) { onClose(); } }; const el = (props: OverlayChildrenProps) => { if (typeof children === "function") { return children(props); } return children as React.ReactElement; }; return ( {({ close }) => (
{el({ close })}
)}
); }; export default Window;