12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import type { FC, ReactElement } from 'react'
- import { useTranslation } from 'react-i18next'
- import {
- RiCloseLine,
- RiErrorWarningFill,
- } from '@remixicon/react'
- import s from './common.module.css'
- import cn from '@/utils/classnames'
- import Modal from '@/app/components/base/modal'
- import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
- import Button from '@/app/components/base/button'
- export type ConfirmCommonProps = {
- type?: string
- isShow: boolean
- onCancel: () => void
- title: string
- desc?: string
- onConfirm?: () => void
- showOperate?: boolean
- showOperateCancel?: boolean
- confirmBtnClassName?: string
- confirmText?: string
- confirmWrapperClassName?: string
- confirmDisabled?: boolean
- }
- const ConfirmCommon: FC<ConfirmCommonProps> = ({
- type = 'danger',
- isShow,
- onCancel,
- title,
- desc,
- onConfirm,
- showOperate = true,
- showOperateCancel = true,
- confirmBtnClassName,
- confirmText,
- confirmWrapperClassName,
- confirmDisabled,
- }) => {
- const { t } = useTranslation()
- const CONFIRM_MAP: Record<string, { icon: ReactElement; confirmText: string }> = {
- danger: {
- icon: <RiErrorWarningFill className='w-6 h-6 text-[#D92D20]' />,
- confirmText: t('common.operation.remove'),
- },
- success: {
- icon: <CheckCircle className='w-6 h-6 text-[#039855]' />,
- confirmText: t('common.operation.ok'),
- },
- }
- return (
- <Modal isShow={isShow} onClose={() => { }} className='!w-[480px] !max-w-[480px] !p-0 !rounded-2xl' wrapperClassName={confirmWrapperClassName}>
- <div className={cn(s[`wrapper-${type}`], 'relative p-8')}>
- <div className='flex items-center justify-center absolute top-4 right-4 w-8 h-8 cursor-pointer' onClick={onCancel}>
- <RiCloseLine className='w-4 h-4 text-gray-500' />
- </div>
- <div className='flex items-center justify-center mb-3 w-12 h-12 bg-white shadow-xl rounded-xl'>
- {CONFIRM_MAP[type].icon}
- </div>
- <div className='text-xl font-semibold text-gray-900'>{title}</div>
- {
- desc && <div className='mt-1 text-sm text-gray-500'>{desc}</div>
- }
- {
- showOperate && (
- <div className='flex items-center justify-end mt-10'>
- {
- showOperateCancel && (
- <Button
- className='mr-2'
- onClick={onCancel}
- >
- {t('common.operation.cancel')}
- </Button>
- )
- }
- <Button
- variant='primary'
- className={confirmBtnClassName || ''}
- onClick={onConfirm}
- disabled={confirmDisabled}
- >
- {confirmText || CONFIRM_MAP[type].confirmText}
- </Button>
- </div>
- )
- }
- </div>
- </Modal>
- )
- }
- export default ConfirmCommon
|