Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/components/ui/modals/OpenModal.tsx
T

55 lines
2.2 KiB
TypeScript

import { ReactNode, Fragment } from "react";
import { Dialog, DialogBackdrop, DialogPanel, Transition, TransitionChild } from "@headlessui/react";
import clsx from "clsx";
interface Props {
children: ReactNode;
onClose: () => void;
className?: string;
}
export default function OpenModal({ children, onClose, className = "sm:max-w-3xl" }: Props) {
return (
<Transition show={true} as={Fragment}>
<Dialog as="div" className="fixed inset-0 z-50 overflow-y-auto" onClose={onClose}>
<div className="flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
<TransitionChild
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<DialogBackdrop className={clsx("fixed inset-0 bg-gray-500/75 transition-opacity")} />
</TransitionChild>
{/* 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">
&#8203;
</span>
<TransitionChild
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"
>
<DialogPanel
className={clsx(
className,
// Subframe ModalBlank panel radius: rounded-md. Kept: overflow-visible (poppers escape panel), padding + sm:p-6, headlessui transitions.
"bg-surface-neutral-modal relative inline-block w-full transform overflow-visible rounded-md px-4 pb-4 pt-5 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:p-6 sm:align-middle"
)}
>
{children}
</DialogPanel>
</TransitionChild>
</div>
</Dialog>
</Transition>
);
}