ant-design-vue/components/tooltip/src/Tooltip.vue

109 lines
3.2 KiB
Vue
Raw Normal View History

2018-01-11 18:53:51 +08:00
<script>
import PropTypes from '../../_util/vue-types'
import Trigger from '../../trigger'
import { placements } from './placements'
import hasProp from '../../_util/hasProp'
export default {
props: {
trigger: PropTypes.any.def(['hover']),
defaultVisible: PropTypes.bool,
visible: PropTypes.bool,
placement: PropTypes.string.def('right'),
transitionName: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]),
animation: PropTypes.any,
// onVisibleChange: PropTypes.func,
afterVisibleChange: PropTypes.func.def(() => {}),
overlay: PropTypes.any,
overlayStyle: PropTypes.object,
overlayClassName: PropTypes.string,
prefixCls: PropTypes.string.def('rc-tooltip'),
mouseEnterDelay: PropTypes.number.def(0),
mouseLeaveDelay: PropTypes.number.def(0.1),
getTooltipContainer: PropTypes.func,
destroyTooltipOnHide: PropTypes.bool.def(false),
align: PropTypes.object.def({}),
arrowContent: PropTypes.any.def(null),
tipId: PropTypes.string,
builtinPlacements: PropTypes.object,
},
methods: {
getPopupElement (h) {
const { arrowContent, overlay, prefixCls, tipId } = this.$props
return ([
<div class={`${prefixCls}-arrow`} key='arrow'>
{this.$slots.arrowContent}
{typeof arrowContent === 'function' ? arrowContent(h) : arrowContent}
</div>,
<div class={`${prefixCls}-inner`} key='content' id={tipId}>
{typeof overlay === 'function' ? overlay(h) : overlay}
{this.$slots.overlay}
</div>,
])
},
getPopupDomNode () {
return this.$refs.trigger.getPopupDomNode()
},
onVisibleChange (val) {
this.$emit('visibleChange', val)
},
onPopupAlign () {
this.$emit('popupAlign', ...arguments)
},
},
render (h) {
const {
overlayClassName, trigger,
mouseEnterDelay, mouseLeaveDelay,
overlayStyle, prefixCls,
afterVisibleChange,
transitionName, animation,
placement, align,
destroyTooltipOnHide,
defaultVisible, getTooltipContainer,
...restProps
} = this.$props
const extraProps = { ...restProps }
if (hasProp(this, 'visible')) {
extraProps.popupVisible = this.$props.visible
}
const triggerProps = {
props: {
popupClassName: overlayClassName,
prefixCls: prefixCls,
action: trigger,
builtinPlacements: placements,
popupPlacement: placement,
popupAlign: align,
getPopupContainer: getTooltipContainer,
// onPopupVisibleChange: onVisibleChange,
afterPopupVisibleChange: afterVisibleChange,
popupTransitionName: transitionName,
popupAnimation: animation,
defaultPopupVisible: defaultVisible,
destroyPopupOnHide: destroyTooltipOnHide,
mouseLeaveDelay: mouseLeaveDelay,
popupStyle: overlayStyle,
mouseEnterDelay: mouseEnterDelay,
...extraProps,
},
on: {
popupVisibleChange: this.onVisibleChange,
popupAlign: this.onPopupAlign,
},
ref: 'trigger',
}
return (<Trigger {...triggerProps}>
<template slot='popup'>
{this.getPopupElement(h)}
</template>
{this.$slots.default}
</Trigger>)
},
}
</script>