common.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import type { FC, ReactElement } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import cn from 'classnames'
  4. import s from './common.module.css'
  5. import Modal from '@/app/components/base/modal'
  6. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  7. import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
  8. import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
  9. import Button from '@/app/components/base/button'
  10. export type ConfirmCommonProps = {
  11. type?: string
  12. isShow: boolean
  13. onCancel: () => void
  14. title: string
  15. desc?: string
  16. onConfirm?: () => void
  17. showOperate?: boolean
  18. showOperateCancel?: boolean
  19. confirmBtnClassName?: string
  20. confirmText?: string
  21. confirmWrapperClassName?: string
  22. }
  23. const ConfirmCommon: FC<ConfirmCommonProps> = ({
  24. type = 'danger',
  25. isShow,
  26. onCancel,
  27. title,
  28. desc,
  29. onConfirm,
  30. showOperate = true,
  31. showOperateCancel = true,
  32. confirmBtnClassName,
  33. confirmText,
  34. confirmWrapperClassName,
  35. }) => {
  36. const { t } = useTranslation()
  37. const CONFIRM_MAP: Record<string, { icon: ReactElement; confirmText: string }> = {
  38. danger: {
  39. icon: <AlertCircle className='w-6 h-6 text-[#D92D20]' />,
  40. confirmText: t('common.operation.remove'),
  41. },
  42. success: {
  43. icon: <CheckCircle className='w-6 h-6 text-[#039855]' />,
  44. confirmText: t('common.operation.ok'),
  45. },
  46. }
  47. return (
  48. <Modal isShow={isShow} onClose={() => {}} className='!w-[480px] !max-w-[480px] !p-0 !rounded-2xl' wrapperClassName={confirmWrapperClassName}>
  49. <div className={cn(s[`wrapper-${type}`], 'relative p-8')}>
  50. <div className='flex items-center justify-center absolute top-4 right-4 w-8 h-8 cursor-pointer' onClick={onCancel}>
  51. <XClose className='w-4 h-4 text-gray-500' />
  52. </div>
  53. <div className='flex items-center justify-center mb-3 w-12 h-12 bg-white shadow-xl rounded-xl'>
  54. {CONFIRM_MAP[type].icon}
  55. </div>
  56. <div className='text-xl font-semibold text-gray-900'>{title}</div>
  57. {
  58. desc && <div className='mt-1 text-sm text-gray-500'>{desc}</div>
  59. }
  60. {
  61. showOperate && (
  62. <div className='flex items-center justify-end mt-10'>
  63. {
  64. showOperateCancel && (
  65. <Button
  66. className='mr-2 min-w-24 text-sm font-medium !text-gray-700'
  67. onClick={onCancel}
  68. >
  69. {t('common.operation.cancel')}
  70. </Button>
  71. )
  72. }
  73. <Button
  74. type='primary'
  75. className={confirmBtnClassName || ''}
  76. onClick={onConfirm}
  77. >
  78. {confirmText || CONFIRM_MAP[type].confirmText}
  79. </Button>
  80. </div>
  81. )
  82. }
  83. </div>
  84. </Modal>
  85. )
  86. }
  87. export default ConfirmCommon