2017-12-22 18:43:28 +08:00
|
|
|
<script>
|
2017-12-25 18:08:36 +08:00
|
|
|
import PropTypes from '../_util/vue-types'
|
2017-12-22 18:43:28 +08:00
|
|
|
import Align from '../align'
|
|
|
|
import PopupInner from './PopupInner'
|
|
|
|
import LazyRenderBox from './LazyRenderBox'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
getClassNameFromAlign: PropTypes.func,
|
|
|
|
getRootDomNode: PropTypes.func,
|
|
|
|
align: PropTypes.any,
|
|
|
|
destroyPopupOnHide: PropTypes.bool,
|
|
|
|
prefixCls: PropTypes.string,
|
2017-12-25 18:08:36 +08:00
|
|
|
getContainer: PropTypes.func,
|
2017-12-26 19:04:28 +08:00
|
|
|
transitionName: PropTypes.string,
|
|
|
|
animation: PropTypes.any,
|
|
|
|
maskAnimation: PropTypes.string,
|
|
|
|
maskTransitionName: PropTypes.string,
|
|
|
|
mask: PropTypes.bool,
|
|
|
|
zIndex: PropTypes.number,
|
2017-12-22 18:43:28 +08:00
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.rootNode = this.getPopupDomNode()
|
2017-12-25 18:08:36 +08:00
|
|
|
this._container = this.getContainer()
|
2017-12-26 19:04:28 +08:00
|
|
|
// this._container.appendChild(this.$el)
|
|
|
|
// this.$refs.alignInstance.forceAlign()
|
2017-12-25 18:08:36 +08:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
this._container && this._container.parentNode.removeChild(this._container)
|
|
|
|
this._container = null
|
2017-12-22 18:43:28 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onAlign (popupDomNode, align) {
|
|
|
|
const props = this.$props
|
|
|
|
const currentAlignClassName = props.getClassNameFromAlign(align)
|
|
|
|
// FIX: https://github.com/react-component/trigger/issues/56
|
|
|
|
// FIX: https://github.com/react-component/tooltip/issues/79
|
|
|
|
if (this.currentAlignClassName !== currentAlignClassName) {
|
|
|
|
this.currentAlignClassName = currentAlignClassName
|
|
|
|
popupDomNode.className = this.getClassName(currentAlignClassName)
|
|
|
|
}
|
|
|
|
this.$emit('align', popupDomNode, align)
|
|
|
|
},
|
|
|
|
|
|
|
|
getPopupDomNode () {
|
2017-12-26 19:04:28 +08:00
|
|
|
return this.$refs.popupInstance ? this.$refs.popupInstance.$el : null
|
2017-12-22 18:43:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getTarget () {
|
|
|
|
return this.$props.getRootDomNode()
|
|
|
|
},
|
|
|
|
|
|
|
|
getMaskTransitionName () {
|
|
|
|
const props = this.$props
|
|
|
|
let transitionName = props.maskTransitionName
|
|
|
|
const animation = props.maskAnimation
|
|
|
|
if (!transitionName && animation) {
|
|
|
|
transitionName = `${props.prefixCls}-${animation}`
|
|
|
|
}
|
|
|
|
return transitionName
|
|
|
|
},
|
|
|
|
|
|
|
|
getTransitionName () {
|
|
|
|
const props = this.$props
|
|
|
|
let transitionName = props.transitionName
|
|
|
|
if (!transitionName && props.animation) {
|
|
|
|
transitionName = `${props.prefixCls}-${props.animation}`
|
|
|
|
}
|
2017-12-26 19:04:28 +08:00
|
|
|
return 'fade'
|
2017-12-22 18:43:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getClassName (currentAlignClassName) {
|
|
|
|
return `${this.$props.prefixCls} ${currentAlignClassName}`
|
|
|
|
},
|
|
|
|
onMouseEnter (e) {
|
|
|
|
this.$emit('mouseenter', e)
|
|
|
|
},
|
|
|
|
onMouseLeave (e) {
|
|
|
|
this.$emit('mouseleave', e)
|
|
|
|
},
|
|
|
|
getPopupElement () {
|
|
|
|
const { $props: props, onMouseEnter, onMouseLeave, $slots } = this
|
|
|
|
const { align, visible, prefixCls, destroyPopupOnHide } = props
|
|
|
|
const className = this.getClassName(this.currentAlignClassName ||
|
|
|
|
props.getClassNameFromAlign(align))
|
|
|
|
const hiddenClassName = `${prefixCls}-hidden`
|
|
|
|
if (!visible) {
|
|
|
|
this.currentAlignClassName = null
|
|
|
|
}
|
2017-12-25 18:08:36 +08:00
|
|
|
// visible = true
|
2017-12-22 18:43:28 +08:00
|
|
|
const popupInnerProps = {
|
|
|
|
props: {
|
|
|
|
prefixCls,
|
|
|
|
visible,
|
|
|
|
},
|
|
|
|
class: className,
|
|
|
|
on: {
|
|
|
|
mouseenter: onMouseEnter,
|
|
|
|
mouseleave: onMouseLeave,
|
|
|
|
},
|
|
|
|
ref: 'popupInstance',
|
|
|
|
style: { ...this.getZIndexStyle() },
|
|
|
|
}
|
2017-12-25 18:08:36 +08:00
|
|
|
|
2017-12-22 18:43:28 +08:00
|
|
|
if (destroyPopupOnHide) {
|
2017-12-25 18:08:36 +08:00
|
|
|
return (<transition
|
|
|
|
name={this.getTransitionName()}
|
2017-12-22 18:43:28 +08:00
|
|
|
>
|
|
|
|
{visible ? (<Align
|
|
|
|
target={this.getTarget}
|
|
|
|
key='popup'
|
|
|
|
ref='alignInstance'
|
|
|
|
monitorWindowResize
|
|
|
|
align={align}
|
|
|
|
onAlign={this.onAlign}
|
|
|
|
>
|
|
|
|
<PopupInner
|
|
|
|
{...popupInnerProps}
|
|
|
|
>
|
|
|
|
{$slots.default}
|
|
|
|
</PopupInner>
|
|
|
|
</Align>) : null}
|
2017-12-25 18:08:36 +08:00
|
|
|
</transition>)
|
2017-12-22 18:43:28 +08:00
|
|
|
}
|
2017-12-26 19:04:28 +08:00
|
|
|
popupInnerProps.props.hiddenClassName = 'hiddenClassName'
|
2017-12-25 18:08:36 +08:00
|
|
|
return (<transition
|
|
|
|
name={this.getTransitionName()}
|
2017-12-22 18:43:28 +08:00
|
|
|
>
|
|
|
|
<Align
|
2017-12-26 19:04:28 +08:00
|
|
|
v-show={visible}
|
2017-12-22 18:43:28 +08:00
|
|
|
target={this.getTarget}
|
|
|
|
key='popup'
|
|
|
|
ref='alignInstance'
|
|
|
|
monitorWindowResize
|
|
|
|
disabled={!visible}
|
|
|
|
align={align}
|
|
|
|
onAlign={this.onAlign}
|
|
|
|
>
|
|
|
|
<PopupInner
|
|
|
|
{...popupInnerProps}
|
|
|
|
>
|
|
|
|
{$slots.default}
|
|
|
|
</PopupInner>
|
|
|
|
</Align>
|
2017-12-25 18:08:36 +08:00
|
|
|
</transition>)
|
2017-12-22 18:43:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getZIndexStyle () {
|
|
|
|
const style = {}
|
|
|
|
const props = this.$props
|
|
|
|
if (props.zIndex !== undefined) {
|
|
|
|
style.zIndex = props.zIndex
|
|
|
|
}
|
|
|
|
return style
|
|
|
|
},
|
|
|
|
|
|
|
|
getMaskElement () {
|
|
|
|
const props = this.$props
|
|
|
|
let maskElement
|
|
|
|
if (props.mask) {
|
|
|
|
const maskTransition = this.getMaskTransitionName()
|
|
|
|
maskElement = (
|
|
|
|
<LazyRenderBox
|
|
|
|
style={this.getZIndexStyle()}
|
|
|
|
key='mask'
|
|
|
|
class={`${props.prefixCls}-mask`}
|
|
|
|
hiddenClassName={`${props.prefixCls}-mask-hidden`}
|
|
|
|
visible={props.visible}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
if (maskTransition) {
|
|
|
|
maskElement = (
|
2017-12-25 18:08:36 +08:00
|
|
|
<transition
|
|
|
|
name={maskTransition}
|
2017-12-22 18:43:28 +08:00
|
|
|
>
|
|
|
|
{maskElement}
|
2017-12-25 18:08:36 +08:00
|
|
|
</transition>
|
2017-12-22 18:43:28 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return maskElement
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.getMaskElement()}
|
|
|
|
{this.getPopupElement()}
|
2017-12-26 19:04:28 +08:00
|
|
|
<transition name='fade'>
|
|
|
|
<div v-show={this.visible}>hello</div>
|
|
|
|
</transition>
|
2017-12-22 18:43:28 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
},
|
2017-12-26 19:04:28 +08:00
|
|
|
// render () {
|
|
|
|
// return (
|
|
|
|
// <transition name='fade'>
|
|
|
|
// <div v-show={this.visible}>hello</div>
|
|
|
|
// </transition>
|
|
|
|
// )
|
|
|
|
// },
|
2017-12-22 18:43:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
2017-12-26 19:04:28 +08:00
|
|
|
|