common.tsx 2.7 KB

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