import { createPopper } from '@popperjs/core/lib/popper-lite'; import offsetModifier from '@popperjs/core/lib/modifiers/offset'; import { createNamespace } from '../utils'; import { BORDER_BOTTOM } from '../utils/constant'; // Mixins import { ClickOutsideMixin } from '../mixins/click-outside'; // Components import Icon from '../icon'; import Popup from '../popup'; const [createComponent, bem] = createNamespace('popover'); export default createComponent({ mixins: [ ClickOutsideMixin({ event: 'touchstart', method: 'onClickOutside', }), ], props: { value: Boolean, overlay: Boolean, textColor: String, backgroundColor: String, offset: { type: Array, default: () => [0, 8], }, theme: { type: String, default: 'light', }, actions: { type: Array, default: () => [], }, placement: { type: String, default: 'bottom', }, getContainer: { type: [String, Function], default: 'body', }, closeOnClickAction: { type: Boolean, default: true, }, }, watch: { placement: 'updateLocation', value(value) { if (value) { this.updateLocation(); } }, }, mounted() { if (this.value) { this.updateLocation(); } }, beforeDestroy() { if (this.popper) { this.popper.destroy(); this.popper = null; } }, methods: { createPopper() { return createPopper(this.$refs.wrapper, this.$refs.popover.$el, { placement: this.placement, modifiers: [ { name: 'computeStyles', options: { adaptive: false, gpuAcceleration: false, }, }, { ...offsetModifier, options: { offset: this.offset, }, }, ], }); }, updateLocation() { this.$nextTick(() => { if (!this.value) { return; } if (!this.popper) { this.popper = this.createPopper(); } else { this.popper.setOptions({ placement: this.placement, }); } }); }, renderAction(action, index) { const { icon, text, disabled, className } = action; return (