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

Editor Chrome: Adding the editor mode switcher #339

Merged
merged 7 commits into from
Mar 29, 2017
Merged

Conversation

youknowriad
Copy link
Contributor

screen shot 2017-03-28 at 14 40 24

Several things in this PR:

  • it adds the concept of Editor Modes (Visual/Text)
  • Adding the onChange content handler and updating the content on the Editor's state
  • V1 of the editor header (would contain, publish, preview, undo/redo ...)
  • The WP Notifications needs some design on this page :)
  • Creating some SASS variables

@youknowriad youknowriad added Design Framework Issues related to broader framework topics, especially as it relates to javascript labels Mar 28, 2017
@youknowriad youknowriad self-assigned this Mar 28, 2017
@youknowriad youknowriad requested review from jasmussen and aduth March 28, 2017 13:46
@jasmussen
Copy link
Contributor

🎉

Solid work! I'm setting up VVV and getting my env up so I can contribute to these branches. There are some little pixel nudges I'd like to do here and there, but nothing you should necessarily worry about. If you'd like to get this in fast, 👍 from me!

This might sound controversial — do we want to show those notices, "get version" and "thanks for creating with WordPress in the editor screen? I say we remove it all for now, and add it back only after presented with good arguments for why they need to be everywhere.

}

componentDidMount() {
this.setState( {
Copy link
Member

Choose a reason for hiding this comment

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

At the very least we should try to do this in componentWillMount or the constructor to avoid an immediate re-render upon mount from setState. Someone shared this with me yesterday which I found quite informative about lifecycle methods and interactions with state:

https://gist.github.com/bvaughn/923dffb2cd9504ee440791fade8db5f9

But more importantly there might be some need to rethink how we're controlling or at least naming the initial content being passed in. Perhaps naming the prop as defaultContent (like defaultValue of base inputs) with a preference toward the state value in the render, or initialContent (initialValue) in defining the initial state.

<ModeSwitcher mode={ mode } onSwitch={ this.switchMode } />
</div>
<div className="editor__body">
{ mode === 'text' && <EditorText html={ html } onChange={ this.changeHtml } /> }
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Possible to consolidate similar logic, though dunno how much this helps readability:

createChangeHandler( type ) {
	return ( value ) => this.setState( { [ type ]: value } );
}

// ...

render() {
	<EditorText html={ html } onChange={ this.createChangeHandler( 'html' ) } />
}

}

toggle( event ) {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

If you assign type="button" to the button element you can avoid the need for preventDefault (only needed because default type of button is "submit").

Copy link
Member

Choose a reason for hiding this comment

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

If you assign type="button" to the button element you can avoid the need for preventDefault (only needed because default type of button is "submit").

I guess it makes no difference at the moment since the button lives outside the page form, but having not assigned a type to the button may come to bite us in the future.

<button
className="editor-mode-switcher__toggle"
onClick={ this.toggle }
aria-label="Switch the editor mode"
Copy link
Member

Choose a reason for hiding this comment

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

We should probably start thinking about localization sooner than later. I might focus on this today (for a separate pull request).


return (
<div className="editor-mode-visual">
<div contentEditable>
Copy link
Member

Choose a reason for hiding this comment

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

contentEditable was removed in #330 and we'll probably want to do the same here.

@youknowriad
Copy link
Contributor Author

@jasmussen I had to rebase this branch to resolve the conflicts, you may have to reset your local branch.

@@ -0,0 +1,9 @@
function Text( { html, onChange } ) {
return (
<div className="editor-mode-text">
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the div wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not much, but it eases styling and I'm certain we'll have other elements added soon.

Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

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

Great start! Ship it!

@youknowriad youknowriad merged commit 001ec39 into master Mar 29, 2017
@youknowriad youknowriad deleted the add/editor-chrome branch March 29, 2017 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants