UNPKG

@atlaskit/navigation-system

Version:

The latest navigation system for Atlassian apps.

46 lines • 1.96 kB
import React, { useContext } from 'react'; import invariant from 'tiny-invariant'; import { sideNavPanelSplitterId } from '../constants'; import { useToggleSideNav } from '../side-nav/use-toggle-side-nav'; import { OnDoubleClickContext } from './on-double-click-context'; import { PanelSplitter } from './panel-splitter'; import { PanelSplitterContext } from './panel-splitter-context'; /** * _SideNavPanelSplitter_ * * A component that allows the user to resize or collapse the side nav. * It must be used within the `SideNav` layout area. * * Example usage: * ```tsx * <SideNav> * <SideNavPanelSplitter label="Double click to collapse" /> * </SideNav> * ``` */ export var SideNavPanelSplitter = function SideNavPanelSplitter(_ref) { var label = _ref.label, onResizeStart = _ref.onResizeStart, onResizeEnd = _ref.onResizeEnd, testId = _ref.testId, _ref$shouldCollapseOn = _ref.shouldCollapseOnDoubleClick, shouldCollapseOnDoubleClick = _ref$shouldCollapseOn === void 0 ? true : _ref$shouldCollapseOn, tooltipContent = _ref.tooltipContent; var context = useContext(PanelSplitterContext); invariant((context === null || context === void 0 ? void 0 : context.panelId) === sideNavPanelSplitterId, 'SideNavPanelSplitter must be rendered as a child of <SideNav />.'); var toggleSideNav = useToggleSideNav({ trigger: 'double-click' }); return /*#__PURE__*/React.createElement(OnDoubleClickContext.Provider, { value: shouldCollapseOnDoubleClick ? toggleSideNav : undefined }, /*#__PURE__*/React.createElement(PanelSplitter, { label: label, onResizeStart: onResizeStart, onResizeEnd: onResizeEnd, testId: testId, tooltipContent: // Only displaying the tooltip if double click to collapse is enabled. // Otherwise, we would be displaying a tooltip with "Double click to collapse", when it actually won't. shouldCollapseOnDoubleClick ? tooltipContent : undefined })); };