-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Writing Flow: Always add an empty at the end of the block list #3623
Changes from all commits
33fafb4
29768ab
11a1eca
7265186
9b619a7
b8f960c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import classnames from 'classnames'; | ||
import 'element-closest'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { getDefaultBlockName, createBlock } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import BlockDropZone from '../block-drop-zone'; | ||
import { insertBlock } from '../../actions'; | ||
import { getBlockCount } from '../../selectors'; | ||
|
||
class DefaultBlockAppender extends Component { | ||
constructor( props ) { | ||
super( props ); | ||
this.appendDefaultBlock = this.appendDefaultBlock.bind( this ); | ||
} | ||
|
||
appendDefaultBlock() { | ||
const newBlock = createBlock( getDefaultBlockName() ); | ||
this.props.onInsertBlock( newBlock ); | ||
} | ||
|
||
render() { | ||
const { count } = this.props; | ||
|
||
const className = classnames( 'editor-default-block-appender', { | ||
'is-visible-placeholder': count === 0, | ||
} ); | ||
|
||
return ( | ||
<div className={ className }> | ||
<BlockDropZone /> | ||
{ count === 0 && | ||
<input | ||
className="editor-default-block-appender__content" | ||
type="text" | ||
readOnly | ||
onFocus={ this.appendDefaultBlock } | ||
onClick={ this.appendDefaultBlock } | ||
onKeyDown={ this.appendDefaultBlock } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what case could a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, probably a useless event handler. |
||
value={ __( 'Write your story' ) } | ||
/> | ||
} | ||
{ count !== 0 && | ||
<button | ||
className="editor-default-block-appender__content" | ||
onClick={ this.appendDefaultBlock } | ||
/> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be nice to have 3 unit tests:
I can add them, just ping me :) |
||
( state ) => ( { | ||
count: getBlockCount( state ), | ||
} ), | ||
{ onInsertBlock: insertBlock } | ||
)( DefaultBlockAppender ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
$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 * 1.5; | ||
font-size: $editor-font-size; | ||
line-height: $editor-line-height; | ||
cursor: text; | ||
max-width: none; // fixes a bleed issue from the admin | ||
|
||
&:focus { | ||
outline: 1px solid $light-gray-500; | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to update
createBlock
definition to simplify this call to:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know :)