mango-ui-v3/components/Modal.tsx

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-04-09 07:27:49 -07:00
import { Portal } from 'react-portal'
import { XIcon } from '@heroicons/react/outline'
2021-04-09 07:27:49 -07:00
2021-04-19 09:15:49 -07:00
const Modal = ({ isOpen, onClose, children, hideClose = false }) => {
2021-04-09 07:27:49 -07:00
return (
<Portal>
<div
2021-11-30 03:51:33 -08:00
className="fixed z-30 inset-0 overflow-y-auto sm:py-8"
2021-04-09 07:27:49 -07:00
aria-labelledby="modal-title"
role="dialog"
aria-modal="true"
>
2021-08-31 05:46:47 -07:00
<div className="flex items-center min-h-screen text-center sm:block sm:p-0">
2021-04-09 07:27:49 -07:00
{isOpen ? (
<div
2021-04-18 03:34:37 -07:00
className="fixed inset-0 bg-black bg-opacity-70 transition-opacity"
2021-04-09 07:27:49 -07:00
aria-hidden="true"
onClick={onClose}
></div>
) : null}
<span
className="hidden sm:inline-block sm:align-middle sm:h-screen"
2021-04-09 07:27:49 -07:00
aria-hidden="true"
>
&#8203;
</span>
{isOpen ? (
<div
2021-08-31 05:46:47 -07:00
className="inline-block bg-th-bkg-2 min-h-screen sm:min-h-full
2021-10-26 04:05:48 -07:00
sm:rounded-lg text-left px-8 pt-6 pb-6 shadow-lg transform transition-all align-middle sm:max-w-lg w-full"
2021-04-09 07:27:49 -07:00
>
{!hideClose ? (
<div className="">
<button
onClick={onClose}
2021-08-31 05:46:47 -07:00
className={`absolute right-4 top-4 md:right-2 md:top-2 text-th-fgd-1 hover:text-th-primary focus:outline-none`}
>
<XIcon className={`h-5 w-5`} />
</button>
</div>
) : (
<div className="w-full pt-4" />
)}
2021-04-09 17:01:00 -07:00
{children}
2021-04-09 07:27:49 -07:00
</div>
) : null}
</div>
</div>
</Portal>
)
}
const Header = ({ children }) => {
return (
<div className={`flex justify-center bg-th-bkg-2 pb-4`}>{children}</div>
2021-04-09 07:27:49 -07:00
)
}
Modal.Header = Header
export default Modal