import { FC } from 'react'; import { DialogActions, DialogContent, Dialog, makeStyles, Theme, createStyles, Typography, } from '@material-ui/core'; import { CustomDialogType } from './Types'; import { useTranslation } from 'react-i18next'; import CustomButton from '../customButton/CustomButton'; import CustomDialogTitle from './CustomDialogTitle'; const useStyles = makeStyles((theme: Theme) => createStyles({ paper: { minWidth: 480, borderRadius: 8, padding: 0, backgroundColor: 'transparent', }, noticePaper: { backgroundColor: '#fff', maxWidth: 480, }, paperSm: { maxWidth: '80%', }, dialogContent: { marginTop: theme.spacing(2), }, title: { '& p': { fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: 300, fontSize: 20, }, }, padding: { padding: theme.spacing(3, 4, 4), }, cancel: { color: theme.palette.common.black, opacity: 0.4, }, }) ); const CustomDialog: FC = props => { const { t } = useTranslation('btn'); const classes = useStyles(); const { open, type, params, onClose, containerClass = '' } = props; const { title, component, confirm, confirmLabel = t('confirm'), cancel, cancelLabel = t('cancel'), confirmClass = '', handleClose, } = params; // for notice type const { component: CustomComponent } = params; // for custom type const handleConfirm = async () => { if (confirm) { const res = await confirm(); if (!res) { return; } } handleClose ? handleClose() : onClose(); }; const handleCancel = async () => { if (cancel) { const res = await cancel(); if (!res) { return; } } handleClose ? handleClose() : onClose(); }; return ( {type === 'notice' ? (
{title} {component && ( {component} )} handleCancel()} className={classes.cancel} color="default" > {cancelLabel} {confirmLabel}
) : ( CustomComponent )}
); }; export default CustomDialog;