UNPKG

@atlaskit/page-layout

Version:

A collection of components which let you compose an application's page layout.

69 lines (67 loc) 3 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["setLeftSidebarState"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { createContext, useContext, useEffect } from 'react'; import noop from '@atlaskit/ds-lib/noop'; var leftSidebarState = { isFlyoutOpen: false, isResizing: false, isLeftSidebarCollapsed: false, leftSidebarWidth: 0, lastLeftSidebarWidth: 0, flyoutLockCount: 0, isFixed: true, hasInit: false }; // eslint-disable-next-line @repo/internal/react/require-jsdoc export var SidebarResizeContext = /*#__PURE__*/createContext({ isLeftSidebarCollapsed: false, expandLeftSidebar: noop, collapseLeftSidebar: noop, leftSidebarState: leftSidebarState, setLeftSidebarState: noop, toggleLeftSidebar: noop }); export var usePageLayoutResize = function usePageLayoutResize() { var _useContext = useContext(SidebarResizeContext), setLeftSidebarState = _useContext.setLeftSidebarState, context = _objectWithoutProperties(_useContext, _excluded); return context; }; /** * _**WARNING:**_ This hook is intended as a temporary solution and * is likely to be removed in a future version of page-layout. * * --- * * This hook will prevent the left sidebar from automatically collapsing * when it is in a flyout state. * * The intended use case for this hook is to allow popup menus in the * left sidebar to be usable while it is in a flyout state. * * ## Usage * The intended usage is to use this hook within the popup component * you are rendering. This way the left sidebar will be locked for * as long as the popup is open. */ export var useLeftSidebarFlyoutLock = function useLeftSidebarFlyoutLock() { var _useContext2 = useContext(SidebarResizeContext), setLeftSidebarState = _useContext2.setLeftSidebarState; useEffect(function () { setLeftSidebarState(function (current) { return _objectSpread(_objectSpread({}, current), {}, { flyoutLockCount: current.flyoutLockCount + 1 }); }); return function () { setLeftSidebarState(function (current) { return _objectSpread(_objectSpread({}, current), {}, { flyoutLockCount: current.flyoutLockCount - 1 }); }); }; }, [setLeftSidebarState]); };