/** * External dependencies */ // eslint-disable-next-line no-restricted-imports import type { Ref } from 'react'; import { css } from '@emotion/react'; /** * GeChiUI dependencies */ import { useMemo, useState } from '@gechiui/element'; /** * Internal dependencies */ import { contextConnect, useContextSystem, GeChiUIComponentProps, } from '../../ui/context'; import { useCx } from '../../utils/hooks/use-cx'; import { View } from '../../view'; import { NavigatorContext } from '../context'; import type { NavigatorProviderProps, NavigatorPath } from '../types'; function NavigatorProvider( props: GeChiUIComponentProps< NavigatorProviderProps, 'div' >, forwardedRef: Ref< any > ) { const { initialPath, children, className, ...otherProps } = useContextSystem( props, 'NavigatorProvider' ); const [ path, setPath ] = useState< NavigatorPath >( { path: initialPath, } ); const cx = useCx(); const classes = useMemo( // Prevents horizontal overflow while animating screen transitions () => cx( css( { overflowX: 'hidden' } ), className ), [ className ] ); return ( { children } ); } /** * The `NavigatorProvider` component allows rendering nested panels or menus (via the `NavigatorScreen` component) and navigate between these different states (via the `useNavigator` hook). * The Global Styles sidebar is an example of this. The `Navigator*` family of components is _not_ opinionated in terms of UI, and can be composed with any UI components to navigate between the nested screens. * * @example * ```jsx * import { * __experimentalNavigatorProvider as NavigatorProvider, * __experimentalNavigatorScreen as NavigatorScreen, * __experimentalUseNavigator as useNavigator, * } from '@gechiui/components'; * * function NavigatorButton( { * path, * isBack = false, * ...props * } ) { * const navigator = useNavigator(); * return ( * navigator.push( path, { isBack } ) } * { ...props } * /> * ); * } * * const MyNavigation = () => ( * * * This is the home screen. * * Navigate to child screen. * * * * * This is the child screen. * * Go back * * * * ); * ``` */ const ConnectedNavigatorProvider = contextConnect( NavigatorProvider, 'NavigatorProvider' ); export default ConnectedNavigatorProvider;
This is the home screen.
This is the child screen.