index.tsx 1.9 KB

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