'use client' import React, { useEffect } from 'react' import Icons from './Icons' const Modal = props => { //? Porps const { isShow, onClose, effect, children } = props //? Re-Renders useEffect(() => { if (isShow) document.body.style.overflow = 'hidden' else document.body.style.overflow = 'unset' }, [isShow]) //? Styles const effectClasses = effect === 'bottom-to-top' ? ` ${isShow ? 'bottom-0 lg:mt-20' : '-bottom-full lg:mt-60'} w-full h-full lg:h-auto lg:max-w-3xl transition-all duration-700 mx-auto relative` : effect === 'ease-out' ? ` ${isShow ? 'top-40 transform scale-100' : 'top-40 transform scale-50 '} max-w-3xl fixed transition-all duration-700 left-0 right-0 mx-auto relative` : effect === 'buttom-to-fit' ? ` ${isShow ? 'bottom-0' : '-bottom-full'} w-full h-fit lg:max-w-3xl fixed transition-all duration-700 left-0 right-0 mx-auto relative` : '' //? Render(s) return (
{React.Children.map(children, child => { if (React.isValidElement(child)) { return React.cloneElement(child, { onClose }) } return child })}
) } const Content = props => { //? Props const { onClose, children, ...restProps } = props //? Render(s) return (
{React.Children.map(children, child => { if (React.isValidElement(child)) { return React.cloneElement(child, { onClose }) } return child })}
) } const Header = props => { //? Props const { onClose, children } = props //? Render(s) return (
{children}
) } const Body = ({ children }) => { return <>{children} } const _default = Object.assign(Modal, { Modal, Content, Header, Body, }) export default _default