// Reference: https://github.com/WordPress/gutenberg/blob/v16.4.0/packages/edit-site/src/components/sidebar-navigation-screen/index.js
/* eslint-disable @woocommerce/dependency-group */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* External dependencies
*/
import classnames from 'classnames';
import { useContext, useState } from '@wordpress/element';
import {
// @ts-ignore No types for this exist yet.
__experimentalHStack as HStack,
// @ts-ignore No types for this exist yet.
__experimentalHeading as Heading,
// @ts-ignore No types for this exist yet.
__experimentalUseNavigator as useNavigator,
// @ts-ignore No types for this exist yet.
__experimentalVStack as VStack,
} from '@wordpress/components';
import { isRTL, __ } from '@wordpress/i18n';
import { chevronRight, chevronLeft } from '@wordpress/icons';
// @ts-ignore No types for this exist yet.
import { privateApis as routerPrivateApis } from '@wordpress/router';
// @ts-ignore No types for this exist yet.
import { unlock } from '@wordpress/edit-site/build-module/lock-unlock';
// @ts-ignore No types for this exist yet.
import SidebarButton from '@wordpress/edit-site/build-module/components/sidebar-button';
import { GoBackWarningModal } from './go-back-warning-modal';
/**
* Internal dependencies
*/
import { CustomizeStoreContext } from '../';
const { useLocation } = unlock( routerPrivateApis );
export const SidebarNavigationScreen = ( {
isRoot,
title,
actions,
meta,
content,
footer,
description,
backPath: backPathProp,
onNavigateBackClick,
}: {
isRoot?: boolean;
title: string;
actions?: React.ReactNode;
meta?: React.ReactNode;
content: React.ReactNode;
footer?: React.ReactNode;
description?: React.ReactNode;
backPath?: string;
onNavigateBackClick?: () => void;
} ) => {
const { sendEvent } = useContext( CustomizeStoreContext );
const [ openWarningModal, setOpenWarningModal ] =
useState< boolean >( false );
const location = useLocation();
const navigator = useNavigator();
const icon = isRTL() ? chevronRight : chevronLeft;
return (
<>
{ ! isRoot && (
{
onNavigateBackClick?.();
const backPath =
backPathProp ?? location.state?.backPath;
if ( backPath ) {
navigator.goTo( backPath, {
isBack: true,
} );
} else {
navigator.goToParent();
}
} }
icon={ icon }
label={ __( 'Back', 'woocommerce' ) }
showTooltip={ false }
/>
) }
{ isRoot && (
{
setOpenWarningModal( true );
} }
icon={ icon }
label={ __( 'Back', 'woocommerce' ) }
showTooltip={ false }
/>
) }
{ title }
{ actions && (
{ actions }
) }
{ meta && (
<>
{ meta }
>
) }
{ description && (
{ description }
) }
{ content }
{ footer && (
) }
{ openWarningModal && (
) }
>
);
};