You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/modal/ConfirmDialog.jsx

102 lines
3.1 KiB

import classNames from 'classnames';
import Icon from '../icon';
import Dialog from './Modal';
import ActionButton from './ActionButton';
import { getConfirmLocale } from './locale';
7 years ago
export default {
functional: true,
render(h, context) {
const { props } = context;
const {
onCancel,
onOk,
close,
zIndex,
afterClose,
visible,
keyboard,
centered,
getContainer,
maskStyle,
okButtonProps,
cancelButtonProps,
} = props;
const iconType = props.iconType || 'question-circle';
const okType = props.okType || 'primary';
const prefixCls = props.prefixCls || 'ant-modal';
const contentPrefixCls = `${prefixCls}-confirm`;
7 years ago
// 默认为 true保持向下兼容
const okCancel = 'okCancel' in props ? props.okCancel : true;
const width = props.width || 416;
const style = props.style || {};
7 years ago
// 默认为 false保持旧版默认行为
const maskClosable = props.maskClosable === undefined ? false : props.maskClosable;
const runtimeLocale = getConfirmLocale();
const okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
const cancelText = props.cancelText || runtimeLocale.cancelText;
const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
7 years ago
const classString = classNames(
contentPrefixCls,
`${contentPrefixCls}-${props.type}`,
7 years ago
`${prefixCls}-${props.type}`,
props.class,
);
7 years ago
const cancelButton = okCancel && (
<ActionButton
actionFn={onCancel}
closeModal={close}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
>
7 years ago
{cancelText}
</ActionButton>
);
7 years ago
return (
<Dialog
prefixCls={prefixCls}
7 years ago
class={classString}
wrapClassName={classNames({ [`${contentPrefixCls}-centered`]: !!centered })}
onCancel={e => close({ triggerCancel: true }, e)}
7 years ago
visible={visible}
title=""
transitionName="zoom"
footer=""
maskTransitionName="fade"
7 years ago
maskClosable={maskClosable}
maskStyle={maskStyle}
7 years ago
style={style}
width={width}
zIndex={zIndex}
afterClose={afterClose}
7 years ago
keyboard={keyboard}
centered={centered}
getContainer={getContainer}
7 years ago
>
<div class={`${contentPrefixCls}-body-wrapper`}>
<div class={`${contentPrefixCls}-body`}>
7 years ago
<Icon type={iconType} />
<span class={`${contentPrefixCls}-title`}>{props.title}</span>
<div class={`${contentPrefixCls}-content`}>{props.content}</div>
7 years ago
</div>
<div class={`${contentPrefixCls}-btns`}>
7 years ago
{cancelButton}
<ActionButton
type={okType}
actionFn={onOk}
closeModal={close}
autoFocus={autoFocusButton === 'ok'}
buttonProps={okButtonProps}
>
7 years ago
{okText}
</ActionButton>
</div>
</div>
</Dialog>
);
7 years ago
},
};