common.tsx 2.8 KB

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