ant-design-vue/components/popconfirm/index.jsx

129 lines
3.2 KiB
React
Raw Normal View History

2018-03-19 10:16:27 +08:00
2018-01-12 19:04:42 +08:00
import omit from 'omit.js'
import Tooltip from '../tooltip'
import abstractTooltipProps from '../tooltip/abstractTooltipProps'
import PropTypes from '../_util/vue-types'
import { getOptionProps, hasProp, getComponentFromProp } from '../_util/props-util'
import BaseMixin from '../_util/BaseMixin'
import buttonTypes from '../button/buttonTypes'
import Icon from '../icon'
import Button from '../button'
import LocaleReceiver from '../locale-provider/LocaleReceiver'
import defaultLocale from '../locale-provider/default'
2018-01-12 19:04:42 +08:00
2018-01-15 17:33:34 +08:00
const tooltipProps = abstractTooltipProps()
const btnProps = buttonTypes()
2018-01-12 19:04:42 +08:00
export default {
name: 'popconfirm',
props: {
2018-01-15 17:33:34 +08:00
...tooltipProps,
2018-01-12 19:04:42 +08:00
prefixCls: PropTypes.string.def('ant-popover'),
transitionName: PropTypes.string.def('zoom-big'),
content: PropTypes.any,
title: PropTypes.any,
2018-01-15 17:33:34 +08:00
trigger: tooltipProps.trigger.def('click'),
okType: btnProps.type.def('primary'),
2018-01-12 19:04:42 +08:00
okText: PropTypes.any,
cancelText: PropTypes.any,
},
mixins: [BaseMixin],
model: {
prop: 'visible',
2018-01-15 17:33:34 +08:00
event: 'visibleChange',
},
watch: {
visible (val) {
this.sVisible = val
},
2018-01-12 19:04:42 +08:00
},
data () {
return {
sVisible: this.$props.visible,
}
},
methods: {
onConfirm (e) {
this.setVisible(false)
this.$emit('confirm', e)
},
onCancel (e) {
this.setVisible(false)
this.$emit('cancel', e)
},
onVisibleChange (sVisible) {
this.setVisible(sVisible)
},
setVisible (sVisible) {
if (!hasProp(this, 'visible')) {
this.setState({ sVisible })
}
2018-01-15 17:33:34 +08:00
this.$emit('visibleChange', sVisible)
2018-01-12 19:04:42 +08:00
},
getPopupDomNode () {
return this.$refs.tooltip.getPopupDomNode()
},
renderOverlay (popconfirmLocale) {
const { prefixCls, okType } = this
return (
<div class={`${prefixCls}-inner-content`}>
<div class={`${prefixCls}-message`}>
<Icon type='exclamation-circle' />
<div class={`${prefixCls}-message-title`}>
{getComponentFromProp(this, 'title')}
</div>
</div>
<div class={`${prefixCls}-buttons`}>
<Button onClick={this.onCancel} size='small'>
{getComponentFromProp(this, 'cancelText') || popconfirmLocale.cancelText}
</Button>
<Button onClick={this.onConfirm} type={okType} size='small'>
{getComponentFromProp(this, 'okText') || popconfirmLocale.okText}
</Button>
</div>
</div>
)
},
2018-01-12 19:04:42 +08:00
},
render (h) {
const props = getOptionProps(this)
const otherProps = omit(props, [
'title',
'content',
'cancelText',
'okText',
])
const tooltipProps = {
props: {
...otherProps,
visible: this.sVisible,
},
ref: 'tooltip',
on: {
change: this.onVisibleChange,
},
}
const overlay = (
<LocaleReceiver
componentName='Popconfirm'
defaultLocale={defaultLocale.Popconfirm}
scopedSlots={
{ default: this.renderOverlay }
}
/>)
2018-01-12 19:04:42 +08:00
return (
<Tooltip
{...tooltipProps}
>
<template slot='title'>
{overlay}
</template>
{this.$slots.default}
</Tooltip>
)
},
}