Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import React, { Fragment } from 'react'; import { Dialog, Transition } from '@headlessui/react'; import { cn } from '@/lib/utils'; export interface ModalProps { show: boolean; onClose: () => void; children: React.ReactNode; maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl'; closeable?: boolean; } export function Modal({ show, onClose, children, maxWidth = 'md', closeable = true }: ModalProps) { 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', }; return ( <Transition appear show={show} as={Fragment}> <Dialog as="div" className="relative z-50" onClose={closeable ? onClose : () => { }}> <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="fixed inset-0 bg-black bg-opacity-25" /> </Transition.Child> <div className="fixed inset-0 overflow-y-auto"> <div className="flex items-center justify-center min-h-full p-4 text-center"> <Transition.Child as={Fragment} enter="ease-out duration-300" enterFrom="opacity-0 scale-95" enterTo="opacity-100 scale-100" leave="ease-in duration-200" leaveFrom="opacity-100 scale-100" leaveTo="opacity-0 scale-95" > <Dialog.Panel className={cn( 'w-full transform overflow-hidden rounded-lg bg-white p-6 text-left align-middle shadow-xl transition-all', maxWidthClass[maxWidth] )} > {children} </Dialog.Panel> </Transition.Child> </div> </div> </Dialog> </Transition> ); } |