2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import Trigger from '../vc-trigger';
|
|
|
|
import { placements } from './placements';
|
|
|
|
import Content from './Content';
|
2020-01-18 21:44:13 +08:00
|
|
|
import { hasProp, getComponentFromProp, getOptionProps, getListeners } from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
function noop() {}
|
2018-01-11 18:53:51 +08:00
|
|
|
export default {
|
|
|
|
props: {
|
2018-09-05 21:28:54 +08:00
|
|
|
trigger: PropTypes.any.def(['hover']),
|
2018-01-11 18:53:51 +08:00
|
|
|
defaultVisible: PropTypes.bool,
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
placement: PropTypes.string.def('right'),
|
2019-01-12 11:33:27 +08:00
|
|
|
transitionName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
2018-01-11 18:53:51 +08:00
|
|
|
animation: PropTypes.any,
|
|
|
|
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),
|
2020-03-07 19:45:13 +08:00
|
|
|
align: PropTypes.object.def(() => ({})),
|
2018-01-11 18:53:51 +08:00
|
|
|
arrowContent: PropTypes.any.def(null),
|
|
|
|
tipId: PropTypes.string,
|
|
|
|
builtinPlacements: PropTypes.object,
|
|
|
|
},
|
|
|
|
methods: {
|
2019-02-01 17:23:00 +08:00
|
|
|
getPopupElement() {
|
2019-01-12 11:33:27 +08:00
|
|
|
const { prefixCls, tipId } = this.$props;
|
|
|
|
return [
|
|
|
|
<div class={`${prefixCls}-arrow`} key="arrow">
|
2018-01-18 10:43:39 +08:00
|
|
|
{getComponentFromProp(this, 'arrowContent')}
|
2018-01-11 18:53:51 +08:00
|
|
|
</div>,
|
2018-09-05 21:28:54 +08:00
|
|
|
<Content
|
2019-01-12 11:33:27 +08:00
|
|
|
key="content"
|
2018-09-05 21:28:54 +08:00
|
|
|
trigger={this.$refs.trigger}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
id={tipId}
|
|
|
|
overlay={getComponentFromProp(this, 'overlay')}
|
|
|
|
/>,
|
2019-01-12 11:33:27 +08:00
|
|
|
];
|
2018-01-11 18:53:51 +08:00
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
getPopupDomNode() {
|
|
|
|
return this.$refs.trigger.getPopupDomNode();
|
2018-01-11 18:53:51 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render(h) {
|
2018-01-11 18:53:51 +08:00
|
|
|
const {
|
2019-01-12 11:33:27 +08:00
|
|
|
overlayClassName,
|
|
|
|
trigger,
|
|
|
|
mouseEnterDelay,
|
|
|
|
mouseLeaveDelay,
|
|
|
|
overlayStyle,
|
|
|
|
prefixCls,
|
2018-01-11 18:53:51 +08:00
|
|
|
afterVisibleChange,
|
2019-01-12 11:33:27 +08:00
|
|
|
transitionName,
|
|
|
|
animation,
|
|
|
|
placement,
|
|
|
|
align,
|
2018-01-11 18:53:51 +08:00
|
|
|
destroyTooltipOnHide,
|
2019-01-12 11:33:27 +08:00
|
|
|
defaultVisible,
|
|
|
|
getTooltipContainer,
|
2018-01-11 18:53:51 +08:00
|
|
|
...restProps
|
2019-01-12 11:33:27 +08:00
|
|
|
} = getOptionProps(this);
|
|
|
|
const extraProps = { ...restProps };
|
2018-01-11 18:53:51 +08:00
|
|
|
if (hasProp(this, 'visible')) {
|
2019-01-12 11:33:27 +08:00
|
|
|
extraProps.popupVisible = this.$props.visible;
|
2018-01-11 18:53:51 +08:00
|
|
|
}
|
2020-01-18 21:44:13 +08:00
|
|
|
const listeners = getListeners(this);
|
2018-01-11 18:53:51 +08:00
|
|
|
const triggerProps = {
|
|
|
|
props: {
|
|
|
|
popupClassName: overlayClassName,
|
2020-03-18 14:52:02 +08:00
|
|
|
prefixCls,
|
2018-01-11 18:53:51 +08:00
|
|
|
action: trigger,
|
|
|
|
builtinPlacements: placements,
|
|
|
|
popupPlacement: placement,
|
|
|
|
popupAlign: align,
|
|
|
|
getPopupContainer: getTooltipContainer,
|
|
|
|
afterPopupVisibleChange: afterVisibleChange,
|
|
|
|
popupTransitionName: transitionName,
|
|
|
|
popupAnimation: animation,
|
|
|
|
defaultPopupVisible: defaultVisible,
|
|
|
|
destroyPopupOnHide: destroyTooltipOnHide,
|
2020-03-18 14:52:02 +08:00
|
|
|
mouseLeaveDelay,
|
2018-01-11 18:53:51 +08:00
|
|
|
popupStyle: overlayStyle,
|
2020-03-18 14:52:02 +08:00
|
|
|
mouseEnterDelay,
|
2018-03-26 12:18:06 +08:00
|
|
|
...extraProps,
|
2018-01-11 18:53:51 +08:00
|
|
|
},
|
|
|
|
on: {
|
2020-01-18 21:44:13 +08:00
|
|
|
...listeners,
|
|
|
|
popupVisibleChange: listeners.visibleChange || noop,
|
|
|
|
popupAlign: listeners.popupAlign || noop,
|
2018-01-11 18:53:51 +08:00
|
|
|
},
|
|
|
|
ref: 'trigger',
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Trigger {...triggerProps}>
|
|
|
|
<template slot="popup">{this.getPopupElement(h)}</template>
|
|
|
|
{this.$slots.default}
|
|
|
|
</Trigger>
|
|
|
|
);
|
2018-01-11 18:53:51 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|