Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Oct 18, 2018
1 parent e3c6524 commit 7bfff6a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );
const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );

class ImageEdit extends Component {
constructor() {
constructor( { attributes } ) {
super( ...arguments );
this.updateAlt = this.updateAlt.bind( this );
this.updateAlignment = this.updateAlignment.bind( this );
Expand All @@ -101,7 +101,7 @@ class ImageEdit extends Component {

this.state = {
captionFocused: false,
isEditing: ! this.props.attributes.url,
isEditing: ! attributes.url,
};
}

Expand Down Expand Up @@ -461,7 +461,7 @@ class ImageEdit extends Component {
// Disable reason: Image itself is not meant to be
// interactive, but should direct focus to block
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
const img = ( <img src={ url } alt={ alt } onClick={ this.onImageClick } /> );
const img = <img src={ url } alt={ alt } onClick={ this.onImageClick } />;

if ( ! isResizable || ! imageWidthWithinContainer ) {
return (
Expand Down
63 changes: 35 additions & 28 deletions packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ import MediaUpload from '../media-upload';
import URLPopover from '../url-popover';
import { mediaUpload } from '../../utils/';

const InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (
<URLPopover onClose={ onClose }>
<form
className="editor-media-placeholder__url-input-form"
onSubmit={ onSubmit }
>
<input
className="editor-media-placeholder__url-input-field"
type="url"
aria-label={ __( 'URL' ) }
placeholder={ __( 'Paste or type URL' ) }
onChange={ onChange }
value={ src }
/>
<IconButton
className="editor-media-placeholder__url-input-submit-button"
icon="editor-break"
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
);

class MediaPlaceholder extends Component {
constructor() {
super( ...arguments );
Expand Down Expand Up @@ -129,10 +153,9 @@ class MediaPlaceholder extends Component {

const {
isURLInputVisible,
src,
} = this.state;

const toggleURLInput = ! isURLInputVisible ? this.openURLInput : undefined;

const allowedTypes = this.getAllowedTypes();

return (
Expand Down Expand Up @@ -174,38 +197,22 @@ class MediaPlaceholder extends Component {
) }
/>
{ onSelectURL && (
<div
className="editor-media-placeholder__url-input-container"
>
<div className="editor-media-placeholder__url-input-container">
<Button
className="editor-media-placeholder__button"
onClick={ toggleURLInput }
onClick={ this.openURLInput }
isToggled={ isURLInputVisible }
isLarge>
isLarge
>
{ __( 'Insert from URL' ) }
</Button>
{ isURLInputVisible && (
<URLPopover onClose={ this.closeURLInput }>
<form
className="editor-media-placeholder__url-input-form"
onSubmit={ this.onSubmitSrc }
>
<input
className="editor-media-placeholder__url-input-field"
type="url"
aria-label={ __( 'URL' ) }
placeholder={ __( 'Paste or type URL' ) }
onChange={ this.onChangeSrc }
value={ this.state.src }
/>
<IconButton
className="editor-media-placeholder__url-input-submit-button"
icon="editor-break"
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
<InsertFromURLPopover
src={ src }
onChange={ this.onChangeSrc }
onSubmit={ this.onSubmitSrc }
onClose={ this.closeURLInput }
/>
) }
</div>
) }
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/url-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class URLPopover extends Component {
children,
renderSettings,
onClose,
onClickOutside = onClose,
onClickOutside,
position = 'bottom center',
focusOnMount = 'firstElement',
} = this.props;
Expand Down

0 comments on commit 7bfff6a

Please sign in to comment.