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

Editable: Adding the link control #505

Closed
wants to merge 1 commit into from
Closed

Conversation

youknowriad
Copy link
Contributor

This PR adds the link control to the formatting toolbar.
I had to change how the Toolbar works to allow advanced controls showing Modals and updating the state accordingly.

Testing instructions

  • Try adding links and navigating inside an Editable.

@youknowriad youknowriad added the Framework Issues related to broader framework topics, especially as it relates to javascript label Apr 25, 2017
@youknowriad youknowriad self-assigned this Apr 25, 2017
@@ -60,3 +60,22 @@
.editor-visual-editor .editor-inserter {
margin: $item-spacing;
}


// joen make me pretty
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasmussen you shouldn't have showed me this tip :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha love it :D — I'll take a look.

@jasmussen
Copy link
Contributor

Nice work!

I'm curious on Ella's thoughts here, as the link feature of the current editor is stellar in how it works. Whatever we could copy from that needs to come along for the ride. That includes the "select text and paste link" feature. There's also a bunch of little enhancements like the link dialog showing in context of the selected text, and easily dismissing with a click outside, as well as an easy way to unlink the link again.

Here's a mockup:

screen shot 2017-04-25 at 14 01 47

To put it differently — how can we port as much as possible of the current link behavior? Is that out of scope for this PR?

@jasmussen
Copy link
Contributor

Here's a quick mockup of what I was thinking:

screen shot 2017-04-25 at 14 13 08

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Empty file editor/components/format-toolbar/index.js should be removed.

@@ -141,6 +141,14 @@ export default class Editable extends wp.element.Component {
return result;
}, {} );

// Link format
const link = parents.find( parent => parent.nodeName === 'A' );
Copy link
Member

Choose a reason for hiding this comment

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

We're not polyfilling Array#find, this will error in IE11.

@@ -9,27 +9,34 @@ import classNames from 'classnames';
import './style.scss';
import IconButton from 'components/icon-button';

function Toolbar( { controls } ) {
function Toolbar( { attributes, setAttributes, controls } ) {
Copy link
Member

Choose a reason for hiding this comment

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

My first reaction to these changes is that the line is becoming blurred between the concept of a general-purpose toolbar and a block-specific toolbar. We should decide if there's value in the former and whether we can or care to preserve this distinction.

Copy link
Contributor Author

@youknowriad youknowriad Apr 25, 2017

Choose a reason for hiding this comment

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

Well attributes and setAttributes here don't mean "block attributes" and "update block attributes" but I see it as "toolbarState" "updateToolbarState" which is generic enough. Could be renamed but this would impact the attributes setAttributes used in the isActive and onClick of the block controls.

Copy link
Member

Choose a reason for hiding this comment

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

Well attributes and setAttributes here don't mean "block attributes" and "update block attributes" but I see it as "toolbarState" "updateToolbarState" which is generic enough.

Given that I had trouble making this distinction, I expect others will as well.

control.onClick( attributes, setAttributes );
} }
className={ classNames( 'editor-toolbar__control', {
'is-active': control.isActive && control.isActive( attributes )
Copy link
Member

Choose a reason for hiding this comment

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

This will need to be rebased to account for changes in #500.

@@ -0,0 +1,105 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

Should this file have been named link-control.js?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see now the LinkControl component is inlined in the file, but the default export is the array of formatting controls. Hmm...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be two files

<div className="editable-visual-editor__link-modal">
<form onSubmit={ this.submitLinkModal }>
<input type="url" value={ this.state.value } onChange={ this.updateLinkValue } />
<button>{ wp.i18n.__( 'Add Link' ) }</button>
Copy link
Member

Choose a reason for hiding this comment

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

Trying to decide if there's value in the <Button /> component (editor/components/button) being the preferred default usage so we can apply styles broadly to all buttons in the editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this needs to be updated to match @jasmussen's comment

} ) }
/>
{ this.state.opened &&
<div className="editable-visual-editor__link-modal">
Copy link
Member

Choose a reason for hiding this comment

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

Can we apply this class to the form and drop the wrapper element?

@youknowriad
Copy link
Contributor Author

@jasmussen My question about your mockups is when do we show/hide the link "modal". Do we show it automatically when the link is focused?

@jasmussen
Copy link
Contributor

My question about your mockups is when do we show/hide the link "modal". Do we show it automatically when the link is focused?

I was thinking the behavior should be as 1:1 identical to the current wp-admin behavior as we can make it, to the point that if we could copy the whole thing over (I know that we can't) it would be great.

link in wp admin

@youknowriad
Copy link
Contributor Author

closing in favor of #524

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