feat: popconfirm

This commit is contained in:
wangxueliang 2019-04-10 09:20:22 +08:00
parent fa41d5b205
commit 81e80bfaed

View File

@ -9,6 +9,7 @@ import Icon from '../icon';
import Button from '../button'; import Button from '../button';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default'; import defaultLocale from '../locale-provider/default';
import { ConfigConsumerProps } from '../config-provider';
const tooltipProps = abstractTooltipProps(); const tooltipProps = abstractTooltipProps();
const btnProps = buttonTypes(); const btnProps = buttonTypes();
@ -16,7 +17,7 @@ const Popconfirm = {
name: 'APopconfirm', name: 'APopconfirm',
props: { props: {
...tooltipProps, ...tooltipProps,
prefixCls: PropTypes.string.def('ant-popover'), prefixCls: PropTypes.string,
transitionName: PropTypes.string.def('zoom-big'), transitionName: PropTypes.string.def('zoom-big'),
content: PropTypes.any, content: PropTypes.any,
title: PropTypes.any, title: PropTypes.any,
@ -38,6 +39,9 @@ const Popconfirm = {
this.sVisible = val; this.sVisible = val;
}, },
}, },
inject: {
configProvider: { default: () => ({}) },
},
data() { data() {
const props = getOptionProps(this); const props = getOptionProps(this);
const state = { sVisible: false }; const state = { sVisible: false };
@ -72,8 +76,8 @@ const Popconfirm = {
getPopupDomNode() { getPopupDomNode() {
return this.$refs.tooltip.getPopupDomNode(); return this.$refs.tooltip.getPopupDomNode();
}, },
renderOverlay(popconfirmLocale) { renderOverlay(prefixCls, popconfirmLocale) {
const { prefixCls, okType, okButtonProps, cancelButtonProps } = this; const { okType, okButtonProps, cancelButtonProps } = this;
const icon = getComponentFromProp(this, 'icon') || ( const icon = getComponentFromProp(this, 'icon') || (
<Icon type="exclamation-circle" theme="filled" /> <Icon type="exclamation-circle" theme="filled" />
); );
@ -120,10 +124,15 @@ const Popconfirm = {
}, },
render() { render() {
const props = getOptionProps(this); const props = getOptionProps(this);
const { prefixCls: customizePrefixCls } = props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('popover', customizePrefixCls);
const otherProps = omit(props, ['title', 'content', 'cancelText', 'okText']); const otherProps = omit(props, ['title', 'content', 'cancelText', 'okText']);
const tooltipProps = { const tooltipProps = {
props: { props: {
...otherProps, ...otherProps,
prefixCls,
visible: this.sVisible, visible: this.sVisible,
}, },
ref: 'tooltip', ref: 'tooltip',
@ -135,7 +144,7 @@ const Popconfirm = {
<LocaleReceiver <LocaleReceiver
componentName="Popconfirm" componentName="Popconfirm"
defaultLocale={defaultLocale.Popconfirm} defaultLocale={defaultLocale.Popconfirm}
scopedSlots={{ default: this.renderOverlay }} scopedSlots={{ default: (popconfirmLocale) => this.renderOverlay(prefixCls, popconfirmLocale) }}
/> />
); );
return ( return (