import React from 'react'; import Pop, { PopProps } from '../pop/index'; import Button, { ButtonProps } from '../button/index'; import { IconInfo, IconCheckCircle, IconAlertCircle, IconXCircle, } from '../icon/index'; import bem from '../utils/bem'; const b = bem('rdf-pop-dialog'); const ICONS = { info: , success: , warning: , error: , }; export type PopDialogType = 'info' | 'success' | 'warning' | 'error'; export interface PopDialogProps extends PopProps { type?: PopDialogType; okType?: ButtonProps['type']; okText?: string; cancelText?: string; onOk?: React.EventHandler; onCancel?: React.EventHandler; } export interface PopDialogState { visible?: boolean; } export class PopDialog extends React.Component { static defaultProps: PopDialogProps = { type: 'info', trigger: 'click', position: 'top-center', withArrow: true, okType: 'primary', okText: '确定', cancelText: '取消', }; state: PopDialogState = { visible: false, }; handleVisibleChange = (visible: boolean) => { this.setState({ visible }); }; handleOk = (ev: React.SyntheticEvent) => { const { onOk } = this.props; this.setState({ visible: false }); onOk && onOk(ev); }; handleCancel = (ev: React.SyntheticEvent) => { const { onCancel } = this.props; this.setState({ visible: false }); onCancel && onCancel(ev); }; renderContent() { const { type, content, okType, okText, cancelText } = this.props; return ( <> {ICONS[type as PopDialogType]} {content} {cancelText} {okText} > ); } render() { const { visible } = this.state; return ( {this.props.children} ); } } export default PopDialog;