index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useRef } from 'react'
  4. import cn from 'classnames'
  5. import Drawer from '@/app/components/base/drawer'
  6. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  7. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  8. type Props = {
  9. isShow: boolean
  10. onHide: () => void
  11. panelClassName?: string
  12. maxWidthClassName?: string
  13. contentClassName?: string
  14. headerClassName?: string
  15. height?: number | string
  16. title: string | JSX.Element
  17. titleDescription?: string | JSX.Element
  18. body: JSX.Element
  19. foot?: JSX.Element
  20. isShowMask?: boolean
  21. clickOutsideNotOpen?: boolean
  22. }
  23. const DrawerPlus: FC<Props> = ({
  24. isShow,
  25. onHide,
  26. panelClassName = '',
  27. maxWidthClassName = '!max-w-[640px]',
  28. height = 'calc(100vh - 72px)',
  29. contentClassName,
  30. headerClassName,
  31. title,
  32. titleDescription,
  33. body,
  34. foot,
  35. isShowMask,
  36. clickOutsideNotOpen = true,
  37. }) => {
  38. const ref = useRef(null)
  39. const media = useBreakpoints()
  40. const isMobile = media === MediaType.mobile
  41. if (!isShow)
  42. return null
  43. return (
  44. // clickOutsideNotOpen to fix confirm modal click cause drawer close
  45. <Drawer isOpen={isShow} clickOutsideNotOpen={clickOutsideNotOpen} onClose={onHide} footer={null} mask={isMobile || isShowMask} panelClassname={`mt-16 mx-2 sm:mr-2 mb-3 !p-0 ${panelClassName} ${maxWidthClassName} rounded-xl`}>
  46. <div
  47. className={cn(contentClassName, 'w-full flex flex-col bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl')}
  48. style={{
  49. height,
  50. }}
  51. ref={ref}
  52. >
  53. <div className={cn(headerClassName, 'shrink-0 border-b border-b-gray-100 py-4')}>
  54. <div className='flex justify-between items-center pl-6 pr-5 h-6'>
  55. <div className='text-base font-semibold text-gray-900'>
  56. {title}
  57. </div>
  58. <div className='flex items-center'>
  59. <div
  60. onClick={onHide}
  61. className='flex justify-center items-center w-6 h-6 cursor-pointer'
  62. >
  63. <XClose className='w-4 h-4 text-gray-500' />
  64. </div>
  65. </div>
  66. </div>
  67. {titleDescription && (
  68. <div className='pl-6 pr-10 leading-[18px] text-xs font-normal text-gray-500'>
  69. {titleDescription}
  70. </div>
  71. )}
  72. </div>
  73. <div className='grow overflow-y-auto'>
  74. {body}
  75. </div>
  76. {foot && (
  77. <div className='shrink-0'>
  78. {foot}
  79. </div>
  80. )}
  81. </div>
  82. </Drawer>
  83. )
  84. }
  85. export default React.memo(DrawerPlus)