common.tsx 3.0 KB

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