Skip to content

Commit

Permalink
Move "continue writing" next to inserter and show on hover. (#1553)
Browse files Browse the repository at this point in the history
* Move "continue writing" next to inserter and show on hover.
* Convert empty text to row of common blocks.
  • Loading branch information
mtias authored Jun 28, 2017
1 parent ecea4ef commit 8417e9e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
53 changes: 42 additions & 11 deletions editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { throttle, reduce, noop } from 'lodash';
import { __ } from 'i18n';
import { Component } from 'element';
import { serialize, getDefaultBlock, createBlock } from 'blocks';
import { Dashicon } from 'components';
import { ENTER } from 'utils/keycodes';

/**
* Internal dependencies
*/
import VisualEditorBlock from './block';
import Inserter from '../../inserter';
import {
getBlockUids,
getBlockInsertionPoint,
Expand Down Expand Up @@ -191,8 +193,19 @@ class VisualEditorBlockList extends Component {
this.props.onInsertBlock( newBlock );
}

insertBlock( name ) {
const newBlock = createBlock( name );
this.props.onInsertBlock( newBlock );
}

render() {
const { blocks, showInsertionPoint, insertionPoint, multiSelectedBlockUids } = this.props;
const {
blocks,
showInsertionPoint,
insertionPoint,
multiSelectedBlockUids,
} = this.props;

const insertionPointIndex = blocks.indexOf( insertionPoint );
const blocksWithInsertionPoint = showInsertionPoint
? [
Expand Down Expand Up @@ -224,16 +237,34 @@ class VisualEditorBlockList extends Component {
/>
);
} ) }

<input
type="text"
readOnly
className="editor-visual-editor__placeholder"
value={ ! blocks.length ? __( 'Write your story' ) : __( 'Continue writing…' ) }
onFocus={ ! blocks.length ? this.appendDefaultBlock : noop }
onClick={ !! blocks.length ? this.appendDefaultBlock : noop }
onKeyDown={ !! blocks.length ? this.onPlaceholderKeyDown : noop }
/>
{ ! blocks.length &&
<input
type="text"
readOnly
className="editor-visual-editor__placeholder"
value={ __( 'Write your story' ) }
onFocus={ this.appendDefaultBlock }
onClick={ noop }
onKeyDown={ noop }
/>
}
<div className="editor-visual-editor__continue-writing">
<Inserter position="top right" />
<button
className="editor-inserter__block"
onClick={ () => this.insertBlock( 'core/text' ) }
>
<Dashicon icon="text" />
{ __( 'Text' ) }
</button>
<button
className="editor-inserter__block"
onClick={ () => this.insertBlock( 'core/image' ) }
>
<Dashicon icon="format-image" />
{ __( 'Image' ) }
</button>
</div>
</div>
);
}
Expand Down
2 changes: 0 additions & 2 deletions editor/modes/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { CHAR_A } from 'utils/keycodes';
* Internal dependencies
*/
import './style.scss';
import Inserter from '../../inserter';
import VisualEditorBlockList from './block-list';
import PostTitle from '../../post-title';
import { getBlockUids } from '../../selectors';
Expand Down Expand Up @@ -80,7 +79,6 @@ class VisualEditor extends Component {
>
<PostTitle />
<VisualEditorBlockList ref={ this.bindBlocksContainer } />
<Inserter position="top right" />
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
Expand Down
18 changes: 18 additions & 0 deletions editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,21 @@ $sticky-bottom-offset: 20px;
outline: 1px solid $light-gray-500;
}
}

.editor-visual-editor__continue-writing {
display: flex;
align-items: baseline;

.editor-inserter__block {
opacity: 0;
transition: opacity 150ms;
margin: 0 10px;
width: auto;
font-family: $default-font;
font-size: $default-font-size;
}
&:hover .editor-inserter__block,
&:focus .editor-inserter__block {
opacity: 1;
}
}

0 comments on commit 8417e9e

Please sign in to comment.