Skip to content

Commit

Permalink
Editor: Bring back the trailing placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jan 12, 2018
1 parent d937d3a commit 2ee822c
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 392 deletions.
46 changes: 30 additions & 16 deletions editor/components/default-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,54 @@
* External dependencies
*/
import { connect } from 'react-redux';
import 'element-closest';
import classnames from 'classnames';
import { last } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { getDefaultBlockName } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './style.scss';
import BlockDropZone from '../block-drop-zone';
import { appendDefaultBlock } from '../../store/actions';
import { getBlockCount } from '../../store/selectors';
import { getBlockCount, getBlocks } from '../../store/selectors';

export class DefaultBlockAppender extends Component {
render() {
const { count } = this.props;
if ( count !== 0 ) {
return null;
}
const { count, blocks } = this.props;
const lastBlock = last( blocks );
const showAppender = lastBlock && lastBlock.name !== getDefaultBlockName();

const className = classnames( 'editor-default-block-appender', {
'is-visible-placeholder': count === 0,
} );

return (
<div className="editor-default-block-appender">
<div className={ className }>
<BlockDropZone />
<input
className="editor-default-block-appender__content"
type="text"
readOnly
onFocus={ this.props.appendDefaultBlock }
onClick={ this.props.appendDefaultBlock }
onKeyDown={ this.props.appendDefaultBlock }
value={ __( 'Write your story' ) }
/>
{ count === 0 &&
<input
className="editor-default-block-appender__content"
type="text"
readOnly
onFocus={ this.props.appendDefaultBlock }
onClick={ this.props.appendDefaultBlock }
onKeyDown={ this.props.appendDefaultBlock }
value={ __( 'Write your story' ) }
/>
}
{ count !== 0 && showAppender &&
<button
className="editor-default-block-appender__content"
onClick={ this.props.appendDefaultBlock }
/>
}
</div>
);
}
Expand All @@ -45,6 +58,7 @@ export class DefaultBlockAppender extends Component {
export default connect(
( state ) => ( {
count: getBlockCount( state ),
blocks: getBlocks( state ),
} ),
{ appendDefaultBlock }
)( DefaultBlockAppender );
27 changes: 16 additions & 11 deletions editor/components/default-block-appender/style.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
$empty-paragraph-height: $text-editor-font-size * 4;

.editor-default-block-appender {
&.is-visible-placeholder .editor-default-block-appender__content {
height: $empty-paragraph-height;
color: $dark-gray-300;
outline: 1px solid transparent;
transition: 0.2s outline;

&:hover {
outline: 1px solid $light-gray-500;
}
}
}

.editor-default-block-appender__content,
input[type=text].editor-default-block-appender__content {
border: none;
background: none;
box-shadow: none;
display: block;
width: 100%;
height: $empty-paragraph-height;
font-size: $editor-font-size;
cursor: text;
max-width: none; // fixes a bleed issue from the admin
height: $empty-paragraph-height;
color: $dark-gray-300;
outline: 1px solid transparent;
transition: 0.2s outline;

// subtract 1px for border
position: relative;
top: -1px;
left: -1px;
margin-bottom: $block-spacing - 1px;

&:focus, &:hover {
&:focus {
outline: 1px solid $light-gray-500;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DefaultBlockAppender blocks present should match snapshot 1`] = `""`;
exports[`DefaultBlockAppender blocks present should match snapshot 1`] = `
<div
className="editor-default-block-appender"
>
<Connect(WrappedComponent) />
</div>
`;

exports[`DefaultBlockAppender no block present should match snapshot 1`] = `
<div
className="editor-default-block-appender"
className="editor-default-block-appender is-visible-placeholder"
>
<Connect(WrappedComponent) />
<input
Expand Down
9 changes: 9 additions & 0 deletions editor/components/default-block-appender/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,14 @@ describe( 'DefaultBlockAppender', () => {

expect( wrapper ).toMatchSnapshot();
} );

it( 'should append a default block when button clicked', () => {
const insertBlock = jest.fn();
const wrapper = shallow( <DefaultBlockAppender count={ 5 } blocks={ [ { name: 'core/image' } ] } appendDefaultBlock={ insertBlock } /> );

wrapper.find( 'button.editor-default-block-appender__content' ).simulate( 'click' );

expectAppendDefaultBlockCalled( insertBlock );
} );
} );
} );
2 changes: 0 additions & 2 deletions editor/edit-post/modes/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Component, findDOMNode } from '@wordpress/element';
*/
import './style.scss';
import { BlockList, PostTitle, WritingFlow, DefaultBlockAppender, EditorGlobalKeyboardShortcuts } from '../../../components';
import VisualEditorInserter from './inserter';
import { hasFixedToolbar } from '../../../store/selectors';
import { clearSelectedBlock } from '../../../store/actions';

Expand Down Expand Up @@ -62,7 +61,6 @@ class VisualEditor extends Component {
/>
<DefaultBlockAppender />
</WritingFlow>
<VisualEditorInserter />
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
Expand Down
114 changes: 0 additions & 114 deletions editor/edit-post/modes/visual-editor/inserter.js

This file was deleted.

43 changes: 0 additions & 43 deletions editor/edit-post/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,6 @@
}
}

.editor-visual-editor__inserter {
display: flex;
align-items: baseline;
max-width: $visual-editor-max-width + ( 2 * $block-mover-padding-visible );
margin: 0 auto;
clear: both;

padding: $block-padding;
padding-left: $block-padding - 8px; // Offset by left button's own padding
@include break-small {
padding: $block-padding ( $block-padding + $block-mover-padding-visible );
padding-left: $block-padding + $block-mover-padding-visible - 8px;
}

> .editor-inserter__block {
flex-direction: row;
opacity: 0;
transition: opacity 150ms;
margin: 0 10px;
width: auto;
font-family: $default-font;
font-size: $default-font-size;
box-shadow: none;
padding: 6px;
align-items: center;
}

&:hover > .editor-inserter__block,
&.is-showing-controls > .editor-inserter__block {
opacity: 1;

&:disabled {
@include button-style__disabled;
}
}
}

.editor-visual-editor__inserter-block-icon {
display: inline-block;
margin-right: 8px;
height: 20px;
}

.editor-visual-editor .editor-post-title {
margin-left: auto;
margin-right: auto;
Expand Down
56 changes: 0 additions & 56 deletions editor/edit-post/modes/visual-editor/test/inserter.js

This file was deleted.

Loading

0 comments on commit 2ee822c

Please sign in to comment.