import React, { ReactChild } from "react"; import Modal, { Props } from "react-modal"; import { useThemeUI, Close } from "theme-ui"; import { useSpring, animated, config } from "react-spring"; import CSS from "csstype"; type ModalProps = Props & { children: ReactChild | ReactChild[]; allowClose: boolean; }; function StyledModal({ isOpen, onRequestClose, children, allowClose, style, ...props }: ModalProps) { const { theme } = useThemeUI(); const openAnimation = useSpring({ opacity: isOpen ? 1 : 0, transform: isOpen ? "scale(1)" : "scale(0.99)", config: config.default, }); return ( ( {content} )} overlayElement={(props, content) => (
{ // Prevent drag event from triggering with a modal open e.preventDefault(); e.stopPropagation(); }} {...props} > {content}
)} {...props} > {children} {allowClose && ( )}
); } StyledModal.defaultProps = { allowClose: true, style: {}, }; export default StyledModal;