@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
50 lines • 2.25 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 var PanelSplitterProvider = function PanelSplitterProvider(_ref) {
var panelId = _ref.panelId,
panelWidth = _ref.panelWidth,
onCompleteResize = _ref.onCompleteResize,
onResizeStartInternal = _ref.onResizeStartInternal,
onResizeInternal = _ref.onResizeInternal,
prepareResize = _ref.prepareResize,
getResizeBounds = _ref.getResizeBounds,
resizingCssVar = _ref.resizingCssVar,
panelRef = _ref.panelRef,
resizingElementRef = _ref.resizingElementRef,
providedPortalRef = _ref.portalRef,
_ref$position = _ref.position,
position = _ref$position === void 0 ? 'end' : _ref$position,
_ref$isEnabled = _ref.isEnabled,
isEnabled = _ref$isEnabled === void 0 ? true : _ref$isEnabled,
shortcut = _ref.shortcut,
children = _ref.children;
var portalRef = useRef(null);
var context = useMemo(function () {
return {
panelId: panelId,
panelWidth: panelWidth,
onCompleteResize: onCompleteResize,
onResizeStartInternal: onResizeStartInternal,
onResizeInternal: onResizeInternal,
prepareResize: prepareResize,
getResizeBounds: getResizeBounds,
resizingCssVar: resizingCssVar,
position: position,
panelRef: panelRef,
resizingElementRef: resizingElementRef,
isEnabled: isEnabled,
portalRef: typeof providedPortalRef !== 'undefined' ? providedPortalRef : portalRef,
shortcut: 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
}));
};