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

70 lines
1.8 KiB
Vue
Raw Normal View History

2019-01-12 11:33:27 +08:00
import Tooltip from '../tooltip';
import abstractTooltipProps from '../tooltip/abstractTooltipProps';
import PropTypes from '../_util/vue-types';
2020-01-19 16:58:38 +08:00
import { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
2019-04-10 09:23:53 +08:00
import { ConfigConsumerProps } from '../config-provider';
import Base from '../base';
2018-03-19 10:16:27 +08:00
2019-01-12 11:33:27 +08:00
const props = abstractTooltipProps();
const Popover = {
2018-04-08 21:17:20 +08:00
name: 'APopover',
2018-01-12 16:10:41 +08:00
props: {
2018-01-15 18:54:26 +08:00
...props,
prefixCls: PropTypes.string,
2018-01-12 16:10:41 +08:00
transitionName: PropTypes.string.def('zoom-big'),
content: PropTypes.any,
title: PropTypes.any,
},
model: {
prop: 'visible',
2018-06-26 10:17:30 +08:00
event: 'visibleChange',
2018-01-12 16:10:41 +08:00
},
2019-04-10 09:23:53 +08:00
inject: {
configProvider: { default: () => ConfigConsumerProps },
2019-04-10 09:23:53 +08:00
},
2018-01-12 16:10:41 +08:00
methods: {
2019-01-12 11:33:27 +08:00
getPopupDomNode() {
return this.$refs.tooltip.getPopupDomNode();
2018-01-12 16:10:41 +08:00
},
},
2019-02-01 17:23:00 +08:00
render() {
2019-04-10 09:23:53 +08:00
const { title, prefixCls: customizePrefixCls, $slots } = this;
2019-09-11 22:35:25 +08:00
const getPrefixCls = this.configProvider.getPrefixCls;
2019-04-10 09:23:53 +08:00
const prefixCls = getPrefixCls('popover', customizePrefixCls);
2019-01-12 11:33:27 +08:00
const props = getOptionProps(this);
delete props.title;
delete props.content;
2018-01-12 16:10:41 +08:00
const tooltipProps = {
props: {
...props,
2019-04-10 09:23:53 +08:00
prefixCls,
2018-01-12 16:10:41 +08:00
},
ref: 'tooltip',
2020-01-19 16:58:38 +08:00
on: getListeners(this),
2019-01-12 11:33:27 +08:00
};
2018-01-12 16:10:41 +08:00
return (
2019-01-12 11:33:27 +08:00
<Tooltip {...tooltipProps}>
<template slot="title">
2018-01-12 19:04:42 +08:00
<div>
2019-01-12 11:33:27 +08:00
{(title || $slots.title) && (
<div class={`${prefixCls}-title`}>{getComponentFromProp(this, 'title')}</div>
)}
<div class={`${prefixCls}-inner-content`}>{getComponentFromProp(this, 'content')}</div>
2018-01-12 19:04:42 +08:00
</div>
2018-01-12 16:10:41 +08:00
</template>
{this.$slots.default}
</Tooltip>
2019-01-12 11:33:27 +08:00
);
2018-01-12 16:10:41 +08:00
},
2019-01-12 11:33:27 +08:00
};
2018-01-12 16:10:41 +08:00
/* istanbul ignore next */
2019-01-12 11:33:27 +08:00
Popover.install = function(Vue) {
Vue.use(Base);
2019-01-12 11:33:27 +08:00
Vue.component(Popover.name, Popover);
};
2019-01-12 11:33:27 +08:00
export default Popover;