Skip to content

Commit

Permalink
Edit Post: Add basic support for sidebar pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 26, 2018
1 parent 7b766c2 commit 80b02c8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 deletions.
20 changes: 12 additions & 8 deletions edit-post/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { compose } from '@wordpress/element';
import './style.scss';
import MoreMenu from './more-menu';
import HeaderToolbar from './header-toolbar';
import PinnedPlugins from './pinned-plugins';

function Header( {
isEditorSidebarOpened,
Expand Down Expand Up @@ -50,14 +51,17 @@ function Header( {
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
/>
<IconButton
icon="admin-generic"
onClick={ toggleGeneralSidebar }
isToggled={ isEditorSidebarOpened }
label={ __( 'Settings' ) }
aria-expanded={ isEditorSidebarOpened }
/>
<MoreMenu key="more-menu" />
<PinnedPlugins>
<IconButton
icon="admin-generic"
onClick={ toggleGeneralSidebar }
isToggled={ isEditorSidebarOpened }
label={ __( 'Settings' ) }
aria-expanded={ isEditorSidebarOpened }
/>
</PinnedPlugins>
<PinnedPlugins.Slot />
<MoreMenu />
</div>
) }
</div>
Expand Down
28 changes: 28 additions & 0 deletions edit-post/components/header/pinned-plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import './style.scss';

const { Fill: PinnedPlugins, Slot } = createSlotFill( 'PinnedPlugins' );

PinnedPlugins.Slot = ( { fillProps } ) => (
<Slot fillProps={ fillProps }>
{ ( fills ) => ! isEmpty( fills ) && (
<div className="edit-post-pinned-plugins">
{ fills }
</div>
) }
</Slot>
);

export default PinnedPlugins;
3 changes: 3 additions & 0 deletions edit-post/components/header/pinned-plugins/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.edit-post-pinned-plugins {
display: flex;
}
38 changes: 26 additions & 12 deletions edit-post/components/header/plugin-sidebar-more-menu-item/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/element';
import { compose, Fragment } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { MenuItem } from '@wordpress/components';
import { IconButton, MenuItem } from '@wordpress/components';
import { withPluginContext } from '@wordpress/plugins';

/**
* Internal dependencies
*/
import PinnedPlugins from '../pinned-plugins';
import PluginsMoreMenuGroup from '../plugins-more-menu-group';

const PluginSidebarMoreMenuItem = ( { children, isSelected, icon, onClick } ) => (
<PluginsMoreMenuGroup>
{ ( fillProps ) => (
<MenuItem
icon={ isSelected ? 'yes' : icon }
isSelected={ isSelected }
onClick={ compose( onClick, fillProps.onClose ) }
>
{ children }
</MenuItem>
<Fragment>
{ icon && (
<PinnedPlugins>
<IconButton
icon={ icon }
label={ children }
onClick={ onClick }
isToggled={ isSelected }
aria-expanded={ isSelected }
/>
</PinnedPlugins>
) }
</PluginsMoreMenuGroup>
<PluginsMoreMenuGroup>
{ ( fillProps ) => (
<MenuItem
icon={ isSelected ? 'yes' : icon }
isSelected={ isSelected }
onClick={ compose( onClick, fillProps.onClose ) }
>
{ children }
</MenuItem>
) }
</PluginsMoreMenuGroup>
</Fragment>
);

export default compose(
Expand Down

0 comments on commit 80b02c8

Please sign in to comment.