Add header with “pinned items”
I only wanted to have a button to open and close the sidebar, like “regular” site editor does in WordPress. Apparently, this is done via a “pinned” slot/fill thing, that make the visibility of that button a user decision, by default—WordPress removes the pin button to avoid that. The thing is that it does not work: ComplementaryArea adds a ComplementaryAreaToggle in the PinnedItems fill, and that toggle is a button-like compenent that calls enableComplementaryArea or disableComplementaryArea on the interface store, however disableComplementaryArea does **not** update the interface store, instead updates preferences, meaning that the useSelect inside the toggle, that only subscribes to the interface store, is never called when the area is disabled, and can not be enabled again with that toggle button. I worked around the issue by adding dispatch({ type: 'ENABLE_COMPLEMENTARY_AREA', scope, area: undefined }); at the end of disableComplementaryArea. I suspect this is not the proper solution, and that there must be another way, because WordPress does not exhibit that behaviour, however it signals that there _is_ an error in the library, but i could not find any bug report within the 5k+ issues currently reported to Gutenberg’s project. For now, it will do.
This commit is contained in:
parent
fadb56f06b
commit
7e0b57c2e4
|
@ -2,6 +2,7 @@ import { useSelect } from '@wordpress/data';
|
||||||
import { InterfaceSkeleton, FullscreenMode, ComplementaryArea } from '@wordpress/interface';
|
import { InterfaceSkeleton, FullscreenMode, ComplementaryArea } from '@wordpress/interface';
|
||||||
import { BlockBreadcrumb, BlockCanvas, store as blockEditorStore } from '@wordpress/block-editor';
|
import { BlockBreadcrumb, BlockCanvas, store as blockEditorStore } from '@wordpress/block-editor';
|
||||||
|
|
||||||
|
import Header from './Header';
|
||||||
import Sidebar from './Sidebar';
|
import Sidebar from './Sidebar';
|
||||||
import { scope } from './constants';
|
import { scope } from './constants';
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ export default function BlockEditor() {
|
||||||
<FullscreenMode isActive={ true } />
|
<FullscreenMode isActive={ true } />
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<InterfaceSkeleton
|
<InterfaceSkeleton
|
||||||
|
header={ <Header /> }
|
||||||
content={ <BlockCanvas height="100%" styles={styles} /> }
|
content={ <BlockCanvas height="100%" styles={styles} /> }
|
||||||
sidebar={ <ComplementaryArea.Slot scope={ scope } /> }
|
sidebar={ <ComplementaryArea.Slot scope={ scope } /> }
|
||||||
footer={ <BlockBreadcrumb /> }
|
footer={ <BlockBreadcrumb /> }
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { PinnedItems } from '@wordpress/interface';
|
||||||
|
|
||||||
|
import { scope } from './constants';
|
||||||
|
|
||||||
|
export default function Header() {
|
||||||
|
return (
|
||||||
|
<div className="tipus-header">
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
<div className="tipus-header__settings">
|
||||||
|
<PinnedItems.Slot scope={ scope } />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -15,3 +15,19 @@ main {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tipus-header {
|
||||||
|
height: 3.75rem;
|
||||||
|
background: white;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
max-width: 100vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tipus-header__settings {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: .5rem;
|
||||||
|
padding-right: .5rem;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue