/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ // eslint-disable-next-line import/no-extraneous-dependencies import * as React from 'react'; import classnames from 'classnames'; import OPButton from '../op-button'; // import event from '../event'; import { DialogSizeEnum, IconEnum } from './constants'; import './index.scss'; type DialogSize = 'small' | 'medium' | 'large'; type IconType = 'success' | 'warning' | 'notice' | 'about'; type DefaultFooterActions = 'cancel' | 'ok'; type FlagClass = 'cancel-left' | 'ok-left'; type StateEnum = 'error'; interface DialogProps { className?: string; visible: boolean; title?: React.ReactNode; subTitle?: React.ReactNode; onOk?: () => void; onCancel?: () => void; children?: React.ReactNode; footer?: boolean | React.ReactNode; maskClosable?: boolean; okText?: React.ReactNode; cancelText?: React.ReactNode; bodyStyle?: React.CSSProperties; size?: DialogSize; icon?: IconType; footerActions?: Array; width?: number | string; loading?: boolean; okHotKey?: string; cancelHotKey?: string; okDisabled?: boolean; cancelDisabled?: boolean; state?: StateEnum; } export default function Dialog(props: DialogProps) { let flagClass: FlagClass; const { className = '', visible = false, title, children, onOk = () => {}, onCancel = () => {}, footer = true, maskClosable = true, bodyStyle, size = 'small', okText = '确定', cancelText = '取消', icon, subTitle, footerActions = ['cancel', 'ok'], width, loading, okHotKey = 'Enter', cancelHotKey = 'Esc', cancelDisabled, okDisabled, state = '', } = props; const show = { opacity: 1 } as any; const hide = { opacity: 0 } as any; return visible ? (
{title && (
{icon && ( )} {title}
)} {subTitle &&
{subTitle}
}
{children}
{footer && (
{typeof footer === 'boolean' ? ( <> {footerActions.map((item: DefaultFooterActions, index) => { if (index === 0) { if (item === 'cancel') { flagClass = 'cancel-left'; } else { flagClass = 'ok-left'; } } if (index === 1) { if (item === 'cancel') { flagClass = 'ok-left'; } else { flagClass = 'cancel-left'; } } return ( <> {item === 'cancel' && ( {cancelText} )} {item === 'ok' && ( {okText} )} ); })} ) : ( footer )}
)}
maskClosable && onCancel()} />
) : (
); } // export default OPDialog;