This was the original code from the Modal Component that came along with the Laravel Breeze React starter kit, but I can’t see to get the modal to show up – is this code only for a dark background of low opacity to appear?
import { Fragment } from "react";
import { Dialog, Transition } from "@headlessui/react";
import IconClose from "./IconClose";
export default function Modal({
children,
show,
maxWidth = "2xl",
closeable = true,
onClose = () => {},
}) {
const close = () => {
if (closeable) {
onClose();
}
};
const maxWidthClass = {
sm: "sm:max-w-sm",
md: "sm:max-w-md",
lg: "sm:max-w-lg",
xl: "sm:max-w-xl",
"2xl": "sm:max-w-2xl",
}[maxWidth];
return (
<Transition show={show} as={Fragment} leave="duration-200">
<Dialog
as="div"
id="modal"
className="fixed inset-0 flex overflow-y-auto px-4 py-6 sm:px-0 items-center z-50 transform transition-all"
onClose={close}
>
<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"
>
<div className="absolute inset-0 bg-gray-500/75 dark:bg-gray-900/75" />
</Transition.Child>
<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"
>
<Dialog.Panel
className={`mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto ${maxWidthClass}`}
>
{children}
</Dialog.Panel>
</Transition.Child>
</Dialog>
</Transition>
);
}
I am not sure where to put the text content of my modal, but I have placed it in a <div>
within Dialog.Panel
:
<Dialog.Panel className={`z-0 mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto ${maxWidthClass}`}
>
{children}
<div className="z-10">
Is this where things are supposed to go? Is there no
window? Why cant i clsoe this
<IconClose onClick={() => close()} />
</div>
</Dialog.Panel>
but even with the z-index, the div
still hides behind the background of lower opacity:
screenshot here
I can’t seem to find any tutorial or explanation of how to integrate this in-built Modal Component into my React Application. Can someone offer some advice?