parent
123afca2f2
commit
2bd2a91944
@ -0,0 +1,26 @@ |
|||||||
|
/* dragbar UI */ |
||||||
|
|
||||||
|
.dragbar { |
||||||
|
display : block; |
||||||
|
height : 100%; |
||||||
|
position : absolute; |
||||||
|
left: 0px; |
||||||
|
top: 0px; |
||||||
|
width: 0.3em; |
||||||
|
z-index: 9999; |
||||||
|
} |
||||||
|
|
||||||
|
.overlay { |
||||||
|
position: absolute; |
||||||
|
left: 0; |
||||||
|
top: 0; |
||||||
|
width: 100vw; |
||||||
|
height: 100vh; |
||||||
|
display: block; |
||||||
|
z-index: 9998; |
||||||
|
} |
||||||
|
|
||||||
|
.dragbar:hover, .dragbar.ondrag{ |
||||||
|
background-color: var(--secondary); |
||||||
|
cursor:col-resize; |
||||||
|
} |
@ -1,36 +1,53 @@ |
|||||||
import React, { useState } from 'react' |
import React, { useEffect, useState } from 'react' |
||||||
import Draggable from 'react-draggable' |
import Draggable from 'react-draggable' |
||||||
|
import './dragbar.css' |
||||||
|
|
||||||
interface IRemixDragBarUi { |
interface IRemixDragBarUi { |
||||||
refObject: React.MutableRefObject<any>; |
refObject: React.MutableRefObject<any>; |
||||||
setHideStatus: (hide: boolean) => void; |
setHideStatus: (hide: boolean) => void; |
||||||
|
hidden: boolean |
||||||
|
minWidth: number |
||||||
} |
} |
||||||
|
|
||||||
const DragBar = (props: IRemixDragBarUi) => { |
const DragBar = (props: IRemixDragBarUi) => { |
||||||
const [dragState, setDragState] = useState<boolean>(false) |
const [dragState, setDragState] = useState<boolean>(false) |
||||||
const [dragBarPos, setDragBarPos] = useState<number>(0) |
const [dragBarPosX, setDragBarPosX] = useState<number>(0) |
||||||
|
const [offset, setOffSet] = useState<number>(0) |
||||||
|
const nodeRef = React.useRef(null) // fix for strictmode
|
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
// arbitrary time out to wait the the UI to be completely done
|
||||||
|
setTimeout(() => { |
||||||
|
setOffSet(props.refObject.current.offsetLeft) |
||||||
|
setDragBarPosX(offset + props.refObject.current.offsetWidth) |
||||||
|
}, 1000) |
||||||
|
}, []) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
setDragBarPosX(offset + (props.hidden ? 0 : props.refObject.current.offsetWidth)) |
||||||
|
}, [props.hidden, offset]) |
||||||
|
|
||||||
function stopDrag (e: MouseEvent, data: any) { |
function stopDrag (e: MouseEvent, data: any) { |
||||||
console.log(data) |
|
||||||
setDragState(false) |
setDragState(false) |
||||||
props.refObject.current.style.width = (320 + data.x) + 'px' |
if (data.x < props.minWidth) { |
||||||
console.log(props.refObject.current.offsetWidth) |
setDragBarPosX(offset) |
||||||
if ((320 + data.x) < 250) { |
|
||||||
props.setHideStatus(true) |
props.setHideStatus(true) |
||||||
setDragBarPos(41 - 360) |
|
||||||
} else { |
} else { |
||||||
|
props.refObject.current.style.width = (data.x - offset) + 'px' |
||||||
props.setHideStatus(false) |
props.setHideStatus(false) |
||||||
setDragBarPos(props.refObject.current.offsetWidth - 320) |
setDragBarPosX(offset + props.refObject.current.offsetWidth) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
function startDrag (e: MouseEvent, data: any) { |
function startDrag () { |
||||||
console.log('start') |
|
||||||
setDragState(true) |
setDragState(true) |
||||||
} |
} |
||||||
return <Draggable position={{ x: dragBarPos, y: 0 }} onStart={startDrag} onStop={stopDrag} axis="x"> |
return <> |
||||||
<div className={`dragbar ${dragState ? 'ondrag' : ''}`}></div> |
<div className={`overlay ${dragState ? '' : 'd-none'}`} ></div> |
||||||
</Draggable> |
<Draggable nodeRef={nodeRef} position={{ x: dragBarPosX, y: 0 }} onStart={startDrag} onStop={stopDrag} axis="x"> |
||||||
|
<div ref={nodeRef} className={`dragbar ${dragState ? 'ondrag' : ''}`}></div> |
||||||
|
</Draggable> |
||||||
|
</> |
||||||
} |
} |
||||||
|
|
||||||
export default DragBar |
export default DragBar |
||||||
|
Loading…
Reference in new issue