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

Sent all the panel sizes via onPanelWidthChange in EuiResizableComponent rather than just the 2 panel sizes #3630

Merged
merged 9 commits into from
Jun 29, 2020
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
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