-
Notifications
You must be signed in to change notification settings - Fork 2k
/
gutenboard.tsx
75 lines (70 loc) · 2.55 KB
/
gutenboard.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
/**
* External dependencies
*/
import '@wordpress/editor'; // This shouldn't be necessary
import { __ as NO__ } from '@wordpress/i18n';
import { BlockEditorProvider, BlockList } from '@wordpress/block-editor';
import { Popover, DropZoneProvider } from '@wordpress/components';
import { createBlock, registerBlockType } from '@wordpress/blocks';
import '@wordpress/format-library';
import React, { useRef } from 'react';
// Uncomment and remove the redundant sass import from `./style.css` when a release after @wordpress/[email protected] is published.
// See https://github.com/WordPress/gutenberg/pull/19535
// import '@wordpress/components/build-style/style.css';
import { useRouteMatch } from 'react-router-dom';
/**
* Internal dependencies
*/
import Header from './components/header';
import { name, settings } from './onboarding-block';
import { routes, Step } from './steps';
import './style.scss';
registerBlockType( name, settings );
export function Gutenboard() {
// @TODO: This is currently needed in addition to the routing (inside the Onboarding Block)
// for the 'Back' and 'Next' buttons in the header. If we remove those (and move navigation
// entirely into the block), we'll be able to remove this code.
const r = useRouteMatch( routes );
let next: undefined | string;
let prev: undefined | string;
switch ( r?.url ) {
case Step.DesignSelection:
prev = Step.IntentGathering;
next = Step.CreateSite;
break;
}
// We're persisting the block via `useRef` in order to prevent re-renders
// which would collide with the routing done inside of the block
// (and would lead to weird mounting/unmounting behavior).
const onboardingBlock = useRef( createBlock( name, {} ) );
/* eslint-disable wpcalypso/jsx-classname-namespace */
return (
<div className="block-editor__container">
<DropZoneProvider>
<div className="edit-post-layout">
<Header prev={ prev } next={ next } />
<BlockEditorProvider
useSubRegistry={ false }
value={ [ onboardingBlock.current ] }
settings={ {
templateLock: 'all',
} }
>
<div className="gutenboard__edit-post-layout-content edit-post-layout__content ">
<div
className="edit-post-visual-editor editor-styles-wrapper"
role="region"
aria-label={ NO__( 'Onboarding screen content' ) }
tabIndex={ -1 }
>
<BlockList className="gutenboarding-block-list" />
</div>
</div>
</BlockEditorProvider>
</div>
</DropZoneProvider>
<Popover.Slot />
</div>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}