- { ! isFocusMode && ! hasStyleBook && (
+ { ! isFocusMode && hasDefaultEditorCanvasView && (
select( editSiteStore ).getEditorMode(),
- []
+ const { editorMode, editorCanvasView } = useSelect( ( select ) => {
+ return {
+ editorMode: select( editSiteStore ).getEditorMode(),
+ editorCanvasView: unlock(
+ select( editSiteStore )
+ ).getEditorCanvasContainerView(),
+ };
+ }, [] );
+ const { setEditorCanvasContainerView } = unlock(
+ useDispatch( editSiteStore )
);
useEffect( () => {
if ( editorMode !== 'visual' ) {
- setIsStyleBookOpened( false );
+ setEditorCanvasContainerView( undefined );
}
}, [ editorMode ] );
+
+ const isStyleBookOpened = editorCanvasView === 'style-book';
+
return (
{
- setIsStyleBookOpened( ! isStyleBookOpened );
- } }
+ onClick={ () =>
+ setEditorCanvasContainerView(
+ isStyleBookOpened ? undefined : 'style-book'
+ )
+ }
/>
@@ -58,10 +69,7 @@ export default function GlobalStylesSidebar() {
}
>
- setIsStyleBookOpened( false ) }
- />
+
);
}
diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js
index a010f811dcf1d..650f38eea95b9 100644
--- a/packages/edit-site/src/components/style-book/index.js
+++ b/packages/edit-site/src/components/style-book/index.js
@@ -7,14 +7,11 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
- Button,
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
Disabled,
TabPanel,
- createSlotFill,
- __experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import {
@@ -31,29 +28,19 @@ import {
__unstableIframe as Iframe,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
-import { closeSmall } from '@wordpress/icons';
-import {
- useResizeObserver,
- useFocusOnMount,
- useFocusReturn,
- useMergeRefs,
-} from '@wordpress/compose';
+import { useResizeObserver } from '@wordpress/compose';
import { useMemo, memo } from '@wordpress/element';
-import { ESCAPE } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
+import EditorCanvasContainer from '../editor-canvas-container';
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
blockEditorPrivateApis
);
-const SLOT_FILL_NAME = 'EditSiteStyleBook';
-const { Slot: StyleBookSlot, Fill: StyleBookFill } =
- createSlotFill( SLOT_FILL_NAME );
-
// The content area of the Style Book is rendered within an iframe so that global styles
// are applied to elements within the entire content area. To support elements that are
// not part of the block previews, such as headings and layout for the block previews,
@@ -174,11 +161,8 @@ function getExamples() {
return [ headingsExample, ...otherExamples ];
}
-function StyleBook( { isSelected, onSelect, onClose } ) {
+function StyleBook( { isSelected, onSelect } ) {
const [ resizeObserver, sizes ] = useResizeObserver();
- const focusOnMountRef = useFocusOnMount( 'firstElement' );
- const sectionFocusReturnRef = useFocusReturn();
-
const [ textColor ] = useGlobalStyle( 'color.text' );
const [ backgroundColor ] = useGlobalStyle( 'color.background' );
const examples = useMemo( getExamples, [] );
@@ -207,17 +191,9 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
[ originalSettings ]
);
- function closeOnEscape( event ) {
- if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
- event.preventDefault();
- onClose();
- }
- }
-
return (
-
- { /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
-
+ 600,
} ) }
@@ -225,21 +201,8 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
color: textColor,
background: backgroundColor,
} }
- aria-label={ __( 'Style Book' ) }
- onKeyDown={ closeOnEscape }
- ref={ useMergeRefs( [
- sectionFocusReturnRef,
- focusOnMountRef,
- ] ) }
>
{ resizeObserver }
-
) }
-
-
+
+
);
}
@@ -365,11 +328,4 @@ const Example = ( { composite, id, title, blocks, isSelected, onClick } ) => {
);
};
-function useHasStyleBook() {
- const fills = useSlotFills( SLOT_FILL_NAME );
- return !! fills?.length;
-}
-
-StyleBook.Slot = StyleBookSlot;
export default StyleBook;
-export { useHasStyleBook };
diff --git a/packages/edit-site/src/components/style-book/style.scss b/packages/edit-site/src/components/style-book/style.scss
index cf84655258725..6dcc1fec328ab 100644
--- a/packages/edit-site/src/components/style-book/style.scss
+++ b/packages/edit-site/src/components/style-book/style.scss
@@ -1,21 +1,3 @@
-.edit-site-style-book {
- background: $white; // Fallback color, overridden by JavaScript.
- border-radius: $radius-block-ui;
- bottom: 0;
- left: 0;
- overflow: hidden;
- position: absolute;
- right: 0;
- top: 0;
- transition: all 0.3s; // Match .block-editor-iframe__body transition.
-}
-
-.edit-site-style-book__close-button {
- position: absolute;
- right: $grid-unit-10;
- top: math.div($grid-unit-60 - $button-size, 2); // ( tab height - button size ) / 2
-}
-
.edit-site-style-book__tab-panel {
.components-tab-panel__tabs {
background: $white;
diff --git a/packages/edit-site/src/store/private-actions.js b/packages/edit-site/src/store/private-actions.js
index aeaf1d72833d7..952c1852ae305 100644
--- a/packages/edit-site/src/store/private-actions.js
+++ b/packages/edit-site/src/store/private-actions.js
@@ -27,3 +27,17 @@ export const setCanvasMode =
dispatch.setIsListViewOpened( true );
}
};
+
+/**
+ * Action that switches the editor canvas container view.
+ *
+ * @param {?string} view Editor canvas container view.
+ */
+export const setEditorCanvasContainerView =
+ ( view ) =>
+ ( { dispatch } ) => {
+ dispatch( {
+ type: 'SET_EDITOR_CANVAS_CONTAINER_VIEW',
+ view,
+ } );
+ };
diff --git a/packages/edit-site/src/store/private-selectors.js b/packages/edit-site/src/store/private-selectors.js
index fa4085d17f89c..1f1f6e999fdb2 100644
--- a/packages/edit-site/src/store/private-selectors.js
+++ b/packages/edit-site/src/store/private-selectors.js
@@ -8,3 +8,14 @@
export function getCanvasMode( state ) {
return state.canvasMode;
}
+
+/**
+ * Returns the editor canvas container view.
+ *
+ * @param {Object} state Global application state.
+ *
+ * @return {string} Editor canvas container view.
+ */
+export function getEditorCanvasContainerView( state ) {
+ return state.editorCanvasContainerView;
+}
diff --git a/packages/edit-site/src/store/reducer.js b/packages/edit-site/src/store/reducer.js
index fee3a8fcc5618..a46d215f90507 100644
--- a/packages/edit-site/src/store/reducer.js
+++ b/packages/edit-site/src/store/reducer.js
@@ -140,6 +140,23 @@ function canvasMode( state = 'init', action ) {
return state;
}
+/**
+ * Reducer used to track the site editor canvas container view.
+ * Default is `undefined`, denoting the default, visual block editor.
+ * This could be, for example, `'style-book'` (the style book).
+ *
+ * @param {string|undefined} state Current state.
+ * @param {Object} action Dispatched action.
+ */
+function editorCanvasContainerView( state = undefined, action ) {
+ switch ( action.type ) {
+ case 'SET_EDITOR_CANVAS_CONTAINER_VIEW':
+ return action.view;
+ }
+
+ return state;
+}
+
export default combineReducers( {
deviceType,
settings,
@@ -148,4 +165,5 @@ export default combineReducers( {
listViewPanel,
saveViewPanel,
canvasMode,
+ editorCanvasContainerView,
} );
diff --git a/packages/edit-site/src/style.scss b/packages/edit-site/src/style.scss
index a68971f901157..30abf4057b80e 100644
--- a/packages/edit-site/src/style.scss
+++ b/packages/edit-site/src/style.scss
@@ -31,6 +31,7 @@
@import "./components/sidebar-navigation-screen-navigation-menus/style.scss";
@import "./components/site-icon/style.scss";
@import "./components/style-book/style.scss";
+@import "./components/editor-canvas-container/style.scss";
@import "./hooks/push-changes-to-global-styles/style.scss";
html #wpadminbar {