common.tsx 2.9 KB

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