import React, { useState, useEffect } from 'react' import ReactModal from 'react-modal' import { Icon } from '../../Icons' const sizeClasses = { small: 'sm:max-w-xl', default: 'sm:max-w-4xl', large: 'sm:max-w-6xl', } const ModalComponent = ({ className = '', isOpen = false, preventClose = false, size = 'default', headerTitle, headerClose = 'Fechar', footerActions, onClose, parentSelector, children, }: ModalProps) => { const [modalIsOpen, setModalIsOpen] = useState(false) const [modalPreventClose, setModalPreventClose] = useState(false) useEffect(() => { setModalIsOpen(isOpen) setModalPreventClose(preventClose) }, [isOpen, preventClose]) const handleRequestCloseFunc = () => { setModalIsOpen(false) } const handleAfterCloseFunc = () => { onClose && onClose() } return ( (parentSelector ? parentSelector : document.body)} contentElement={(props, children) => (
{headerTitle}
{children}
{footerActions && (
{footerActions}
)}
)} > {children}
) } export const Modal = React.memo(ModalComponent) export interface ModalProps { /** * Custom class name * */ className?: string /** Modal is open * @default false */ isOpen?: boolean /** Prevent modal close * @default false */ preventClose?: boolean /** Modal width * @default 'default' * */ size?: 'default' | 'large' | 'small' /** * Modal title * */ headerTitle?: string | React.ReactNode /** Close text at header * @default 'Fechar' * */ headerClose?: string | false /** * Call when modal is closed * */ onClose?: Function /** * React children */ children?: React.ReactNode /** * React children */ footerActions?: React.ReactNode /** The parent element that the modal will be attached to * @default 'document.body' */ parentSelector?: HTMLElement | null }