4
4
import { useState } from '@wordpress/element' ;
5
5
import { registerPlugin } from '@wordpress/plugins' ;
6
6
import { PluginSidebar , PluginSidebarMoreMenuItem } from '@wordpress/editor' ;
7
- import { __ , _x } from '@wordpress/i18n' ;
7
+ import { __ , _x , isRTL } from '@wordpress/i18n' ;
8
8
import { useDispatch } from '@wordpress/data' ;
9
9
import { store as noticesStore } from '@wordpress/notices' ;
10
10
import {
11
11
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
12
12
__experimentalVStack as VStack ,
13
13
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
14
- __experimentalSpacer as Spacer ,
15
- // eslint-disable-next-line @wordpress/no-unsafe-wp-apis
16
14
__experimentalNavigatorProvider as NavigatorProvider ,
17
15
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
18
16
__experimentalNavigatorScreen as NavigatorScreen ,
@@ -24,6 +22,7 @@ import {
24
22
__experimentalText as Text ,
25
23
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
26
24
__experimentalDivider as Divider ,
25
+ // eslint-disable-next-line @wordpress/no-unsafe-wp-apis
27
26
Button ,
28
27
Icon ,
29
28
FlexItem ,
@@ -35,6 +34,7 @@ import {
35
34
download ,
36
35
edit ,
37
36
code ,
37
+ chevronLeft ,
38
38
chevronRight ,
39
39
addCard ,
40
40
blockMeta ,
@@ -58,6 +58,23 @@ import AboutPlugin from './editor-sidebar/about';
58
58
import ResetTheme from './editor-sidebar/reset-theme' ;
59
59
import './plugin-styles.scss' ;
60
60
61
+ function PluginSidebarItem ( { icon, path, children, ...props } ) {
62
+ const ItemWrapper = path ? NavigatorButton : Button ;
63
+ return (
64
+ < ItemWrapper { ...props } path = { path } >
65
+ < HStack justify = "flex-start" >
66
+ < HStack justify = "flex-start" >
67
+ < Icon icon = { icon } />
68
+ < FlexItem > { children } </ FlexItem >
69
+ </ HStack >
70
+ { path && (
71
+ < Icon icon = { isRTL ( ) ? chevronLeft : chevronRight } />
72
+ ) }
73
+ </ HStack >
74
+ </ ItemWrapper >
75
+ ) ;
76
+ }
77
+
61
78
const CreateBlockThemePlugin = ( ) => {
62
79
const [ isEditorOpen , setIsEditorOpen ] = useState ( false ) ;
63
80
const [ isGlobalStylesEditorOpen , setIsGlobalStylesEditorOpen ] =
@@ -111,34 +128,22 @@ const CreateBlockThemePlugin = () => {
111
128
< NavigatorScreen path = "/" >
112
129
< PanelBody >
113
130
< VStack spacing = { 0 } >
114
- < NavigatorButton path = "/save" icon = { copy } >
115
- < Spacer />
116
- < HStack >
117
- < FlexItem >
118
- { __ (
119
- 'Save Changes to Theme' ,
120
- 'create-block-theme'
121
- ) }
122
- </ FlexItem >
123
- < Icon icon = { chevronRight } />
124
- </ HStack >
125
- </ NavigatorButton >
126
- < NavigatorButton
131
+ < PluginSidebarItem path = "/save" icon = { copy } >
132
+ { __ (
133
+ 'Save Changes to Theme' ,
134
+ 'create-block-theme'
135
+ ) }
136
+ </ PluginSidebarItem >
137
+ < PluginSidebarItem
127
138
path = "/create/variation"
128
139
icon = { blockMeta }
129
140
>
130
- < Spacer />
131
- < HStack >
132
- < FlexItem >
133
- { __ (
134
- 'Create Theme Variation' ,
135
- 'create-block-theme'
136
- ) }
137
- </ FlexItem >
138
- < Icon icon = { chevronRight } />
139
- </ HStack >
140
- </ NavigatorButton >
141
- < Button
141
+ { __ (
142
+ 'Create Theme Variation' ,
143
+ 'create-block-theme'
144
+ ) }
145
+ </ PluginSidebarItem >
146
+ < PluginSidebarItem
142
147
icon = { edit }
143
148
onClick = { ( ) =>
144
149
setIsMetadataEditorOpen ( true )
@@ -148,17 +153,17 @@ const CreateBlockThemePlugin = () => {
148
153
'Edit Theme Metadata' ,
149
154
'create-block-theme'
150
155
) }
151
- </ Button >
152
- < Button
156
+ </ PluginSidebarItem >
157
+ < PluginSidebarItem
153
158
icon = { code }
154
159
onClick = { ( ) => setIsEditorOpen ( true ) }
155
160
>
156
161
{ __ (
157
162
'View theme.json' ,
158
163
'create-block-theme'
159
164
) }
160
- </ Button >
161
- < Button
165
+ </ PluginSidebarItem >
166
+ < PluginSidebarItem
162
167
icon = { code }
163
168
onClick = { ( ) =>
164
169
setIsGlobalStylesEditorOpen ( true )
@@ -168,76 +173,44 @@ const CreateBlockThemePlugin = () => {
168
173
'View Custom Styles' ,
169
174
'create-block-theme'
170
175
) }
171
- </ Button >
172
- < Button
176
+ </ PluginSidebarItem >
177
+ < PluginSidebarItem
173
178
icon = { download }
174
179
onClick = { ( ) => handleExportClick ( ) }
175
180
>
176
181
{ __ ( 'Export Zip' , 'create-block-theme' ) }
177
- </ Button >
182
+ </ PluginSidebarItem >
178
183
< Divider />
179
- < NavigatorButton
184
+ < PluginSidebarItem
180
185
path = "/create/blank"
181
186
icon = { addCard }
182
187
>
183
- < Spacer />
184
- < HStack >
185
- < FlexItem >
186
- { __ (
187
- 'Create Blank Theme' ,
188
- 'create-block-theme'
189
- ) }
190
- </ FlexItem >
191
- < Icon icon = { chevronRight } />
192
- </ HStack >
193
- </ NavigatorButton >
194
- < NavigatorButton path = "/clone" icon = { copy } >
195
- < Spacer />
196
- < HStack >
197
- < FlexItem >
198
- { __ (
199
- 'Create Theme' ,
200
- 'create-block-theme'
201
- ) }
202
- </ FlexItem >
203
- < Icon icon = { chevronRight } />
204
- </ HStack >
205
- </ NavigatorButton >
188
+ { __ (
189
+ 'Create Blank Theme' ,
190
+ 'create-block-theme'
191
+ ) }
192
+ </ PluginSidebarItem >
193
+ < PluginSidebarItem path = "/clone" icon = { copy } >
194
+ { __ (
195
+ 'Create Theme' ,
196
+ 'create-block-theme'
197
+ ) }
198
+ </ PluginSidebarItem >
206
199
207
200
< Divider />
208
201
209
- < NavigatorButton path = "/reset" icon = { trash } >
210
- < Spacer />
211
- < HStack >
212
- < FlexItem >
213
- { __ (
214
- 'Reset Theme' ,
215
- 'create-block-theme'
216
- ) }
217
- </ FlexItem >
218
- < Icon icon = { chevronRight } />
219
- </ HStack >
220
- </ NavigatorButton >
202
+ < PluginSidebarItem path = "/reset" icon = { trash } >
203
+ { __ (
204
+ 'Reset Theme' ,
205
+ 'create-block-theme'
206
+ ) }
207
+ </ PluginSidebarItem >
221
208
222
209
< Divider />
223
210
224
- < NavigatorButton
225
- path = "/about"
226
- icon = { help }
227
- className = {
228
- 'create-block-theme__plugin-sidebar__about-button'
229
- }
230
- >
231
- < Spacer />
232
- < HStack >
233
- < FlexItem >
234
- { __ (
235
- 'Help' ,
236
- 'create-block-theme'
237
- ) }
238
- </ FlexItem >
239
- </ HStack >
240
- </ NavigatorButton >
211
+ < PluginSidebarItem path = "/about" icon = { help } >
212
+ { __ ( 'Help' , 'create-block-theme' ) }
213
+ </ PluginSidebarItem >
241
214
</ VStack >
242
215
</ PanelBody >
243
216
</ NavigatorScreen >
@@ -258,49 +231,37 @@ const CreateBlockThemePlugin = () => {
258
231
) }
259
232
</ Text >
260
233
< Divider />
261
- < NavigatorButton
234
+ < PluginSidebarItem
262
235
path = "/clone/create"
263
236
icon = { copy }
264
237
onClick = { ( ) => {
265
238
setCloneCreateType ( 'createClone' ) ;
266
239
} }
267
240
>
268
- < Spacer />
269
- < HStack >
270
- < FlexItem >
271
- { __ (
272
- 'Clone Theme' ,
273
- 'create-block-theme'
274
- ) }
275
- </ FlexItem >
276
- < Icon icon = { chevronRight } />
277
- </ HStack >
278
- </ NavigatorButton >
241
+ { __ (
242
+ 'Clone Theme' ,
243
+ 'create-block-theme'
244
+ ) }
245
+ </ PluginSidebarItem >
279
246
< Text variant = "muted" >
280
247
{ __ (
281
248
'Create a clone of this theme with a new name. The user changes will be preserved in the new theme.' ,
282
249
'create-block-theme'
283
250
) }
284
251
</ Text >
285
252
< Divider />
286
- < NavigatorButton
253
+ < PluginSidebarItem
287
254
path = "/clone/create"
288
255
icon = { copy }
289
256
onClick = { ( ) => {
290
257
setCloneCreateType ( 'createChild' ) ;
291
258
} }
292
259
>
293
- < Spacer />
294
- < HStack >
295
- < FlexItem >
296
- { __ (
297
- 'Create Child Theme' ,
298
- 'create-block-theme'
299
- ) }
300
- </ FlexItem >
301
- < Icon icon = { chevronRight } />
302
- </ HStack >
303
- </ NavigatorButton >
260
+ { __ (
261
+ 'Create Child Theme' ,
262
+ 'create-block-theme'
263
+ ) }
264
+ </ PluginSidebarItem >
304
265
< Text variant = "muted" >
305
266
{ __ (
306
267
'Create a child theme that uses this theme as a parent. This theme will remain unchanged and the user changes will be preserved in the new child theme.' ,
0 commit comments