1515 */
1616
1717import { useEffect , useRef , useState } from 'react'
18- import Draggable , { ControlPosition , DraggableData } from 'react-draggable'
19- import { DraggableWrapperProps , DraggablePositionVariant } from './types'
20- import { useWindowSize } from '../Hooks'
18+ import Draggable , { ControlPosition } from 'react-draggable'
19+
2120import { MAX_Z_INDEX } from '../Constants'
21+ import { useWindowSize } from '../Hooks'
22+ import { DraggablePositionVariant , DraggableWrapperProps } from './types'
2223
2324/**
2425 * TODO: import it as lazy, after it is supported in common
2526 * 1. If using react select please use menuPlacement='auto'
2627 * 2. dragSelector will be used to identify the grabbable button that will grab the div to drag
2728 * 3. parentRef is the reference point from which we will derive the base top:0 ,left: 0 position
2829 */
29- export default function DraggableWrapper ( {
30+ const DraggableWrapper = ( {
3031 children,
3132 zIndex = MAX_Z_INDEX ,
3233 positionVariant,
3334 dragSelector,
3435 parentRef,
3536 boundaryGap = 16 ,
3637 childDivProps = { } ,
37- layoutFixDelta = 0 ,
38- } : DraggableWrapperProps ) {
38+ } : DraggableWrapperProps ) => {
3939 const windowSize = useWindowSize ( )
4040 const nodeRef = useRef < HTMLDivElement > ( null )
41-
41+
4242 // letting the dom render the element without displaying it so that we know it's dimensions
4343 const [ initialRenderDone , setInitialRenderDone ] = useState ( false )
4444
45- const getDefaultPosition = ( positionVariant : DraggablePositionVariant ) : ControlPosition => {
45+ const getDefaultPosition = ( ) : ControlPosition => {
4646 // if this return x: 0, y: 0 then it will be top left corner of parentDiv
4747 const parentRect =
4848 parentRef ?. current ?. getBoundingClientRect ( ) ??
@@ -60,10 +60,6 @@ export default function DraggableWrapper({
6060 case DraggablePositionVariant . PARENT_BOTTOM_CENTER : {
6161 // center div to middle of the parent rect and then add the left offset of the parent rect
6262 const x = ( parentRect . width - nodeRefWidth ) / 2 + parentRect . left
63- // TODO (v3): Temp fix. Revisit
64- const parentRectTop = parentRect . top > 0 ? parentRect . top : layoutFixDelta
65- // currently at parentRect.y now parent height can be greater than windowSize.height so taking min
66- // subtracting parentRect.top since window height already contains that
6763 if ( parentRect . height > windowSize . height ) {
6864 return { x, y : windowSize . height - boundaryGap - nodeRefHeight }
6965 }
@@ -104,9 +100,10 @@ export default function DraggableWrapper({
104100 < Draggable
105101 key = { `${ JSON . stringify ( windowSize ) } ${ initialRenderDone } ` }
106102 handle = { dragSelector }
107- defaultPosition = { getDefaultPosition ( positionVariant ) }
103+ defaultPosition = { getDefaultPosition ( ) }
108104 bounds = "#devtron-base-main-identifier"
109- nodeRef = { nodeRef } >
105+ nodeRef = { nodeRef }
106+ >
110107 < div
111108 ref = { nodeRef }
112109 { ...childDivProps }
@@ -121,3 +118,5 @@ export default function DraggableWrapper({
121118 </ div >
122119 )
123120}
121+
122+ export default DraggableWrapper
0 commit comments