Skip to content

Commit

Permalink
move width and height into hook
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Apr 20, 2023
1 parent 7129771 commit 14dacf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,9 @@ const ColumnSelectPopover = ({
ColumnMeta | undefined
>(initialSimpleColumn);

const [width, setWidth] = useState(POPOVER_INITIAL_WIDTH);
const [height, setHeight] = useState(POPOVER_INITIAL_HEIGHT);

const resizeButton = useResizeButton(
const [resizeButton, width, height] = useResizeButton(
POPOVER_INITIAL_WIDTH,
POPOVER_INITIAL_HEIGHT,
width,
height,
setWidth,
setHeight,
);

const sqlEditorRef = useRef(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@

import React, { useCallback, useEffect, useState } from 'react';
import throttle from 'lodash/throttle';
import {
POPOVER_INITIAL_HEIGHT,
POPOVER_INITIAL_WIDTH,
} from 'src/explore/constants';

const RESIZE_THROTTLE_MS = 50;

export default function useResizeButton(
minWidth: number,
minHeight: number,
width: number,
height: number,
setWidth: (newWidth: number) => void,
setHeight: (newHeight: number) => void,
) {
): [JSX.Element, number, number] {
const [width, setWidth] = useState(POPOVER_INITIAL_WIDTH);
const [height, setHeight] = useState(POPOVER_INITIAL_HEIGHT);
const [clientX, setClientX] = useState(0);
const [clientY, setClientY] = useState(0);
const [dragStartX, setDragStartX] = useState(0);
Expand Down Expand Up @@ -123,13 +125,15 @@ export default function useResizeButton(
return () => document.removeEventListener('mouseup', onMouseUp);
}, [onMouseUp]);

return (
return [
<i
role="button"
aria-label="Resize"
tabIndex={0}
onMouseDown={onDragDown}
className="fa fa-expand edit-popover-resize text-muted"
/>
);
/>,
width,
height,
];
}

0 comments on commit 14dacf8

Please sign in to comment.