clean up and fixes, change popover padding -> margin

This commit is contained in:
Shpuld Shpuldson 2020-02-19 08:49:04 +02:00
parent 813d121cdd
commit 16302b5630
4 changed files with 53 additions and 39 deletions

View file

@ -69,12 +69,10 @@
margin: 0 .8em; margin: 0 .8em;
} }
.account-tools-popover {
}
.account-actions button.dropdown-item { .account-actions button.dropdown-item {
margin-left: 0; margin-left: 0;
} }
.account-actions .trigger-button { .account-actions .trigger-button {
color: $fallback--lightText; color: $fallback--lightText;
color: var(--lightText, $fallback--lightText); color: var(--lightText, $fallback--lightText);

View file

@ -23,7 +23,12 @@
:compact="true" :compact="true"
/> />
<div class="reacted-user-names"> <div class="reacted-user-names">
<span class="reacted-user-name" v-html="account.name_html" /> <!-- eslint-disable vue/no-v-html -->
<span
class="reacted-user-name"
v-html="account.name_html"
/>
<!-- eslint-enable vue/no-v-html -->
<span class="reacted-user-screen-name">{{ account.screen_name }}</span> <span class="reacted-user-screen-name">{{ account.screen_name }}</span>
</div> </div>
</div> </div>
@ -44,15 +49,14 @@
</button> </button>
</Popover> </Popover>
<a <a
v-if="tooManyReactions" v-if="tooManyReactions"
@click="toggleShowAll" class="emoji-reaction-expand faint"
class="emoji-reaction-expand faint" href="javascript:void(0)"
href='javascript:void(0)' @click="toggleShowAll"
> >
{{ showAll ? $t('general.show_less') : showMoreString }} {{ showAll ? $t('general.show_less') : showMoreString }}
</a> </a>
</div> </div>
</template> </template>
<script src="./emoji_reactions.js" ></script> <script src="./emoji_reactions.js" ></script>

View file

@ -1,14 +1,24 @@
const Popover = { const Popover = {
name: 'Popover', name: 'Popover',
props: [ props: {
'trigger', // Action to trigger popover: either 'hover' or 'click'
'placement', trigger: String,
'boundTo', // Either 'top' or 'bottom'
'padding', placement: String,
'offset', // Takes object with properties 'x' and 'y', values of these can be
'popoverClass' // 'container' for using offsetParent as boundaries for either axis
], // or 'viewport'
boundTo: Object,
// Takes a top/bottom/left/right object, how much space to leave
// between boundary and popover element
margin: Object,
// Takes a x/y object and tells how many pixels to offset from
// anchor point on either axis
offset: Object,
// Additional styles you may want for the popover container
popoverClass: String
},
data () { data () {
return { return {
hidden: true, hidden: true,
@ -16,14 +26,14 @@ const Popover = {
oldSize: { width: 0, height: 0 } oldSize: { width: 0, height: 0 }
} }
}, },
computed: {
display () {
return !this.hidden
}
},
methods: { methods: {
updateStyles () { updateStyles () {
if (this.hidden) return { opacity: 0 } if (this.hidden) {
this.styles = {
opacity: 0
}
return
}
// Popover will be anchored around this element, trigger ref is the container, so // Popover will be anchored around this element, trigger ref is the container, so
// its children are what are inside the slot. Expect only one slot="trigger". // its children are what are inside the slot. Expect only one slot="trigger".
@ -36,31 +46,31 @@ const Popover = {
const parentBounds = this.boundTo && const parentBounds = this.boundTo &&
(this.boundTo.x === 'container' || this.boundTo.y === 'container') && (this.boundTo.x === 'container' || this.boundTo.y === 'container') &&
this.$el.offsetParent.getBoundingClientRect() this.$el.offsetParent.getBoundingClientRect()
const padding = this.padding || {} const margin = this.margin || {}
// What are the screen bounds for the popover? Viewport vs container // What are the screen bounds for the popover? Viewport vs container
// when using viewport, using default padding values to dodge the navbar // when using viewport, using default margin values to dodge the navbar
const xBounds = this.boundTo && this.boundTo.x === 'container' ? { const xBounds = this.boundTo && this.boundTo.x === 'container' ? {
min: parentBounds.left + (padding.left || 0), min: parentBounds.left + (margin.left || 0),
max: parentBounds.right - (padding.right || 0) max: parentBounds.right - (margin.right || 0)
} : { } : {
min: 0 + (padding.left || 10), min: 0 + (margin.left || 10),
max: window.innerWidth - (padding.right || 10) max: window.innerWidth - (margin.right || 10)
} }
const yBounds = this.boundTo && this.boundTo.y === 'container' ? { const yBounds = this.boundTo && this.boundTo.y === 'container' ? {
min: parentBounds.top + (padding.top || 0), min: parentBounds.top + (margin.top || 0),
max: parentBounds.bottom - (padding.bottom || 0) max: parentBounds.bottom - (margin.bottom || 0)
} : { } : {
min: 0 + (padding.top || 50), min: 0 + (margin.top || 50),
max: window.innerHeight - (padding.bottom || 5) max: window.innerHeight - (margin.bottom || 5)
} }
let horizOffset = 0 let horizOffset = 0
// If overflowing from left, move it so that it doesn't // If overflowing from left, move it so that it doesn't
if ((origin.x - content.offsetWidth * 0.5) < xBounds.min) { if ((origin.x - content.offsetWidth * 0.5) < xBounds.min) {
horizOffset = -(origin.x - content.offsetWidth * 0.5) + xBounds.min horizOffset += -(origin.x - content.offsetWidth * 0.5) + xBounds.min
} }
// If overflowing from right, move it so that it doesn't // If overflowing from right, move it so that it doesn't
@ -85,9 +95,11 @@ const Popover = {
const xOffset = (this.offset && this.offset.x) || 0 const xOffset = (this.offset && this.offset.x) || 0
const translateX = (anchorEl.offsetWidth * 0.5) - content.offsetWidth * 0.5 + horizOffset + xOffset const translateX = (anchorEl.offsetWidth * 0.5) - content.offsetWidth * 0.5 + horizOffset + xOffset
// Note, separate translateX and translateY avoids blurry text on chromium,
// single translate or translate3d resulted in blurry text.
this.styles = { this.styles = {
opacity: 1, opacity: 1,
transform: `translate(${Math.floor(translateX)}px) translateY(${Math.floor(translateY)}px)` transform: `translateX(${Math.floor(translateX)}px) translateY(${Math.floor(translateY)}px)`
} }
}, },
showPopover () { showPopover () {

View file

@ -10,7 +10,7 @@
<slot name="trigger" /> <slot name="trigger" />
</div> </div>
<div <div
v-if="display" v-if="!hidden"
ref="content" ref="content"
:style="styles" :style="styles"
class="popover" class="popover"