UNPKG

@atlaskit/navigation-system

Version:

The latest navigation system for Atlassian apps.

27 lines (26 loc) • 1.16 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 const useSideNavVisibility = ({ defaultCollapsed = false } = {}) => { const 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' }; };