@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
47 lines • 1.54 kB
JavaScript
import React, { Fragment, useMemo, useRef } from 'react';
import { PanelSplitterContext } from './panel-splitter-context';
/**
* Provides the context required for the panel splitter to work within a page layout slot.
*
* Should be used in the layout area components, e.g. SideNav, Aside etc, as opposed to products.
*/
export const PanelSplitterProvider = ({
panelId,
panelWidth,
onCompleteResize,
onResizeStartInternal,
onResizeInternal,
prepareResize,
getResizeBounds,
resizingCssVar,
panelRef,
resizingElementRef,
portalRef: providedPortalRef,
position = 'end',
isEnabled = true,
shortcut,
children
}) => {
const portalRef = useRef(null);
const context = useMemo(() => ({
panelId,
panelWidth,
onCompleteResize,
onResizeStartInternal,
onResizeInternal,
prepareResize,
getResizeBounds,
resizingCssVar,
position,
panelRef,
resizingElementRef,
isEnabled,
portalRef: typeof providedPortalRef !== 'undefined' ? providedPortalRef : portalRef,
shortcut
}), [panelId, panelWidth, onCompleteResize, onResizeStartInternal, onResizeInternal, prepareResize, getResizeBounds, resizingCssVar, position, panelRef, resizingElementRef, isEnabled, providedPortalRef, shortcut]);
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(PanelSplitterContext.Provider, {
value: context
}, children), typeof providedPortalRef !== 'undefined' ? null : /*#__PURE__*/React.createElement("div", {
ref: portalRef
}));
};