Skip to content

Commit

Permalink
Add sidebar tabs to switch between doc and block settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtias committed Jul 10, 2017
1 parent 4e0ea5c commit 83512b8
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 20 deletions.
2 changes: 1 addition & 1 deletion editor/header/tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Tools( { undo, redo, hasUndo, hasRedo, isSidebarOpened, toggleSidebar }
<PreviewButton />
<div className="editor-tools__tabs">
<IconButton icon="admin-generic" onClick={ toggleSidebar } isToggled={ isSidebarOpened }>
{ __( 'Post Settings' ) }
{ __( 'Settings' ) }
</IconButton>
</div>
<PublishButton />
Expand Down
10 changes: 10 additions & 0 deletions editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export function getEditorMode( state ) {
return state.mode;
}

/**
* Returns the current sidebar mode.
*
* @param {Object} state Global application state
* @return {String} Sidebar mode
*/
export function getSidebarMode( state ) {
return state.sidebarMode;
}

/**
* Returns true if the editor sidebar panel is open, or false otherwise.
*
Expand Down
3 changes: 1 addition & 2 deletions editor/sidebar/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getSelectedBlock } from '../../selectors';

const BlockInspector = ( { selectedBlock, ...props } ) => {
if ( ! selectedBlock ) {
return null;
return <span>{ __( 'No block selected.' ) }</span>;
}

const blockType = getBlockType( selectedBlock.name );
Expand All @@ -42,7 +42,6 @@ const BlockInspector = ( { selectedBlock, ...props } ) => {

return (
<Panel>
<PanelHeader label={ header } />
<PanelBody>
<Slot name="Inspector.Controls" />
</PanelBody>
Expand Down
54 changes: 54 additions & 0 deletions editor/sidebar/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import { IconButton } from 'components';

/**
* Internal Dependencies
*/
import { getSidebarMode } from 'editor/selectors';

const SidebarHeader = ( { mode, onSelectMode, toggleSidebar } ) => {
return (
<div className="components-panel__header">
<h2
onClick={ () => onSelectMode( 'document' ) }
className={ `editor-sidebar__mode-tab ${ mode === 'document' ? 'is-active' : '' }` }
>
{ __( 'Document' ) }
</h2>
<h2
onClick={ () => onSelectMode( 'block' ) }
className={ `editor-sidebar__mode-tab ${ mode === 'block' ? 'is-active' : '' }` }
>
{ __( 'Block' ) }
</h2>
<IconButton
onClick={ toggleSidebar }
icon="no-alt"
label={ __( 'Close post settings sidebar' ) }
/>
</div>
);
};

export default connect(
( state ) => ( {
mode: getSidebarMode( state ),
} ),
( dispatch ) => ( {
onSelectMode( mode ) {
dispatch( {
type: 'SELECT_SIDEBAR_MODE',
sidebarMode: mode,
} );
},
toggleSidebar: () => dispatch( { type: 'TOGGLE_SIDEBAR' } ),
} )
)( SidebarHeader );
11 changes: 7 additions & 4 deletions editor/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { withFocusReturn } from 'components';
import './style.scss';
import PostSettings from './post-settings';
import BlockInspector from './block-inspector';
import { getSelectedBlock } from '../selectors';
import Header from './header';
import { getSelectedBlock, getSidebarMode } from '../selectors';

const Sidebar = ( { selectedBlock } ) => {
const Sidebar = ( { selectedBlock, sidebarMode } ) => {
return (
<div className="editor-sidebar">
{ ! selectedBlock && <PostSettings /> }
{ selectedBlock && <BlockInspector /> }
<Header />
{ sidebarMode === 'document' && <PostSettings /> }
{ sidebarMode === 'block' && <BlockInspector /> }
</div>
);
};
Expand All @@ -29,6 +31,7 @@ export default connect(
( state ) => {
return {
selectedBlock: getSelectedBlock( state ),
sidebarMode: getSidebarMode( state ),
};
}
)( withFocusReturn( Sidebar ) );
13 changes: 0 additions & 13 deletions editor/sidebar/post-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ import LastRevision from '../last-revision';
const PostSettings = ( { toggleSidebar } ) => {
return (
<Panel>
<PanelHeader label={ __( 'Post Settings' ) } >
<div className="editor-sidebar-post-settings__icons">
<IconButton
icon="admin-settings"
label={ __( 'WordPress settings' ) }
/>
<IconButton
onClick={ toggleSidebar }
icon="no-alt"
label={ __( 'Close post settings sidebar' ) }
/>
</div>
</PanelHeader>
<PostStatus />
<LastRevision />
<PostTaxonomies />
Expand Down
11 changes: 11 additions & 0 deletions editor/sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@
.editor-layout.is-sidebar-opened .editor-text-editor__formatting {
margin-right: $sidebar-width;
}

.editor-sidebar__mode-tab {
border-bottom: 3px solid transparent;
cursor: pointer;
height: 50px;
line-height: 50px;
padding: 0 20px;
&.is-active {
border-bottom-color: $blue-medium-500;
}
}
10 changes: 10 additions & 0 deletions editor/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ export function isSidebarOpened( state = ! isMobile, action ) {
return state;
}

export function sidebarMode( state = 'document', action ) {
switch ( action.type ) {
case 'SELECT_SIDEBAR_MODE':
return action.sidebarMode;
}

return state;
}

/**
* Reducer returning current network request state (whether a request to the WP
* REST API is in progress, successful, or failed).
Expand Down Expand Up @@ -496,6 +505,7 @@ export function createReduxStore() {
showInsertionPoint,
mode,
isSidebarOpened,
sidebarMode,
saving,
notices,
} ) );
Expand Down

0 comments on commit 83512b8

Please sign in to comment.