2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

fix: Popover

- hideArrow prop
- Use Popover in Dropdown
- Rename prop show to showPopup
This commit is contained in:
Faris Ansari 2020-02-03 23:22:28 +05:30
parent d3bd5c26e0
commit 0e5df61045
3 changed files with 41 additions and 27 deletions

View File

@ -1,6 +1,14 @@
<template> <template>
<div class="relative" v-on-outside-click="() => (isShown = false)"> <Popover
<div class="h-full"> :show-popup="isShown"
:hide-arrow="true"
:placement="right ? 'bottom-end' : 'bottom-start'"
>
<div
slot="target"
class="h-full"
v-on-outside-click="() => (isShown = false)"
>
<slot <slot
:toggleDropdown="toggleDropdown" :toggleDropdown="toggleDropdown"
:highlightItemUp="highlightItemUp" :highlightItemUp="highlightItemUp"
@ -8,12 +16,8 @@
:selectHighlightedItem="selectHighlightedItem" :selectHighlightedItem="selectHighlightedItem"
></slot> ></slot>
</div> </div>
<div <div slot="content" class="z-10 bg-white rounded w-full min-w-40">
:class="right ? 'right-0' : 'left-0'" <div class="p-1 max-h-64 overflow-auto text-sm">
class="mt-1 absolute z-10 bg-white rounded border w-full min-w-40 shadow-md"
v-if="isShown"
>
<div class="p-1 max-h-64 overflow-auto">
<div v-for="d in dropdownItems" :key="d.label"> <div v-for="d in dropdownItems" :key="d.label">
<div <div
v-if="d.isGroup" v-if="d.isGroup"
@ -36,10 +40,11 @@
</div> </div>
</div> </div>
</div> </div>
</div> </Popover>
</template> </template>
<script> <script>
import Popover from './Popover';
import uniq from 'lodash/uniq'; import uniq from 'lodash/uniq';
export default { export default {
@ -58,6 +63,9 @@ export default {
default: false default: false
} }
}, },
components: {
Popover
},
data() { data() {
return { return {
isShown: false, isShown: false,

View File

@ -10,7 +10,7 @@
class="bg-white rounded border min-w-40 shadow-md popover-container relative" class="bg-white rounded border min-w-40 shadow-md popover-container relative"
v-show="isOpen" v-show="isOpen"
> >
<div class="popover-arrow" ref="popover-arrow"></div> <div v-if="!hideArrow" class="popover-arrow" ref="popover-arrow"></div>
<slot name="content" :togglePopover="togglePopover"></slot> <slot name="content" :togglePopover="togglePopover"></slot>
</div> </div>
</portal> </portal>
@ -23,7 +23,11 @@ import { createPopper } from '@popperjs/core';
export default { export default {
name: 'Popover', name: 'Popover',
props: { props: {
show: { hideArrow: {
type: Boolean,
default: false
},
showPopup: {
default: null default: null
}, },
right: Boolean, right: Boolean,
@ -34,7 +38,7 @@ export default {
popoverClass: [String, Object, Array] popoverClass: [String, Object, Array]
}, },
watch: { watch: {
show(value) { showPopup(value) {
if (value === true) { if (value === true) {
this.open(); this.open();
} }
@ -74,7 +78,8 @@ export default {
if (!this.popper) { if (!this.popper) {
this.popper = createPopper(this.$refs.reference, this.$refs.popover, { this.popper = createPopper(this.$refs.reference, this.$refs.popover, {
placement: this.placement, placement: this.placement,
modifiers: [ modifiers: !this.hideArrow
? [
{ {
name: 'arrow', name: 'arrow',
options: { options: {
@ -88,6 +93,7 @@ export default {
} }
} }
] ]
: []
}); });
} else { } else {
this.popper.update(); this.popper.update();

View File

@ -26,7 +26,7 @@
" "
:autofocus="true" :autofocus="true"
/> />
<Popover placement="auto" :show="Boolean(emailError)"> <Popover placement="auto" :show-popup="Boolean(emailError)">
<template slot="target"> <template slot="target">
<FormControl <FormControl
:df="meta.getField('email')" :df="meta.getField('email')"