add(paceable): add flip prop

This commit is contained in:
songwanli2025@163.com 2019-12-31 16:18:51 +08:00
parent 0b8b3dfd34
commit 90fb7ea091
2 changed files with 11 additions and 4 deletions

View File

@ -116,6 +116,10 @@ export default {
manuallyPositioned: {
type: Boolean,
default: false
},
flip: {
type: Boolean,
default: true
}
},
computed: {
@ -229,7 +233,7 @@ export default {
// console.log(contentBoundingClientRect)
// debugger
// console.log('scroll', activatorBoundingClientRect, contentBoundingClientRect)
const [placementTransform, suggestedTransformOrigin] = calcPlacementTransfrom(this.placement, activatorBoundingClientRect, contentBoundingClientRect)
const [placementTransform, suggestedTransformOrigin] = calcPlacementTransfrom(this.placement, activatorBoundingClientRect, contentBoundingClientRect, this.flip)
// console.log(this.trackingElement, this.positionMode, this.positionModeisAbsolute)
if (this.positionModeisAbsolute) {
const position = getPositionInAbsoluteMode(this.placement, suggestedTransformOrigin)

View File

@ -19,7 +19,10 @@ const lengthToCompare = {
right: 'width'
}
function getAdjustedPlacementOfTrackingElement (placement = 'bottom-start', trackedRect, trackingRect) {
function getAdjustedPlacementOfTrackingElement (placement = 'bottom-start', trackedRect, trackingRect, flip) {
if (!flip) {
return placement
}
let [direction, position] = placement.split('-')
let newPosition = position
if (position === 'start') {
@ -141,7 +144,7 @@ function getPosition (placement, trackedRect, trackingRect) {
return position
}
function calcPlacementTransform (placement, activatorRect, contentRect) {
function calcPlacementTransform (placement, activatorRect, contentRect, flip) {
const trackedRect = {
left: parseInt(activatorRect.left),
top: parseInt(activatorRect.top),
@ -151,7 +154,7 @@ function calcPlacementTransform (placement, activatorRect, contentRect) {
height: parseInt(activatorRect.height)
}
const trackingRect = contentRect
const adjustedPlacement = getAdjustedPlacementOfTrackingElement(placement, trackedRect, trackingRect)
const adjustedPlacement = getAdjustedPlacementOfTrackingElement(placement, trackedRect, trackingRect, flip)
const suggesetedTransfromOrigin = getTransformOriginByPlacement(adjustedPlacement)
const position = getPosition(adjustedPlacement, trackedRect, trackingRect)
return [position, suggesetedTransfromOrigin]