Skip to content

Commit

Permalink
Sent all the panel sizes via onPanelWidthChange in `EuiResizableCom…
Browse files Browse the repository at this point in the history
…ponent` rather than just the 2 panel sizes (#3630)

* Sent all the panel sizes via  in  rather than just the 2 panels

* Fixed lint errors

* sent percentages instead of pixels and formatted

* Lint

* Lint errors fixed

* updated changes

* Updated changes

* CL

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
  • Loading branch information
shrey and thompsongl authored Jun 29, 2020
1 parent 88f1167 commit c042314
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added `gutterSize` prop to `EuiFacetGroup` ([#3639](https://github.com/elastic/eui/pull/3639))
- Updated props of `EuiCode` and `EuiCodeBlock` to reflect only functional props ([#3647](https://github.com/elastic/eui/pull/3647))
- Updated `EuiResizableContainer` `onPanelWidthChange` callback method to include all panel widths ([#3630](https://github.com/elastic/eui/pull/3630))

**Bug fixes**

Expand Down
15 changes: 15 additions & 0 deletions src/components/resizable_container/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ export class EuiResizablePanelRegistry {
getResizerSiblings(prevPanelId: string, nextPanelId: string) {
return [this.panels[prevPanelId], this.panels[nextPanelId]];
}

fetchAllPanels(
prevPanelId: string,
nextPanelId: string,
containerSize: number
) {
const panelWithSizes: { [key: string]: number } = {};
for (const key in this.panels) {
if (key !== prevPanelId && key !== nextPanelId) {
panelWithSizes[key] =
(this.panels[key].getSizePx() / containerSize) * 100;
}
}
return panelWithSizes;
}
}

interface ContextProps {
Expand Down
21 changes: 16 additions & 5 deletions src/components/resizable_container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ export const useContainerCallbacks = ({
);

setState({ ...state, isDragging: false });
if (onPanelWidthChange) {
const panelObject = registry.fetchAllPanels(
prevPanelId,
nextPanelId,
containerSize - resizersSize
);
if (prevPanelSize !== nextPanelSize && onPanelWidthChange) {
onPanelWidthChange({
...panelObject,
[prevPanelId]: prevPanelSize,
[nextPanelId]: nextPanelSize,
});
} else {

prevPanel.setSize(prevPanelSize);
nextPanel.setSize(nextPanelSize);
}
Expand Down Expand Up @@ -204,16 +210,21 @@ export const useContainerCallbacks = ({
containerSize
);

const panelObject = registry.fetchAllPanels(
state.previousPanelId,
state.nextPanelId,
containerSize
);
if (prevPanelSize >= prevPanelMin && nextPanelSize >= nextPanelMin) {
if (onPanelWidthChange) {
onPanelWidthChange({
...panelObject,
[state.previousPanelId]: prevPanelSize,
[state.nextPanelId]: nextPanelSize,
});
} else {
prevPanel.setSize(prevPanelSize);
nextPanel.setSize(nextPanelSize);
}
prevPanel.setSize(prevPanelSize);
nextPanel.setSize(nextPanelSize);

setState({ ...state, currentResizerPos: x });
}
Expand Down

0 comments on commit c042314

Please sign in to comment.