UNPKG

@atlaskit/navigation-system

Version:

The latest navigation system for Atlassian apps.

28 lines (27 loc) • 1.37 kB
import { useContext } from 'react'; import { SideNavVisibilityState } from './side-nav-visibility-state'; /** * This hook is intended to be used internally within the `@atlaskit/navigation-system` package. * * It handles using whether to use the desktop visibility state from _context_, or the _defaultCollapsed_ arg (which comes * from component props) - based on whether the context has been set yet. In SSR / initial render, the context would not have been * set yet, so we need to use the _defaultCollapsed_ argument value instead. */ export var useSideNavVisibility = function useSideNavVisibility() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$defaultCollapsed = _ref.defaultCollapsed, defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed; var sideNavState = useContext(SideNavVisibilityState); // If the context value is `null`, it means we are still in SSR, and should use the default values. // For desktop, it comes from the `defaultCollapsed` prop, and for mobile, it is always `false`. if (sideNavState === null) { return { isExpandedOnDesktop: !defaultCollapsed, isExpandedOnMobile: false }; } return { isExpandedOnDesktop: sideNavState.desktop === 'expanded', isExpandedOnMobile: sideNavState.mobile === 'expanded' }; };