Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the inserter panel for the edit-site screen #22413

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import {
BlockBreadcrumb,
__unstableEditorStyles as EditorStyles,
__experimentalUseResizeCanvas as useResizeCanvas,
__experimentalLibrary as Library,
} from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
import { FullscreenMode, InterfaceSkeleton } from '@wordpress/interface';
import { EntitiesSavedStates } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { PluginArea } from '@wordpress/plugins';
import { close } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -44,7 +46,12 @@ export function useEditorContext() {
return useContext( Context );
}

const interfaceLabels = {
leftSidebar: __( 'Block Library' ),
};

function Editor( { settings: _settings } ) {
const [ isInserterOpen, setIsInserterOpen ] = useState( false );
const isMobile = useViewportMatch( 'medium', '<' );
const [ settings, setSettings ] = useState( _settings );
const template = useSelect(
Expand Down Expand Up @@ -131,6 +138,37 @@ function Editor( { settings: _settings } ) {
<FocusReturnProvider>
<KeyboardShortcuts.Register />
<InterfaceSkeleton
labels={ interfaceLabels }
leftSidebar={
isInserterOpen && (
<div className="edit-site-editor__inserter-panel">
<div className="edit-site-editor__inserter-panel-header">
<Button
icon={ close }
onClick={ () =>
setIsInserterOpen(
false
)
}
/>
</div>
<div className="edit-site-editor__inserter-panel-content">
<Library
showInserterHelpPanel
onSelect={ () => {
if (
isMobile
) {
setIsInserterOpen(
false
);
}
} }
/>
</div>
</div>
)
}
sidebar={
! isMobile && <Sidebar />
}
Expand All @@ -139,6 +177,14 @@ function Editor( { settings: _settings } ) {
openEntitiesSavedStates={
openEntitiesSavedStates
}
isInserterOpen={
isInserterOpen
}
onToggleInserter={ () =>
setIsInserterOpen(
! isInserterOpen
)
}
/>
}
content={
Expand Down
26 changes: 26 additions & 0 deletions packages/edit-site/src/components/editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@
.edit-site-visual-editor {
background-color: $white;
}

.edit-site-editor__inserter-panel {
height: 100%;
display: flex;
flex-direction: column;
}

.edit-site-editor__inserter-panel-header {
padding-top: $grid-unit-10;
padding-right: $grid-unit-10;
display: flex;
justify-content: flex-end;

@include break-medium() {
display: none;
}
}

.edit-site-editor__inserter-panel-content {
// Leave space for the close button
height: calc(100% - #{$button-size} - #{$grid-unit-10});

@include break-medium() {
height: 100%;
}
}
25 changes: 17 additions & 8 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { addQueryArgs } from '@wordpress/url';
import {
BlockNavigationDropdown,
ToolSelector,
Inserter,
__experimentalPreviewOptions as PreviewOptions,
} from '@wordpress/block-editor';
import {
Expand All @@ -18,6 +17,9 @@ import {
PinnedItems,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/interface';
import { _x } from '@wordpress/i18n';
import { plus } from '@wordpress/icons';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -36,9 +38,11 @@ import FullscreenModeClose from './fullscreen-mode-close';
*/
const { fetch } = window;

const inserterToggleProps = { isPrimary: true };

export default function Header( { openEntitiesSavedStates } ) {
export default function Header( {
openEntitiesSavedStates,
isInserterOpen,
onToggleInserter,
} ) {
const { settings, setSettings } = useEditorContext();
const setActiveTemplateId = useCallback(
( newTemplateId ) =>
Expand Down Expand Up @@ -109,10 +113,15 @@ export default function Header( { openEntitiesSavedStates } ) {
<FullscreenModeClose />
</MainDashboardButton.Slot>
<div className="edit-site-header__toolbar">
<Inserter
position="bottom right"
showInserterHelpPanel
toggleProps={ inserterToggleProps }
<Button
isPrimary
isPressed={ isInserterOpen }
onClick={ onToggleInserter }
icon={ plus }
label={ _x(
'Add block',
'Generic label for block inserter button'
) }
/>
<ToolSelector />
<UndoButton />
Expand Down