mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
## Summary
This PR adds resize support to the Discover field list sidebar, which is
persisted to a user's local storage similar to the resizable chart
height.
Additionally it migrates the resizable layout code from Unified
Histogram to a new package called `kbn-resizable-layout` so it can be
shared between Discover and Unified Histogram, as well as act as a new
platform component that other teams can consume to create their own
resizable layouts.
 => {
const [fixedPanelSize, setFixedPanelSize] = useState(500);
const [container, setContainer] = useState<HTMLDivElement | null>(null);
const [fixedPanelNode] = useState(() =>
createHtmlPortalNode({ attributes: { class: 'eui-fullHeight' } })
);
const [flexPanelNode] = useState(() =>
createHtmlPortalNode({ attributes: { class: 'eui-fullHeight' } })
);
const isMobile = useIsWithinBreakpoints(['xs']);
const layoutMode = isMobile ? ResizableLayoutMode.Static : ResizableLayoutMode.Resizable;
const layoutDirection = isMobile
? ResizableLayoutDirection.Vertical
: ResizableLayoutDirection.Horizontal;
const fullWidthAndHeightCss = css`
position: relative;
width: 100%;
height: 100%;
`;
const panelBaseCss = css`
${fullWidthAndHeightCss}
padding: 20px;
`;
const fixedPanelCss = css`
${panelBaseCss}
background-color: rgb(255 0 0 / 30%);
`;
const flexPanelCss = css`
${panelBaseCss}
background-color: rgb(0 0 255 / 30%);
`;
return (
<div ref={setContainer} css={fullWidthAndHeightCss}>
<InPortal node={fixedPanelNode}>
<div css={fixedPanelCss}>
This is the fixed width panel. It will remain the same size when resizing the window until
the flexible panel reaches its minimum size.
</div>
</InPortal>
<InPortal node={flexPanelNode}>
<div css={flexPanelCss}>
This is the flexible width panel. It will resize as the window resizes until it reaches
its minimum size.
</div>
</InPortal>
<ResizableLayout
mode={layoutMode}
direction={layoutDirection}
container={container}
fixedPanelSize={fixedPanelSize}
minFixedPanelSize={300}
minFlexPanelSize={500}
fixedPanel={<OutPortal node={fixedPanelNode} />}
flexPanel={<OutPortal node={flexPanelNode} />}
onFixedPanelSizeChange={setFixedPanelSize}
/>
</div>
);
};