Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
10e4082
Remove submit button; Add ellipsis button
RockinRonE May 27, 2018
7a99dfe
add toggle settings to state
RockinRonE May 27, 2018
3aaf90a
Add setLinkTarget func
RockinRonE May 27, 2018
14e09dc
Pass props to UrlInputButton
RockinRonE May 27, 2018
efdef98
Add set target attribute
RockinRonE May 27, 2018
2d65e82
Add target attribute
RockinRonE May 27, 2018
66d91f7
Add rel attribute
RockinRonE May 28, 2018
b604f7e
Set rel attribute
RockinRonE May 28, 2018
cd05ad6
Add prependHTTP
RockinRonE May 28, 2018
13025ab
Update blockAttributes with target and rel
RockinRonE May 28, 2018
b1aec98
Add popover and remove commented out code
RockinRonE May 29, 2018
2935e5f
Add onKeyDown functions
RockinRonE May 29, 2018
65541c4
Add keyDown handling
RockinRonE May 29, 2018
a79a991
Add setAttributes func to submit
RockinRonE May 29, 2018
3d9ce25
Add edit link section
RockinRonE May 29, 2018
141bf49
Remove box-shadow on focus
RockinRonE May 29, 2018
0b23bea
Add null default value
RockinRonE May 29, 2018
b538789
Add correct input and edit toggle forms
RockinRonE May 29, 2018
85f9fa3
Destructure props and remove toggle on pressing enter
RockinRonE May 29, 2018
f109c4c
Add toggle state reflected in toggle button
RockinRonE May 29, 2018
45193d2
Add disable lint and remove log statement
RockinRonE May 29, 2018
5d45dfb
Add href and target attrs to tests
RockinRonE May 29, 2018
4bc4620
Remove close button test
RockinRonE May 29, 2018
acb5b5a
Remove close form test
RockinRonE May 30, 2018
0edf482
fix merge conflicts
RockinRonE May 30, 2018
c14e4b3
fix formatting
RockinRonE May 30, 2018
345d3e7
fix formatting
RockinRonE May 30, 2018
ce4d81b
remove unused import
RockinRonE May 30, 2018
ccecb2b
remove whitespace
RockinRonE May 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add popover and remove commented out code
  • Loading branch information
RockinRonE committed May 29, 2018
commit b1aec98dfef7cf32f007df1f15a6fb3cfd17b693
100 changes: 48 additions & 52 deletions editor/components/url-input/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import classnames from 'classnames';
import './style.scss';
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { IconButton, ToggleControl } from '@wordpress/components';
import { IconButton, ToggleControl, Popover } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -18,11 +18,11 @@ import UrlInput from './';

class UrlInputButton extends Component {
constructor() {
super(...arguments);
this.toggle = this.toggle.bind(this);
this.submitLink = this.submitLink.bind(this);
this.toggleLinkSettingsVisibility = this.toggleLinkSettingsVisibility.bind(this);
this.setLinkTarget = this.setLinkTarget.bind(this);
super( ...arguments );
this.toggle = this.toggle.bind( this );
this.submitLink = this.submitLink.bind( this );
this.toggleLinkSettingsVisibility = this.toggleLinkSettingsVisibility.bind( this );
this.setLinkTarget = this.setLinkTarget.bind( this );

this.state = {
expanded: false,
Expand All @@ -31,49 +31,40 @@ class UrlInputButton extends Component {
};
}

// this.state = {
//
// linkValue: '',
// };

toggle() {
this.setState({ expanded: !this.state.expanded });
this.setState( { expanded: ! this.state.expanded } );
}



submitLink(event) {
submitLink( event ) {
event.preventDefault();
this.toggle();
}

toggleLinkSettingsVisibility() {
this.setState((state) => ({ settingsVisible: !state.settingsVisible }));
this.setState( ( state ) => ( { settingsVisible: ! state.settingsVisible } ) );
}

setLinkTarget(opensInNewWindow) {
this.setState({ opensInNewWindow });
if (opensInNewWindow) {

this.props.setAttributes({
setLinkTarget( opensInNewWindow ) {
this.setState( { opensInNewWindow } );
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 to track this as part of state?

Or can it be inferred from props in render as:

const opensInNewWindow = ( this.props.attributes.target === '_blank' );

The hope being that we could consolidate to one source of truth (attributes), rather than tracking in two places, which is more prone to falling out of sync.

Edit: I see after the fact that this is also how we populate the initial state in the constructor.

if ( opensInNewWindow ) {
this.props.setAttributes( {
target: '_blank',
rel: opensInNewWindow ? 'noreferrer noopener' : null,
})
} );
}
}


render() {
const { url, onChange } = this.props;
const { expanded, settingsVisible, opensInNewWindow } = this.state;
const buttonLabel = url ? __('Edit Link') : __('Insert Link');
const buttonLabel = url ? __( 'Edit Link' ) : __( 'Insert Link' );

const linkSettings = settingsVisible && (
<div className="editor-format-toolbar__link-modal-line editor-format-toolbar__link-settings">
Copy link
Member

Choose a reason for hiding this comment

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

The coding guidelines for CSS naming is written such that this is not a valid class name to assign to this component. It's reflective of the fact that components are meant to compose one another, and shouldn't be inheriting behaviors, since it can lead to accidental breakage if a change to the format toolbar inadvertently affects this component. Isolating components to silo their behavior / silos helps prevent this.

What I'd like to see instead, and what seemed to be hinted by the idea of "unifying" in the original pull request, is that instead of duplicating what already exists elsewhere, we ought to consider creating a new, separate component which contains the shared behavior (of link management), then use that both here and in other existing usage.

<ToggleControl
label={__('Open in new window')}
checked={opensInNewWindow}
onChange={this.setLinkTarget}
label={ __( 'Open in new window' ) }
checked={ opensInNewWindow }
onChange={ this.setLinkTarget }
/>
</div>
);
Expand All @@ -82,34 +73,39 @@ class UrlInputButton extends Component {
<div className="editor-url-input__button">
<IconButton
icon="admin-links"
label={buttonLabel}
onClick={this.toggle}
className={classnames('components-toolbar__control', {
label={ buttonLabel }
onClick={ this.toggle }
className={ classnames( 'components-toolbar__control', {
'is-active': url,
})}
} ) }
/>
{expanded &&
<form
className="editor-url-input__button-modal"
onSubmit={this.submitLink}
{ expanded &&
<Popover
position="bottom center"
focusOnMount={ true }
>
<div className="editor-url-input__button-modal-line">
<UrlInput value={url || ''} onChange={onChange} data-test="UrlInput" />
<IconButton
icon="editor-break"
label={__('Submit')}
type="submit"
/>
<IconButton
className="editor-format-toolbar__link-settings-toggle"
icon="ellipsis"
label={__('Link Settings')}
onClick={this.toggleLinkSettingsVisibility}
// aria-expanded={settingsVisible}
/>
</div>
{linkSettings}
</form>
<form
className="editor-url-input__button-modal"
onSubmit={ this.submitLink }
>
<div className="editor-url-input__button-modal-line">
<UrlInput value={ url || '' } onChange={ onChange } data-test="UrlInput" />
<IconButton
icon="editor-break"
label={ __( 'Submit' ) }
type="submit"
/>
<IconButton
className="editor-format-toolbar__link-settings-toggle"
icon="ellipsis"
label={ __( 'Link Settings' ) }
onClick={ this.toggleLinkSettingsVisibility }
aria-expanded={ settingsVisible }
/>
</div>
{ linkSettings }
</form>
</Popover>
}
</div>
);
Expand Down