index.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Dialog, Transition } from '@headlessui/react'
  2. import { Fragment } from 'react'
  3. import { RiCloseLargeLine } from '@remixicon/react'
  4. import classNames from '@/utils/classnames'
  5. type IModal = {
  6. className?: string
  7. wrapperClassName?: string
  8. open: boolean
  9. onClose?: () => void
  10. title?: React.ReactNode
  11. description?: React.ReactNode
  12. children?: React.ReactNode
  13. closable?: boolean
  14. overflowVisible?: boolean
  15. }
  16. export default function FullScreenModal({
  17. className,
  18. wrapperClassName,
  19. open,
  20. onClose = () => { },
  21. children,
  22. closable = false,
  23. overflowVisible = false,
  24. }: IModal) {
  25. return (
  26. <Transition show={open} as={Fragment}>
  27. <Dialog as="div" className={classNames('modal-dialog', wrapperClassName)} onClose={onClose}>
  28. <Transition.Child
  29. as={Fragment}
  30. enter="ease-out duration-300"
  31. enterFrom="opacity-0"
  32. enterTo="opacity-100"
  33. leave="ease-in duration-200"
  34. leaveFrom="opacity-100"
  35. leaveTo="opacity-0"
  36. >
  37. <div className="fixed inset-0 bg-background-overlay-backdrop backdrop-blur-[6px]" />
  38. </Transition.Child>
  39. <div
  40. className="fixed inset-0 h-screen w-screen p-4"
  41. onClick={(e) => {
  42. e.preventDefault()
  43. e.stopPropagation()
  44. }}
  45. >
  46. <div className="w-full h-full bg-background-default-subtle rounded-2xl border border-effects-highlight relative">
  47. <Transition.Child
  48. as={Fragment}
  49. enter="ease-out duration-300"
  50. enterFrom="opacity-0 scale-95"
  51. enterTo="opacity-100 scale-100"
  52. leave="ease-in duration-200"
  53. leaveFrom="opacity-100 scale-100"
  54. leaveTo="opacity-0 scale-95"
  55. >
  56. <Dialog.Panel className={classNames(
  57. 'h-full',
  58. overflowVisible ? 'overflow-visible' : 'overflow-hidden',
  59. className,
  60. )}>
  61. {closable
  62. && <div
  63. className='absolute z-50 top-3 right-3 w-9 h-9 flex items-center justify-center rounded-[10px]
  64. bg-components-button-tertiary-bg hover:bg-components-button-tertiary-bg-hover cursor-pointer'
  65. onClick={(e) => {
  66. e.stopPropagation()
  67. onClose()
  68. }}>
  69. <RiCloseLargeLine className='w-3.5 h-3.5 text-components-button-tertiary-text' />
  70. </div>}
  71. {children}
  72. </Dialog.Panel>
  73. </Transition.Child>
  74. </div>
  75. </div>
  76. </Dialog>
  77. </Transition>
  78. )
  79. }