dialog-wrapper.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Fragment, useCallback } from 'react'
  2. import type { ReactNode } from 'react'
  3. import { Dialog, Transition } from '@headlessui/react'
  4. import cn from '@/utils/classnames'
  5. type DialogProps = {
  6. className?: string
  7. children: ReactNode
  8. show: boolean
  9. onClose?: () => void
  10. inWorkflow?: boolean
  11. }
  12. const DialogWrapper = ({
  13. className,
  14. children,
  15. show,
  16. onClose,
  17. inWorkflow = true,
  18. }: DialogProps) => {
  19. const close = useCallback(() => onClose?.(), [onClose])
  20. return (
  21. <Transition appear show={show} as={Fragment}>
  22. <Dialog as="div" className="relative z-40" onClose={close}>
  23. <Transition.Child
  24. as={Fragment}
  25. enter="ease-out duration-300"
  26. enterFrom="opacity-0"
  27. enterTo="opacity-100"
  28. leave="ease-in duration-200"
  29. leaveFrom="opacity-100"
  30. leaveTo="opacity-0"
  31. >
  32. <div className="fixed inset-0 bg-black bg-opacity-25" />
  33. </Transition.Child>
  34. <div className="fixed inset-0">
  35. <div className={cn('flex flex-col items-end justify-center min-h-full pb-2', inWorkflow ? 'pt-[112px]' : 'pt-[64px] pr-2')}>
  36. <Transition.Child
  37. as={Fragment}
  38. enter="ease-out duration-300"
  39. enterFrom="opacity-0 scale-95"
  40. enterTo="opacity-100 scale-100"
  41. leave="ease-in duration-200"
  42. leaveFrom="opacity-100 scale-100"
  43. leaveTo="opacity-0 scale-95"
  44. >
  45. <Dialog.Panel className={cn('grow flex flex-col relative w-[420px] h-0 p-0 overflow-hidden text-left align-middle transition-all transform bg-components-panel-bg-alt border-components-panel-border shadow-xl', inWorkflow ? 'border-t-[0.5px] border-l-[0.5px] border-b-[0.5px] rounded-l-2xl' : 'border-[0.5px] rounded-2xl', className)}>
  46. {children}
  47. </Dialog.Panel>
  48. </Transition.Child>
  49. </div>
  50. </div>
  51. </Dialog>
  52. </Transition >
  53. )
  54. }
  55. export default DialogWrapper