mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
add(paceable): add flip prop
This commit is contained in:
parent
0b8b3dfd34
commit
90fb7ea091
@ -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)
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user