-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
sidebar-navigation-screen.tsx
161 lines (157 loc) · 4.29 KB
/
sidebar-navigation-screen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 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 '../';
import { isAIFlow } from '~/customize-store/guards';
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 { context } = useContext( CustomizeStoreContext );
const [ openWarningModal, setOpenWarningModal ] =
useState< boolean >( false );
const location = useLocation();
const navigator = useNavigator();
const icon = isRTL() ? chevronRight : chevronLeft;
const flowType = context?.flowType;
return (
<>
<VStack
className={ classnames(
'edit-site-sidebar-navigation-screen__main',
{
'has-footer': !! footer,
}
) }
spacing={ 0 }
justify="flex-start"
>
<HStack
spacing={ 4 }
alignment="flex-start"
className="edit-site-sidebar-navigation-screen__title-icon"
>
{ ! isRoot && (
<SidebarButton
onClick={ () => {
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 && (
<SidebarButton
onClick={ () => {
setOpenWarningModal( true );
} }
icon={ icon }
label={ __( 'Back', 'woocommerce' ) }
showTooltip={ false }
/>
) }
<Heading
className="edit-site-sidebar-navigation-screen__title"
color={ '#e0e0e0' /* $gray-200 */ }
level={ 1 }
size={ 20 }
>
{ title }
</Heading>
{ actions && (
<div className="edit-site-sidebar-navigation-screen__actions">
{ actions }
</div>
) }
</HStack>
{ meta && (
<>
<div className="edit-site-sidebar-navigation-screen__meta">
{ meta }
</div>
</>
) }
<div className="edit-site-sidebar-navigation-screen__content">
{ description && (
<p className="edit-site-sidebar-navigation-screen__description">
{ description }
</p>
) }
{ content }
</div>
</VStack>
{ footer && (
<footer className="edit-site-sidebar-navigation-screen__footer">
{ footer }
</footer>
) }
{ openWarningModal && (
<GoBackWarningModal
setOpenWarningModal={ setOpenWarningModal }
onExitClicked={ () => {
window.parent.__wcCustomizeStore.sendEventToIntroMachine(
flowType && isAIFlow( flowType )
? { type: 'GO_BACK_TO_DESIGN_WITH_AI' }
: { type: 'GO_BACK_TO_DESIGN_WITHOUT_AI' }
);
} }
/>
) }
</>
);
};