2022-05-26 21:41:24 +00:00
|
|
|
import { Fragment, ReactNode } from 'react'
|
2022-03-29 19:56:56 +00:00
|
|
|
import { Dialog, Transition } from '@headlessui/react'
|
2022-07-01 22:37:30 +00:00
|
|
|
import clsx from 'clsx'
|
2022-03-29 19:56:56 +00:00
|
|
|
|
|
|
|
// From https://tailwindui.com/components/application-ui/overlays/modals
|
|
|
|
export function Modal(props: {
|
2022-05-26 21:41:24 +00:00
|
|
|
children: ReactNode
|
2022-03-29 19:56:56 +00:00
|
|
|
open: boolean
|
|
|
|
setOpen: (open: boolean) => void
|
2022-07-16 19:21:24 +00:00
|
|
|
size?: 'sm' | 'md' | 'lg' | 'xl'
|
2022-07-01 22:37:30 +00:00
|
|
|
className?: string
|
2022-03-29 19:56:56 +00:00
|
|
|
}) {
|
2022-07-16 19:21:24 +00:00
|
|
|
const { children, open, setOpen, size = 'md', className } = props
|
|
|
|
|
|
|
|
const sizeClass = {
|
|
|
|
sm: 'max-w-sm',
|
|
|
|
md: 'max-w-md',
|
|
|
|
lg: 'max-w-2xl',
|
|
|
|
xl: 'max-w-5xl',
|
|
|
|
}[size]
|
2022-03-29 19:56:56 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Transition.Root show={open} as={Fragment}>
|
|
|
|
<Dialog
|
|
|
|
as="div"
|
|
|
|
className="fixed inset-0 z-50 overflow-y-auto"
|
|
|
|
onClose={setOpen}
|
|
|
|
>
|
2022-07-26 01:27:43 +00:00
|
|
|
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:p-0">
|
2022-03-29 19:56:56 +00:00
|
|
|
<Transition.Child
|
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
|
|
|
<Dialog.Overlay className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
|
|
|
|
</Transition.Child>
|
|
|
|
|
|
|
|
{/* This element is to trick the browser into centering the modal contents. */}
|
|
|
|
<span
|
|
|
|
className="hidden sm:inline-block sm:h-screen sm:align-middle"
|
|
|
|
aria-hidden="true"
|
|
|
|
>
|
|
|
|
​
|
|
|
|
</span>
|
|
|
|
<Transition.Child
|
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
>
|
2022-07-01 22:37:30 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-07-28 02:51:34 +00:00
|
|
|
'my-8 mx-6 inline-block w-full transform overflow-hidden text-left align-bottom transition-all sm:self-center sm:align-middle',
|
2022-07-16 19:21:24 +00:00
|
|
|
sizeClass,
|
2022-07-01 22:37:30 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
2022-03-29 19:56:56 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</Transition.Child>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
</Transition.Root>
|
|
|
|
)
|
|
|
|
}
|