Skip to content

Commit

Permalink
fix: renderer resizing (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza authored May 11, 2023
1 parent 65d68ce commit f1e3981
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.Resizable {
display: flex;
width: 100%;
}

.Resizable .resize-handle {
position: absolute;
width: 10px;
width: 3px;
height: 100%;
cursor: col-resize;
}
Expand Down
23 changes: 16 additions & 7 deletions packages/@dcl/inspector/src/components/Resizable/Resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ function Resizable(props: React.PropsWithChildren<PropTypes>) {
}, [value])

const handleDrag = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const clientValue = event[eventClientValue]
const diff = getParentOffset() - clientValue
if (!dragging || clientValue <= minValue || clientValue > (props.max || Infinity)) return
setValue([clientValue, diff])
if (props.onChange) props.onChange([clientValue, diff])
if (!dragging) return
resize(event[eventClientValue])
}

const resize = (value: number) => {
const diff = getParentOffset() - value
if (value <= minValue || value > (props.max || Infinity)) return
setValue([value, diff])
if (props.onChange) props.onChange([value, diff])
}

const handleMouseUp = useCallback(() => setDragging(false), [])
Expand All @@ -52,10 +56,15 @@ function Resizable(props: React.PropsWithChildren<PropTypes>) {
}
}, [])

const styles = {
[css.childs]: value[0] ?? 'auto',
[`min-${css.childs}`]: minValue
}

return (
<div className={`Resizable ${props.type}`} onMouseMove={handleDrag}>
<div ref={ref} style={{ [css.childs]: value[0] ?? 'auto' }}>{children[0]}</div>
<div className="resize-handle" style={{ [css.handle]: value[0] ?? 0 }} onMouseDown={() => setDragging(true)} />
<div ref={ref} style={styles}>{children[0]}</div>
<div className="resize-handle" onMouseDown={() => setDragging(true)} />
<div style={{ [css.childs]: value[1] ?? 'auto' }}>{children[1]}</div>
</div>
)
Expand Down

0 comments on commit f1e3981

Please sign in to comment.