Skip to content

Commit

Permalink
Merge pull request #77 from perimetre/7.1.0
Browse files Browse the repository at this point in the history
7.1.0
  • Loading branch information
AssisrMatheus authored Jul 21, 2022
2 parents 603afee + 4641bf4 commit ac9106e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [7.0.1] 2022-07-21

### Changes

- `HorizontalResizeablePanel` also triggers events

## [7.0.0] 2022-07-21

### Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@perimetre/ui",
"description": "A component library made by @perimetre",
"version": "7.0.0",
"version": "7.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/perimetre/ui.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export default {
control: {
type: 'text'
}
}
},
onResize: { action: 'onResize' },
onResizeChange: { action: 'onResizeChange' }
}
} as Meta;

Expand Down
18 changes: 18 additions & 0 deletions src/components/HorizontalResizeablePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export type HorizontalResizeablePanelProps = React.HTMLAttributes<HTMLDivElement
* Callback that is called every time the panel is being resized
*/
onResize?: () => void;
/**
* Callback for when the isResizing state changes
*/
onResizeChange?: (isResizing: boolean) => void;

children?: (props: { isResizing: boolean }) => React.ReactNode;
};
Expand All @@ -46,6 +50,7 @@ export type HorizontalResizeablePanelProps = React.HTMLAttributes<HTMLDivElement
* @param props.minRightSize The minimum width allowed when resizing from the right border
* @param props.maxRightSize The maximum width allowed when resizing from the right border
* @param props.onResize Callback that is called every time the panel is being resized
* @param props.onResizeChange Callback for when the isResizing state changes
* @param props.children The element children components
*/
export const HorizontalResizeablePanel: React.FC<HorizontalResizeablePanelProps> = ({
Expand All @@ -56,13 +61,26 @@ export const HorizontalResizeablePanel: React.FC<HorizontalResizeablePanelProps>
minRightSize,
maxRightSize,
onResize,
onResizeChange,
children,
...props
}) => {
const [isResizing, setIsResizing] = useState(false);

const dragRef = useRef<{ isResizing: boolean; lastDownX: number; resizeSide: 'left' | 'right' } | null>(null);
const ref = useRef<HTMLDivElement>(null);
const didInitialize = useRef<boolean | null>(null);

useEffect(() => {
// If the method exists, and has the component initialized
if (onResizeChange && didInitialize.current) {
onResizeChange(isResizing);
}

if (!didInitialize.current) {
didInitialize.current = true;
}
}, [isResizing, onResizeChange]);

useEffect(() => {
/**
Expand Down

0 comments on commit ac9106e

Please sign in to comment.