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

Sidebar: Add a sidebar to hold the post settings and inspector #449

Merged
merged 3 commits into from
Apr 19, 2017
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
1 change: 1 addition & 0 deletions editor/assets/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $editor-font-size: 16px;
$editor-line-height: 1.8em;
$item-spacing: 10px;
$header-height: 56px;
$sidebar-width: 320px;
$admin-bar-height: 32px;
$admin-bar-height-big: 46px;
$admin-sidebar-width: 160px;
Expand Down
5 changes: 3 additions & 2 deletions editor/components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import './style.scss';
import classnames from 'classnames';

function Button( { isPrimary, isLarge, className, ...additionalProps } ) {
function Button( { isPrimary, isLarge, isToggled, className, ...additionalProps } ) {
const classes = classnames( 'editor-button', className, {
button: ( isPrimary || isLarge ),
'button-primary': isPrimary,
'button-large': isLarge
'button-large': isLarge,
'is-toggled': isToggled
} );

return (
Expand Down
6 changes: 6 additions & 0 deletions editor/components/button/style.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
.editor-button {
background: none;
border: none;
outline: none;

&:disabled {
opacity: 0.6;
}

&.is-toggled {
background: $dark-gray-500;
color: $white;
}
}
10 changes: 6 additions & 4 deletions editor/header/tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import IconButton from '../../components/icon-button';
import Inserter from '../../components/inserter';
import Button from '../../components/button';

function Tools( { undo, redo, hasUndo, hasRedo } ) {
function Tools( { undo, redo, hasUndo, hasRedo, isSidebarOpened, toggleSidebar } ) {
return (
<div className="editor-tools">
<IconButton
Expand All @@ -31,7 +31,7 @@ function Tools( { undo, redo, hasUndo, hasRedo } ) {
<Dashicon icon="visibility" />
{ wp.i18n._x( 'Preview', 'imperative verb' ) }
</Button>
<Button>
<Button onClick={ toggleSidebar } isToggled={ isSidebarOpened }>
<Dashicon icon="admin-generic" />
{ wp.i18n.__( 'Post Settings' ) }
</Button>
Expand All @@ -46,10 +46,12 @@ function Tools( { undo, redo, hasUndo, hasRedo } ) {
export default connect(
( state ) => ( {
hasUndo: state.blocks.history.past.length > 0,
hasRedo: state.blocks.history.future.length > 0
hasRedo: state.blocks.history.future.length > 0,
isSidebarOpened: state.isSidebarOpened,
} ),
( dispatch ) => ( {
undo: () => dispatch( { type: 'UNDO' } ),
redo: () => dispatch( { type: 'REDO' } )
redo: () => dispatch( { type: 'REDO' } ),
toggleSidebar: () => dispatch( { type: 'TOGGLE_SIDEBAR' } )
} )
)( Tools );
3 changes: 3 additions & 0 deletions editor/header/tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
color: $dark-gray-500;
margin-right: $item-spacing;
cursor: pointer;
height: 30px;
padding: 0 10px;
border-radius: 3px;

&:hover {
color: $blue-medium;
Expand Down
21 changes: 16 additions & 5 deletions editor/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@
* External dependencies
*/
import { connect } from 'react-redux';
import classnames from 'classnames';

/**
* Internal dependencies
*/
import './style.scss';
import Header from 'header';
import Sidebar from 'sidebar';
import TextEditor from 'modes/text-editor';
import VisualEditor from 'modes/visual-editor';

function Layout( { mode } ) {
function Layout( { mode, isSidebarOpened } ) {
const className = classnames( 'editor-layout', {
'is-sidebar-opened': isSidebarOpened
} );

return (
<div>
<div className={ className }>
<Header />
{ mode === 'text' && <TextEditor /> }
{ mode === 'visual' && <VisualEditor /> }
<div className="editor-layout__content">
{ mode === 'text' && <TextEditor /> }
{ mode === 'visual' && <VisualEditor /> }
</div>
{ isSidebarOpened && <Sidebar /> }
</div>
);
}

export default connect( ( state ) => ( {
mode: state.mode
mode: state.mode,
isSidebarOpened: state.isSidebarOpened
} ) )( Layout );
3 changes: 3 additions & 0 deletions editor/layout/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.editor-layout.is-sidebar-opened .editor-layout__content {
margin-right: $sidebar-width;
}
4 changes: 4 additions & 0 deletions editor/modes/text-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

@include break-small() {
position: fixed;

.editor-layout.is-sidebar-opened & {
margin-right: $sidebar-width;
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions editor/sidebar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Internal Dependencies
*/
import './style.scss';

const Sidebar = () => {
return (
<div className="editor-sidebar">
</div>
);
};

export default Sidebar;
9 changes: 9 additions & 0 deletions editor/sidebar/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.editor-sidebar {
position: fixed;
right: 0;
top: 32px + $header-height;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need some breakpoint styling for this. Not sure if we wanted to do that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this for a more "designy" eyes :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll definitely tackle this separately, it's already on my to-do 😉

bottom: 0;
width: $sidebar-width;
border-left: 1px solid $light-gray-500;
background: $light-gray-300;
}
12 changes: 11 additions & 1 deletion editor/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ export function mode( state = 'visual', action ) {
return state;
}

export function isSidebarOpened( state = false, action ) {
switch ( action.type ) {
case 'TOGGLE_SIDEBAR':
return ! state;
}

return state;
}

/**
* Creates a new instance of a Redux store.
*
Expand All @@ -158,7 +167,8 @@ export function createReduxStore() {
blocks,
selectedBlock,
hoveredBlock,
mode
mode,
isSidebarOpened
} );

return createStore(
Expand Down
20 changes: 19 additions & 1 deletion editor/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
hoveredBlock,
selectedBlock,
mode,
isSidebarOpened,
createReduxStore
} from '../state';

Expand Down Expand Up @@ -281,6 +282,22 @@ describe( 'state', () => {
} );
} );

describe( 'isSidebarOpened()', () => {
it( 'should be closed by default', () => {
const state = isSidebarOpened( undefined, {} );

expect( state ).to.be.false();
} );

it( 'should toggle the sidebar open flag', () => {
const state = isSidebarOpened( false, {
type: 'TOGGLE_SIDEBAR'
} );

expect( state ).to.be.true();
} );
} );

describe( 'createReduxStore()', () => {
it( 'should return a redux store', () => {
const store = createReduxStore();
Expand All @@ -297,7 +314,8 @@ describe( 'state', () => {
'blocks',
'selectedBlock',
'hoveredBlock',
'mode'
'mode',
'isSidebarOpened'
] );
} );
} );
Expand Down