|
1 |
| -import { Fragment, ReactNode } from 'react'; |
2 |
| -import { Dialog, Transition } from '@headlessui/react'; |
| 1 | +import type { ReactNode } from 'react'; |
| 2 | +import { Dialog, DialogBackdrop, DialogPanel } from '@headlessui/react'; |
3 | 3 |
|
4 | 4 |
|
5 | 5 | // A reusable component to wrap a transition and dialog overlay around a screen-centered div.
|
6 | 6 | type CenteredModalProps = {
|
7 |
| - isOpen: boolean, setIsOpen: (isOpen: boolean) => void, |
8 |
| - className: string, children: ReactNode |
| 7 | + isOpen: boolean, |
| 8 | + setIsOpen: (isOpen: boolean) => void, |
| 9 | + className: string, |
| 10 | + children: ReactNode |
9 | 11 | }
|
10 | 12 | export default function CenteredModal(props: CenteredModalProps) {
|
11 | 13 | const { isOpen, setIsOpen, className, children } = props;
|
12 | 14 |
|
13 | 15 | return (
|
14 |
| - <Transition show={isOpen} as={Fragment}> |
15 |
| - <Dialog onClose={() => setIsOpen(false)} className="fixed z-40 inset-0 flex items-center justify-center"> |
16 |
| - <Transition.Child |
17 |
| - as={Fragment} |
18 |
| - enter="ease-out duration-300" |
19 |
| - enterFrom="opacity-0" |
20 |
| - enterTo="opacity-100" |
21 |
| - leave="ease-in duration-200" |
22 |
| - leaveFrom="opacity-100" |
23 |
| - leaveTo="opacity-0" |
24 |
| - > |
25 |
| - <div className="fixed inset-0 bg-black/40" /> |
26 |
| - </Transition.Child> |
| 16 | + <Dialog |
| 17 | + className="fixed z-40 inset-0 flex items-center justify-center" |
| 18 | + open={isOpen} |
| 19 | + onClose={() => setIsOpen(false)} |
| 20 | + > |
| 21 | + <DialogBackdrop |
| 22 | + transition |
| 23 | + className="fixed inset-0 bg-black/40 transition duration-300 data-[closed]:duration-200 ease-out data-[closed]:ease-in data-[closed]:opacity-0" |
| 24 | + /> |
27 | 25 |
|
28 |
| - <Transition.Child |
29 |
| - as={Fragment} |
30 |
| - enter="ease-out duration-300" |
31 |
| - enterFrom="opacity-0 scale-95" |
32 |
| - enterTo="opacity-100 scale-100" |
33 |
| - leave="ease-in duration-200" |
34 |
| - leaveFrom="opacity-100 scale-100" |
35 |
| - leaveTo="opacity-0 scale-95" |
36 |
| - > |
37 |
| - <Dialog.Panel className={className}> |
38 |
| - {children} |
39 |
| - </Dialog.Panel> |
40 |
| - </Transition.Child> |
41 |
| - </Dialog> |
42 |
| - </Transition> |
| 26 | + <DialogPanel |
| 27 | + transition |
| 28 | + className={className + ' transition duration-300 data-[closed]:duration-200 ease-out data-[closed]:ease-in data-[closed]:scale-95 data-[closed]:opacity-0'} |
| 29 | + > |
| 30 | + {children} |
| 31 | + </DialogPanel> |
| 32 | + </Dialog> |
43 | 33 | )
|
44 | 34 | }
|
0 commit comments