Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: renderer resizing #577

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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