index.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use client'
  2. import { Dialog } from '@headlessui/react'
  3. import { useTranslation } from 'react-i18next'
  4. import Button from '../button'
  5. type DrawerProps = {
  6. title?: string
  7. description?: string
  8. panelClassname?: string
  9. children: React.ReactNode
  10. footer?: React.ReactNode
  11. mask?: boolean
  12. isOpen: boolean
  13. // closable: boolean
  14. onClose: () => void
  15. onCancel?: () => void
  16. onOk?: () => void
  17. }
  18. export default function Drawer({
  19. title = '',
  20. description = '',
  21. panelClassname = '',
  22. children,
  23. footer,
  24. mask = true,
  25. isOpen,
  26. onClose,
  27. onCancel,
  28. onOk,
  29. }: DrawerProps) {
  30. const { t } = useTranslation()
  31. return (
  32. <Dialog
  33. unmount={false}
  34. open={isOpen}
  35. onClose={() => onClose()}
  36. className="fixed z-30 inset-0 overflow-y-auto"
  37. >
  38. <div className="flex w-screen h-screen justify-end">
  39. {/* mask */}
  40. <Dialog.Overlay
  41. className={`z-40 fixed inset-0 ${!mask ? '' : 'bg-black bg-opacity-30'}`}
  42. />
  43. <div className={`z-50 flex flex-col justify-between bg-white w-full
  44. max-w-sm p-6 overflow-hidden text-left align-middle
  45. shadow-xl ${panelClassname}`}>
  46. <>
  47. {title && <Dialog.Title
  48. as="h3"
  49. className="text-lg font-medium leading-6 text-gray-900"
  50. >
  51. {title}
  52. </Dialog.Title>}
  53. {description && <Dialog.Description className='text-gray-500 text-xs font-normal mt-2'>{description}</Dialog.Description>}
  54. {children}
  55. </>
  56. {footer || (footer === null
  57. ? null
  58. : <div className="mt-10 flex flex-row justify-end">
  59. <Button
  60. className='mr-2'
  61. onClick={() => {
  62. onCancel && onCancel()
  63. }}>{t('common.operation.cancel')}</Button>
  64. <Button
  65. onClick={() => {
  66. onOk && onOk()
  67. }}>{t('common.operation.save')}</Button>
  68. </div>)}
  69. </div>
  70. </div>
  71. </Dialog>
  72. )
  73. }